From 4fbd14badbd8cb496be79afeb9c7c1dffd83e01d Mon Sep 17 00:00:00 2001 From: Zhenyao Mo Date: Mon, 13 Apr 2020 12:34:20 +0000 Subject: [PATCH] Fix more compilation warnings. Add -Wconditional-uninitialized -Wc++11-narrowing. Bug: chromium:1064305 Change-Id: I1c1503cafaa2e58e990fc18998200af1f2c00d06 Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/19341 Commit-Queue: Corentin Wallez Reviewed-by: Corentin Wallez --- src/common/BUILD.gn | 2 ++ src/dawn_native/d3d12/ShaderModuleD3D12.cpp | 2 +- src/dawn_native/vulkan/VulkanError.cpp | 4 +-- src/tests/end2end/BindGroupTests.cpp | 28 +++++++++---------- src/tests/perf_tests/DrawCallPerf.cpp | 4 +-- .../VulkanImageWrappingTestsOpaqueFD.cpp | 6 ++-- 6 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/common/BUILD.gn b/src/common/BUILD.gn index b696523f39..5ceaa6ebfc 100644 --- a/src/common/BUILD.gn +++ b/src/common/BUILD.gn @@ -97,6 +97,8 @@ config("dawn_internal") { "-Wcstring-format-directive", "-Wtautological-unsigned-zero-compare", "-Wreturn-std-move-in-c++11", + "-Wconditional-uninitialized", + "-Wc++11-narrowing", # Turn on the following flag after removing the empty statement in # third_party/glm/glm/simd/common.h:106 diff --git a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp index 45f87c02b3..d9289cacc2 100644 --- a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp +++ b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp @@ -68,7 +68,7 @@ namespace dawn_native { namespace d3d12 { ResultOrError ShaderModule::GetHLSLSource(PipelineLayout* layout) { std::unique_ptr compiler_impl; - spirv_cross::CompilerHLSL* compiler; + spirv_cross::CompilerHLSL* compiler = nullptr; if (!GetDevice()->IsToggleEnabled(Toggle::UseSpvc)) { // If these options are changed, the values in DawnSPIRVCrossHLSLFastFuzzer.cpp need to // be updated. diff --git a/src/dawn_native/vulkan/VulkanError.cpp b/src/dawn_native/vulkan/VulkanError.cpp index 9d809ba1fa..7cd45b07d6 100644 --- a/src/dawn_native/vulkan/VulkanError.cpp +++ b/src/dawn_native/vulkan/VulkanError.cpp @@ -19,9 +19,9 @@ namespace dawn_native { namespace vulkan { const char* VkResultAsString(::VkResult result) { - // Convert to a uint32_t to silence and MSVC warning that the fake errors don't appear in + // Convert to a int32_t to silence and MSVC warning that the fake errors don't appear in // the original VkResult enum. - uint32_t code = static_cast(result); + int32_t code = static_cast(result); switch (code) { case VK_SUCCESS: diff --git a/src/tests/end2end/BindGroupTests.cpp b/src/tests/end2end/BindGroupTests.cpp index 60d7afc183..ffd66a8d4f 100644 --- a/src/tests/end2end/BindGroupTests.cpp +++ b/src/tests/end2end/BindGroupTests.cpp @@ -19,7 +19,7 @@ #include "utils/ComboRenderPipelineDescriptor.h" #include "utils/WGPUHelpers.h" -constexpr static unsigned int kRTSize = 8; +constexpr static uint32_t kRTSize = 8; class BindGroupTests : public DawnTest { protected: @@ -218,7 +218,7 @@ TEST_P(BindGroupTests, ReusedUBO) { RGBA8 filled(0, 255, 0, 255); RGBA8 notFilled(0, 0, 0, 0); - int min = 1, max = kRTSize - 3; + uint32_t min = 1, max = kRTSize - 3; EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max); @@ -290,13 +290,13 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) { wgpu::Texture texture = device.CreateTexture(&descriptor); wgpu::TextureView textureView = texture.CreateView(); - int width = kRTSize, height = kRTSize; - int widthInBytes = width * sizeof(RGBA8); + uint32_t width = kRTSize, height = kRTSize; + uint32_t widthInBytes = width * sizeof(RGBA8); widthInBytes = (widthInBytes + 255) & ~255; - int sizeInBytes = widthInBytes * height; - int size = sizeInBytes / sizeof(RGBA8); + uint32_t sizeInBytes = widthInBytes * height; + uint32_t size = sizeInBytes / sizeof(RGBA8); std::vector data = std::vector(size); - for (int i = 0; i < size; i++) { + for (uint32_t i = 0; i < size; i++) { data[i] = RGBA8(0, 255, 0, 255); } wgpu::Buffer stagingBuffer = @@ -323,7 +323,7 @@ TEST_P(BindGroupTests, UBOSamplerAndTexture) { RGBA8 filled(0, 255, 0, 255); RGBA8 notFilled(0, 0, 0, 0); - int min = 1, max = kRTSize - 3; + uint32_t min = 1, max = kRTSize - 3; EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max); @@ -407,7 +407,7 @@ TEST_P(BindGroupTests, MultipleBindLayouts) { RGBA8 filled(255, 255, 0, 255); RGBA8 notFilled(0, 0, 0, 0); - int min = 1, max = kRTSize - 3; + uint32_t min = 1, max = kRTSize - 3; EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max); @@ -456,7 +456,7 @@ TEST_P(BindGroupTests, DrawTwiceInSamePipelineWithFourBindGroupSets) { RGBA8 filled(255, 0, 0, 255); RGBA8 notFilled(0, 0, 0, 0); - int min = 1, max = kRTSize - 3; + uint32_t min = 1, max = kRTSize - 3; EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max); @@ -498,7 +498,7 @@ TEST_P(BindGroupTests, SetBindGroupBeforePipeline) { // The result should be red. RGBA8 filled(255, 0, 0, 255); RGBA8 notFilled(0, 0, 0, 0); - int min = 1, max = kRTSize - 3; + uint32_t min = 1, max = kRTSize - 3; EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max); @@ -559,7 +559,7 @@ TEST_P(BindGroupTests, SetDynamicBindGroupBeforePipeline) { // The result should be RGBAunorm(1, 0, 0, 0.5) + RGBAunorm(0, 1, 0, 0.5) RGBA8 filled(255, 255, 0, 255); RGBA8 notFilled(0, 0, 0, 0); - int min = 1, max = kRTSize - 3; + uint32_t min = 1, max = kRTSize - 3; EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max); @@ -636,7 +636,7 @@ TEST_P(BindGroupTests, BindGroupsPersistAfterPipelineChange) { // The result should be RGBAunorm(1, 0, 0, 0.5) + RGBAunorm(0, 1, 0, 0.5) RGBA8 filled(255, 255, 0, 255); RGBA8 notFilled(0, 0, 0, 0); - int min = 1, max = kRTSize - 3; + uint32_t min = 1, max = kRTSize - 3; EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max); @@ -741,7 +741,7 @@ TEST_P(BindGroupTests, DrawThenChangePipelineAndBindGroup) { RGBA8 filled(255, 255, 255, 255); RGBA8 notFilled(0, 0, 0, 0); - int min = 1, max = kRTSize - 3; + uint32_t min = 1, max = kRTSize - 3; EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, max, min); EXPECT_PIXEL_RGBA8_EQ(filled, renderPass.color, min, max); diff --git a/src/tests/perf_tests/DrawCallPerf.cpp b/src/tests/perf_tests/DrawCallPerf.cpp index 5e6ba7891c..a5c1d2adf1 100644 --- a/src/tests/perf_tests/DrawCallPerf.cpp +++ b/src/tests/perf_tests/DrawCallPerf.cpp @@ -104,9 +104,9 @@ namespace { std::tuple; template - int AssignParam(T& lhs, T rhs) { + unsigned int AssignParam(T& lhs, T rhs) { lhs = rhs; - return 0; + return 0u; } // This helper function allows creating a DrawCallParam from a list of arguments diff --git a/src/tests/white_box/VulkanImageWrappingTestsOpaqueFD.cpp b/src/tests/white_box/VulkanImageWrappingTestsOpaqueFD.cpp index 1e3bc75310..0862e163a7 100644 --- a/src/tests/white_box/VulkanImageWrappingTestsOpaqueFD.cpp +++ b/src/tests/white_box/VulkanImageWrappingTestsOpaqueFD.cpp @@ -960,12 +960,12 @@ namespace dawn_native { namespace vulkan { allocationSizeA, memoryTypeIndexA, {}); // Draw a non-trivial picture - int width = 640, height = 480, pixelSize = 4; + uint32_t width = 640, height = 480, pixelSize = 4; uint32_t rowPitch = Align(width * pixelSize, kTextureRowPitchAlignment); uint32_t size = rowPitch * (height - 1) + width * pixelSize; unsigned char data[size]; - for (int row = 0; row < height; row++) { - for (int col = 0; col < width; col++) { + for (uint32_t row = 0; row < height; row++) { + for (uint32_t col = 0; col < width; col++) { float normRow = static_cast(row) / height; float normCol = static_cast(col) / width; float dist = sqrt(normRow * normRow + normCol * normCol) * 3;