Fix more compilation warnings.

Bug: chromium:1064305
Change-Id: I3aac24f8179d2c9e5206dd4542ea2506f26755e9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/19301
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Austin Eng <enga@chromium.org>
Commit-Queue: Zhenyao Mo <zmo@google.com>
diff --git a/generator/templates/dawn_wire/WireCmd.cpp b/generator/templates/dawn_wire/WireCmd.cpp
index 5f6a666..002f84c 100644
--- a/generator/templates/dawn_wire/WireCmd.cpp
+++ b/generator/templates/dawn_wire/WireCmd.cpp
@@ -414,12 +414,12 @@
 
     // Macro to simplify error handling, similar to DAWN_TRY but for DeserializeResult.
 #define DESERIALIZE_TRY(EXPR) \
-    { \
+    do { \
         DeserializeResult exprResult = EXPR; \
         if (exprResult != DeserializeResult::Success) { \
             return exprResult; \
         } \
-    }
+    } while (0)
 
     ObjectHandle::ObjectHandle() = default;
     ObjectHandle::ObjectHandle(ObjectId id, ObjectSerial serial) : id(id), serial(serial) {}
diff --git a/src/common/BUILD.gn b/src/common/BUILD.gn
index b9d674f..b696523 100644
--- a/src/common/BUILD.gn
+++ b/src/common/BUILD.gn
@@ -95,6 +95,12 @@
       "-Wshadow-field",
       "-Wmissing-field-initializers",
       "-Wcstring-format-directive",
+      "-Wtautological-unsigned-zero-compare",
+      "-Wreturn-std-move-in-c++11",
+
+      # Turn on the following flag after removing the empty statement in
+      # third_party/glm/glm/simd/common.h:106
+      # "-Wextra-semi-stmt",
     ]
   }
 }
@@ -143,13 +149,9 @@
     ]
 
     public_configs = [ ":dawn_internal" ]
-    deps = [
-      "${dawn_root}/src/dawn:dawn_headers",
-    ]
+    deps = [ "${dawn_root}/src/dawn:dawn_headers" ]
     if (dawn_enable_vulkan) {
-      public_deps = [
-        "${dawn_root}/third_party/khronos:vulkan_headers",
-      ]
+      public_deps = [ "${dawn_root}/third_party/khronos:vulkan_headers" ]
     }
     if (is_android) {
       libs = [ "log" ]
diff --git a/src/dawn_native/BuddyMemoryAllocator.cpp b/src/dawn_native/BuddyMemoryAllocator.cpp
index c3caa5b..6a428d9 100644
--- a/src/dawn_native/BuddyMemoryAllocator.cpp
+++ b/src/dawn_native/BuddyMemoryAllocator.cpp
@@ -42,7 +42,7 @@
         ResourceMemoryAllocation invalidAllocation = ResourceMemoryAllocation{};
 
         if (allocationSize == 0) {
-            return invalidAllocation;
+            return std::move(invalidAllocation);
         }
 
         // Round allocation size to nearest power-of-two.
@@ -50,13 +50,13 @@
 
         // Allocation cannot exceed the memory size.
         if (allocationSize > mMemoryBlockSize) {
-            return invalidAllocation;
+            return std::move(invalidAllocation);
         }
 
         // Attempt to sub-allocate a block of the requested size.
         const uint64_t blockOffset = mBuddyBlockAllocator.Allocate(allocationSize, alignment);
         if (blockOffset == BuddyAllocator::kInvalidOffset) {
-            return invalidAllocation;
+            return std::move(invalidAllocation);
         }
 
         const uint64_t memoryIndex = GetMemoryIndex(blockOffset);
diff --git a/src/dawn_native/ShaderModule.cpp b/src/dawn_native/ShaderModule.cpp
index a619406..6d3b2b6 100644
--- a/src/dawn_native/ShaderModule.cpp
+++ b/src/dawn_native/ShaderModule.cpp
@@ -700,7 +700,7 @@
                     SpirvCrossBaseTypeToFormatType(shaderFragmentOutputBaseType);
                 if (formatType == Format::Type::Other) {
                     return DAWN_VALIDATION_ERROR("Unexpected Fragment output type");
-                };
+                }
                 mFragmentOutputFormatBaseTypes[location] = formatType;
             }
         }
diff --git a/src/dawn_native/d3d12/BackendD3D12.cpp b/src/dawn_native/d3d12/BackendD3D12.cpp
index b7a3f82..eea9720 100644
--- a/src/dawn_native/d3d12/BackendD3D12.cpp
+++ b/src/dawn_native/d3d12/BackendD3D12.cpp
@@ -65,7 +65,7 @@
             }
 
             ASSERT(factory != nullptr);
-            return factory;
+            return std::move(factory);
         }
 
     }  // anonymous namespace
diff --git a/src/dawn_native/d3d12/DeviceD3D12.cpp b/src/dawn_native/d3d12/DeviceD3D12.cpp
index f1f9baa..9dce6e3 100644
--- a/src/dawn_native/d3d12/DeviceD3D12.cpp
+++ b/src/dawn_native/d3d12/DeviceD3D12.cpp
@@ -395,7 +395,7 @@
         DAWN_TRY(CheckHRESULT(d3d11Texture.As(&dxgiKeyedMutex),
                               "D3D12 QueryInterface ID3D11Texture2D to IDXGIKeyedMutex"));
 
-        return dxgiKeyedMutex;
+        return std::move(dxgiKeyedMutex);
     }
 
     void Device::ReleaseKeyedMutexForTexture(ComPtr<IDXGIKeyedMutex> dxgiKeyedMutex) {
diff --git a/src/dawn_native/d3d12/DeviceD3D12.h b/src/dawn_native/d3d12/DeviceD3D12.h
index 364951e..38334d5 100644
--- a/src/dawn_native/d3d12/DeviceD3D12.h
+++ b/src/dawn_native/d3d12/DeviceD3D12.h
@@ -39,10 +39,10 @@
     class StagingDescriptorAllocator;
 
 #define ASSERT_SUCCESS(hr)            \
-    {                                 \
+    do {                              \
         HRESULT succeeded = hr;       \
         ASSERT(SUCCEEDED(succeeded)); \
-    }
+    } while (0)
 
     // Definition of backend types
     class Device : public DeviceBase {
diff --git a/src/dawn_native/d3d12/HeapAllocatorD3D12.cpp b/src/dawn_native/d3d12/HeapAllocatorD3D12.cpp
index ced2dd1..a038714 100644
--- a/src/dawn_native/d3d12/HeapAllocatorD3D12.cpp
+++ b/src/dawn_native/d3d12/HeapAllocatorD3D12.cpp
@@ -57,7 +57,7 @@
         // Calling CreateHeap implicitly calls MakeResident on the new heap. We must track this to
         // avoid calling MakeResident a second time.
         mDevice->GetResidencyManager()->TrackResidentAllocation(ToBackend(heapBase.get()));
-        return heapBase;
+        return std::move(heapBase);
     }
 
     void HeapAllocator::DeallocateResourceHeap(std::unique_ptr<ResourceHeapBase> heap) {
diff --git a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp
index 803dc6c..f881b8d 100644
--- a/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp
+++ b/src/dawn_native/d3d12/ResourceAllocatorManagerD3D12.cpp
@@ -162,7 +162,7 @@
         DAWN_TRY_ASSIGN(subAllocation,
                         CreatePlacedResource(heapType, resourceDescriptor, initialUsage));
         if (subAllocation.GetInfo().mMethod != AllocationMethod::kInvalid) {
-            return subAllocation;
+            return std::move(subAllocation);
         }
 
         // If sub-allocation fails, fall-back to direct allocation (committed resource).
@@ -170,7 +170,7 @@
         DAWN_TRY_ASSIGN(directAllocation,
                         CreateCommittedResource(heapType, resourceDescriptor, initialUsage));
 
-        return directAllocation;
+        return std::move(directAllocation);
     }
 
     void ResourceAllocatorManager::Tick(Serial completedSerial) {
diff --git a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp
index 086a259..45f87c0 100644
--- a/src/dawn_native/d3d12/ShaderModuleD3D12.cpp
+++ b/src/dawn_native/d3d12/ShaderModuleD3D12.cpp
@@ -122,7 +122,7 @@
             std::string result_string;
             DAWN_TRY(CheckSpvcSuccess(result.GetStringOutput(&result_string),
                                       "Unable to get HLSL shader text"));
-            return result_string;
+            return std::move(result_string);
         } else {
             return compiler->compile();
         }
diff --git a/src/dawn_native/metal/BackendMTL.mm b/src/dawn_native/metal/BackendMTL.mm
index dd7e25f..63567a2 100644
--- a/src/dawn_native/metal/BackendMTL.mm
+++ b/src/dawn_native/metal/BackendMTL.mm
@@ -183,7 +183,7 @@
             if (!instance->ConsumedError(GetDevicePCIInfo(device, &ids))) {
                 mPCIInfo.vendorId = ids.vendorId;
                 mPCIInfo.deviceId = ids.deviceId;
-            };
+            }
 
 #if defined(DAWN_PLATFORM_IOS)
             mAdapterType = wgpu::AdapterType::IntegratedGPU;
diff --git a/src/dawn_native/vulkan/ResourceMemoryAllocatorVk.cpp b/src/dawn_native/vulkan/ResourceMemoryAllocatorVk.cpp
index 3c2ae56..e038d02 100644
--- a/src/dawn_native/vulkan/ResourceMemoryAllocatorVk.cpp
+++ b/src/dawn_native/vulkan/ResourceMemoryAllocatorVk.cpp
@@ -120,7 +120,7 @@
             DAWN_TRY_ASSIGN(subAllocation,
                             mAllocatorsPerType[memoryType]->AllocateMemory(requirements));
             if (subAllocation.GetInfo().mMethod != AllocationMethod::kInvalid) {
-                return subAllocation;
+                return std::move(subAllocation);
             }
         }
 
diff --git a/src/dawn_native/vulkan/VulkanFunctions.cpp b/src/dawn_native/vulkan/VulkanFunctions.cpp
index 159b740..6099c0a 100644
--- a/src/dawn_native/vulkan/VulkanFunctions.cpp
+++ b/src/dawn_native/vulkan/VulkanFunctions.cpp
@@ -19,11 +19,13 @@
 
 namespace dawn_native { namespace vulkan {
 
-#define GET_GLOBAL_PROC(name)                                                          \
-    name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(nullptr, "vk" #name)); \
-    if (name == nullptr) {                                                             \
-        return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #name);       \
-    }
+#define GET_GLOBAL_PROC(name)                                                              \
+    do {                                                                                   \
+        name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(nullptr, "vk" #name)); \
+        if (name == nullptr) {                                                             \
+            return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #name);       \
+        }                                                                                  \
+    } while (0)
 
     MaybeError VulkanFunctions::LoadGlobalProcs(const DynamicLib& vulkanLib) {
         if (!vulkanLib.GetProc(&GetInstanceProcAddr, "vkGetInstanceProcAddr")) {
@@ -41,11 +43,13 @@
         return {};
     }
 
-#define GET_INSTANCE_PROC_BASE(name, procName)                                              \
-    name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(instance, "vk" #procName)); \
-    if (name == nullptr) {                                                                  \
-        return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #procName);        \
-    }
+#define GET_INSTANCE_PROC_BASE(name, procName)                                                  \
+    do {                                                                                        \
+        name = reinterpret_cast<decltype(name)>(GetInstanceProcAddr(instance, "vk" #procName)); \
+        if (name == nullptr) {                                                                  \
+            return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #procName);        \
+        }                                                                                       \
+    } while (0)
 
 #define GET_INSTANCE_PROC(name) GET_INSTANCE_PROC_BASE(name, name)
 #define GET_INSTANCE_PROC_VENDOR(name, vendor) GET_INSTANCE_PROC_BASE(name, name##vendor)
@@ -144,11 +148,13 @@
         return {};
     }
 
-#define GET_DEVICE_PROC(name)                                                       \
-    name = reinterpret_cast<decltype(name)>(GetDeviceProcAddr(device, "vk" #name)); \
-    if (name == nullptr) {                                                          \
-        return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #name);    \
-    }
+#define GET_DEVICE_PROC(name)                                                           \
+    do {                                                                                \
+        name = reinterpret_cast<decltype(name)>(GetDeviceProcAddr(device, "vk" #name)); \
+        if (name == nullptr) {                                                          \
+            return DAWN_INTERNAL_ERROR(std::string("Couldn't get proc vk") + #name);    \
+        }                                                                               \
+    } while (0)
 
     MaybeError VulkanFunctions::LoadDeviceProcs(VkDevice device,
                                                 const VulkanDeviceInfo& deviceInfo) {
diff --git a/src/dawn_native/vulkan/VulkanInfo.cpp b/src/dawn_native/vulkan/VulkanInfo.cpp
index 3d2f66c..4ec4dfd 100644
--- a/src/dawn_native/vulkan/VulkanInfo.cpp
+++ b/src/dawn_native/vulkan/VulkanInfo.cpp
@@ -196,7 +196,7 @@
 
         // TODO(cwallez@chromium:org): Each layer can expose additional extensions, query them?
 
-        return info;
+        return std::move(info);
     }
 
     ResultOrError<std::vector<VkPhysicalDevice>> GetPhysicalDevices(const Backend& backend) {
@@ -215,7 +215,7 @@
             vkFunctions.EnumeratePhysicalDevices(instance, &count, physicalDevices.data()),
             "vkEnumeratePhysicalDevices"));
 
-        return physicalDevices;
+        return std::move(physicalDevices);
     }
 
     ResultOrError<VulkanDeviceInfo> GatherDeviceInfo(const Adapter& adapter) {
@@ -321,7 +321,7 @@
 
         // TODO(cwallez@chromium.org): gather info about formats
 
-        return info;
+        return std::move(info);
     }
 
     ResultOrError<VulkanSurfaceInfo> GatherSurfaceInfo(const Adapter& adapter,
@@ -382,7 +382,7 @@
                                     "vkGetPhysicalDeviceSurfacePresentModesKHR"));
         }
 
-        return info;
+        return std::move(info);
     }
 
 }}  // namespace dawn_native::vulkan
diff --git a/src/dawn_platform/tracing/TraceEvent.h b/src/dawn_platform/tracing/TraceEvent.h
index 06b6c50..a246154 100644
--- a/src/dawn_platform/tracing/TraceEvent.h
+++ b/src/dawn_platform/tracing/TraceEvent.h
@@ -689,13 +689,15 @@
 #define INTERNAL_TRACE_EVENT_ADD_SCOPED(platform, category, name, ...)                         \
     INTERNAL_TRACE_EVENT_GET_CATEGORY_INFO(platform, ::dawn_platform::TraceCategory::category) \
     dawn_platform::TraceEvent::TraceEndOnScopeClose INTERNALTRACEEVENTUID(profileScope);       \
-    if (*INTERNALTRACEEVENTUID(catstatic)) {                                                   \
-        dawn_platform::TraceEvent::addTraceEvent(                                              \
-            platform, TRACE_EVENT_PHASE_BEGIN, INTERNALTRACEEVENTUID(catstatic), name,         \
-            dawn_platform::TraceEvent::noEventId, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__);       \
-        INTERNALTRACEEVENTUID(profileScope)                                                    \
-            .initialize(platform, INTERNALTRACEEVENTUID(catstatic), name);                     \
-    }
+    do {                                                                                       \
+        if (*INTERNALTRACEEVENTUID(catstatic)) {                                               \
+            dawn_platform::TraceEvent::addTraceEvent(                                          \
+                platform, TRACE_EVENT_PHASE_BEGIN, INTERNALTRACEEVENTUID(catstatic), name,     \
+                dawn_platform::TraceEvent::noEventId, TRACE_EVENT_FLAG_NONE, ##__VA_ARGS__);   \
+            INTERNALTRACEEVENTUID(profileScope)                                                \
+                .initialize(platform, INTERNALTRACEEVENTUID(catstatic), name);                 \
+        }                                                                                      \
+    } while (0)
 
 // Implementation detail: internal macro to create static category and add
 // event if the category is enabled.
diff --git a/src/tests/DawnTest.h b/src/tests/DawnTest.h
index 72e0b92..b7c81fd 100644
--- a/src/tests/DawnTest.h
+++ b/src/tests/DawnTest.h
@@ -63,7 +63,7 @@
     StartExpectDeviceError();          \
     statement;                         \
     FlushWire();                       \
-    ASSERT_TRUE(EndExpectDeviceError());
+    ASSERT_TRUE(EndExpectDeviceError())
 
 struct RGBA8 {
     constexpr RGBA8() : RGBA8(0, 0, 0, 0) {
@@ -314,12 +314,14 @@
 };
 
 // Skip a test when the given condition is satisfied.
-#define DAWN_SKIP_TEST_IF(condition)                        \
-    if (condition) {                                        \
-        dawn::InfoLog() << "Test skipped: " #condition "."; \
-        GTEST_SKIP();                                       \
-        return;                                             \
-    }
+#define DAWN_SKIP_TEST_IF(condition)                            \
+    do {                                                        \
+        if (condition) {                                        \
+            dawn::InfoLog() << "Test skipped: " #condition "."; \
+            GTEST_SKIP();                                       \
+            return;                                             \
+        }                                                       \
+    } while (0)
 
 template <typename Params = DawnTestParam>
 class DawnTestWithParams : public DawnTestBase, public ::testing::TestWithParam<Params> {
diff --git a/src/tests/end2end/TextureZeroInitTests.cpp b/src/tests/end2end/TextureZeroInitTests.cpp
index 52d7094..79993ad 100644
--- a/src/tests/end2end/TextureZeroInitTests.cpp
+++ b/src/tests/end2end/TextureZeroInitTests.cpp
@@ -18,15 +18,17 @@
 #include "utils/ComboRenderPipelineDescriptor.h"
 #include "utils/WGPUHelpers.h"
 
-#define EXPECT_LAZY_CLEAR(N, statement)                                                   \
-    if (UsesWire()) {                                                                     \
-        statement;                                                                        \
-    } else {                                                                              \
-        size_t lazyClearsBefore = dawn_native::GetLazyClearCountForTesting(device.Get()); \
-        statement;                                                                        \
-        size_t lazyClearsAfter = dawn_native::GetLazyClearCountForTesting(device.Get());  \
-        EXPECT_EQ(N, lazyClearsAfter - lazyClearsBefore);                                 \
-    }
+#define EXPECT_LAZY_CLEAR(N, statement)                                                       \
+    do {                                                                                      \
+        if (UsesWire()) {                                                                     \
+            statement;                                                                        \
+        } else {                                                                              \
+            size_t lazyClearsBefore = dawn_native::GetLazyClearCountForTesting(device.Get()); \
+            statement;                                                                        \
+            size_t lazyClearsAfter = dawn_native::GetLazyClearCountForTesting(device.Get());  \
+            EXPECT_EQ(N, lazyClearsAfter - lazyClearsBefore);                                 \
+        }                                                                                     \
+    } while (0)
 
 class TextureZeroInitTest : public DawnTest {
   protected:
diff --git a/src/tests/unittests/validation/ValidationTest.h b/src/tests/unittests/validation/ValidationTest.h
index 388606a..eeac5a6 100644
--- a/src/tests/unittests/validation/ValidationTest.h
+++ b/src/tests/unittests/validation/ValidationTest.h
@@ -22,7 +22,7 @@
 #define ASSERT_DEVICE_ERROR(statement) \
     StartExpectDeviceError(); \
     statement; \
-    ASSERT_TRUE(EndExpectDeviceError());
+    ASSERT_TRUE(EndExpectDeviceError())
 
 class ValidationTest : public testing::Test {
   public:
diff --git a/src/tests/white_box/D3D12ResidencyTests.cpp b/src/tests/white_box/D3D12ResidencyTests.cpp
index 21fca34..5860d0a 100644
--- a/src/tests/white_box/D3D12ResidencyTests.cpp
+++ b/src/tests/white_box/D3D12ResidencyTests.cpp
@@ -194,7 +194,7 @@
 TEST_P(D3D12ResidencyTests, AsyncMappedBufferRead) {
     // Dawn currently only manages LOCAL_MEMORY. Mappable buffers exist in NON_LOCAL_MEMORY on
     // discrete devices.
-    DAWN_SKIP_TEST_IF(!IsUMA())
+    DAWN_SKIP_TEST_IF(!IsUMA());
 
     // Create a mappable buffer.
     wgpu::Buffer buffer = CreateBuffer(4, wgpu::BufferUsage::MapRead | wgpu::BufferUsage::CopyDst);
@@ -239,7 +239,7 @@
 TEST_P(D3D12ResidencyTests, AsyncMappedBufferWrite) {
     // Dawn currently only manages LOCAL_MEMORY. Mappable buffers exist in NON_LOCAL_MEMORY on
     // discrete devices.
-    DAWN_SKIP_TEST_IF(!IsUMA())
+    DAWN_SKIP_TEST_IF(!IsUMA());
 
     // Create a mappable buffer.
     wgpu::Buffer buffer = CreateBuffer(4, wgpu::BufferUsage::MapWrite | wgpu::BufferUsage::CopySrc);
@@ -276,4 +276,4 @@
     EXPECT_FALSE(CheckIfBufferIsResident(buffer));
 }
 
-DAWN_INSTANTIATE_TEST(D3D12ResidencyTests, D3D12Backend());
\ No newline at end of file
+DAWN_INSTANTIATE_TEST(D3D12ResidencyTests, D3D12Backend());
diff --git a/src/utils/GLFWUtils.cpp b/src/utils/GLFWUtils.cpp
index fe9195e..55737dd 100644
--- a/src/utils/GLFWUtils.cpp
+++ b/src/utils/GLFWUtils.cpp
@@ -61,7 +61,7 @@
             std::make_unique<wgpu::SurfaceDescriptorFromWindowsHWND>();
         desc->hwnd = glfwGetWin32Window(window);
         desc->hinstance = GetModuleHandle(nullptr);
-        return desc;
+        return std::move(desc);
     }
 #elif defined(DAWN_USE_X11)
     std::unique_ptr<wgpu::ChainedStruct> SetupWindowAndGetSurfaceDescriptorForTesting(
@@ -70,7 +70,7 @@
             std::make_unique<wgpu::SurfaceDescriptorFromXlib>();
         desc->display = glfwGetX11Display();
         desc->window = glfwGetX11Window(window);
-        return desc;
+        return std::move(desc);
     }
 #elif defined(DAWN_ENABLE_BACKEND_METAL)
     // SetupWindowAndGetSurfaceDescriptorForTesting defined in GLFWUtils_metal.mm
diff --git a/src/utils/GLFWUtils_metal.mm b/src/utils/GLFWUtils_metal.mm
index ff09428..a920ec0 100644
--- a/src/utils/GLFWUtils_metal.mm
+++ b/src/utils/GLFWUtils_metal.mm
@@ -45,7 +45,7 @@
             std::unique_ptr<wgpu::SurfaceDescriptorFromMetalLayer> desc =
                 std::make_unique<wgpu::SurfaceDescriptorFromMetalLayer>();
             desc->layer = [view layer];
-            return desc;
+            return std::move(desc);
         }
 
         return nullptr;