[cleanup] Replace `#pragma allow_unsafe_buffers` with targeted TODOs

Transition from file-wide or block-wide `#pragma allow_unsafe_buffers`
to targeted, line-level markings using `DAWN_UNSAFE_TODO`.
This makes unsafe buffer usages more explicit and searchable,
facilitating future cleanup work to eliminate them.

Changes:
- Removed `#pragma allow_unsafe_buffers` blocks where applicable.
- Wrapped specific unsafe operations (e.g., `memcpy`, `fread`, `fwrite`,
  array indexing) in `DAWN_UNSAFE_TODO`.

> NOTE: This patch includes files with <= 10 `DAWN_UNSAFE_TODO`
  insertions

Bug: chromium:507077205
Doc: go/unsafe-buffer-dawn
Change-Id: I88a11d3d7a441769b81643a475500517cf310729
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/308576
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Commit-Queue: Kai Ninomiya <kainino@chromium.org>
Reviewed-by: Kai Ninomiya <kainino@chromium.org>
diff --git a/src/dawn/native/Adapter.cpp b/src/dawn/native/Adapter.cpp
index 8a4646b..5e6e59f 100644
--- a/src/dawn/native/Adapter.cpp
+++ b/src/dawn/native/Adapter.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "dawn/native/Adapter.h"
 
 #include <algorithm>
@@ -48,6 +43,7 @@
 #include "dawn/native/Instance.h"
 #include "dawn/native/PhysicalDevice.h"
 #include "partition_alloc/pointers/raw_ptr.h"
+#include "src/utils/compiler.h"
 
 namespace dawn::native {
 namespace {
@@ -179,7 +175,7 @@
 
     auto AddString = [&](const std::string& in, StringView* out) {
         DAWN_CHECK(in.length() <= outBuffer.length());
-        memcpy(outBuffer.data(), in.data(), in.length());
+        DAWN_UNSAFE_TODO(memcpy(outBuffer.data(), in.data(), in.length()));
         *out = {outBuffer.data(), in.length()};
         outBuffer = outBuffer.subspan(in.length());
     };
@@ -293,7 +289,7 @@
 
     std::unordered_set<wgpu::FeatureName> requiredFeatureSet;
     for (uint32_t i = 0; i < descriptor->requiredFeatureCount; ++i) {
-        requiredFeatureSet.insert(descriptor->requiredFeatures[i]);
+        requiredFeatureSet.insert(DAWN_UNSAFE_TODO(descriptor->requiredFeatures[i]));
     }
 
     // Validate all required features are supported by the adapter and suitable under device
diff --git a/src/dawn/native/BlobCache.cpp b/src/dawn/native/BlobCache.cpp
index 9a005eb..efdb15c 100644
--- a/src/dawn/native/BlobCache.cpp
+++ b/src/dawn/native/BlobCache.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "dawn/native/BlobCache.h"
 
 #include <algorithm>
@@ -43,6 +38,7 @@
 #include "dawn/native/CacheKey.h"
 #include "dawn/native/Instance.h"
 #include "dawn/platform/DawnPlatform.h"
+#include "src/utils/compiler.h"
 
 namespace dawn::native {
 
@@ -59,7 +55,7 @@
     std::vector<std::byte> result(byteSizeWithHash);
 
     // Write the hash to the start of the buffer.
-    *reinterpret_cast<Hash*>(result.data()) = Hasher::Hash(value);
+    *DAWN_UNSAFE_TODO(reinterpret_cast<Hash*>(result.data())) = Hasher::Hash(value);
 
     // Write the payload after the hash.
     std::ranges::copy(value, result.begin() + kHashByteSize);
@@ -86,7 +82,7 @@
         const uint8_t* hashBytes = static_cast<const uint8_t*>(hash);
         for (size_t i = 0; i < kHashByteSize; i++) {
             ss << std::uppercase << std::hex << std::setw(2) << std::setfill('0')
-               << static_cast<int>(hashBytes[i]);
+               << static_cast<int>(DAWN_UNSAFE_TODO(hashBytes[i]));
         }
         return ss.str();
     };
diff --git a/src/dawn/native/ComputePassEncoder.cpp b/src/dawn/native/ComputePassEncoder.cpp
index be3a71e..2b2369d 100644
--- a/src/dawn/native/ComputePassEncoder.cpp
+++ b/src/dawn/native/ComputePassEncoder.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "dawn/native/ComputePassEncoder.h"
 
 #include <algorithm>
@@ -51,6 +46,7 @@
 #include "dawn/native/PassResourceUsageTracker.h"
 #include "dawn/native/QuerySet.h"
 #include "dawn/native/utils/WGPUHelpers.h"
+#include "src/utils/compiler.h"
 
 namespace dawn::native {
 
@@ -576,7 +572,7 @@
             cmd->offset = offset;
             cmd->size = uint32_t(size);
             uint8_t* immediateDatas = allocator->AllocateData<uint8_t>(cmd->size);
-            memcpy(immediateDatas, data, size);
+            DAWN_UNSAFE_TODO(memcpy(immediateDatas, data, size));
 
             mCommandBufferState.SetImmediateData(offset, uint32_t(size));
 
diff --git a/src/dawn/native/Instance.cpp b/src/dawn/native/Instance.cpp
index 0d9c9c0..fbcbc5c 100644
--- a/src/dawn/native/Instance.cpp
+++ b/src/dawn/native/Instance.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "dawn/native/Instance.h"
 
 #include <utility>
@@ -50,6 +45,7 @@
 #include "dawn/native/ValidationUtils_autogen.h"
 #include "dawn/platform/DawnPlatform.h"
 #include "partition_alloc/pointers/raw_ptr.h"
+#include "src/utils/compiler.h"
 
 // For SwiftShader fallback
 #if defined(DAWN_ENABLE_BACKEND_VULKAN)
@@ -304,7 +300,8 @@
     // Process DawnInstanceDescriptor
     if (const auto* dawnDesc = descriptor.Get<DawnInstanceDescriptor>()) {
         for (uint32_t i = 0; i < dawnDesc->additionalRuntimeSearchPathsCount; ++i) {
-            mRuntimeSearchPaths.push_back(dawnDesc->additionalRuntimeSearchPaths[i]);
+            mRuntimeSearchPaths.push_back(
+                DAWN_UNSAFE_TODO(dawnDesc->additionalRuntimeSearchPaths[i]));
         }
         SetPlatform(dawnDesc->platform);
 
@@ -784,7 +781,7 @@
     // Remove blocklisted features.
     if (wgslBlocklist != nullptr) {
         for (size_t i = 0; i < wgslBlocklist->blocklistedFeatureCount; i++) {
-            const char* name = wgslBlocklist->blocklistedFeatures[i];
+            const char* name = DAWN_UNSAFE_TODO(wgslBlocklist->blocklistedFeatures[i]);
             tint::wgsl::LanguageFeature tintFeature = tint::wgsl::ParseLanguageFeature(name);
             if (tintFeature == tint::wgsl::LanguageFeature::kUndefined) {
                 // Ignore unknown features in the blocklist.
@@ -807,7 +804,7 @@
     wgpu::WGSLLanguageFeatureName* wgslFeatures = new wgpu::WGSLLanguageFeatureName[featureCount];
     uint32_t index = 0;
     for (wgpu::WGSLLanguageFeatureName feature : mWGSLFeatures) {
-        wgslFeatures[index++] = feature;
+        DAWN_UNSAFE_TODO(wgslFeatures[index++]) = feature;
     }
     DAWN_CHECK(index == featureCount);
 
diff --git a/src/dawn/native/SwapChain.cpp b/src/dawn/native/SwapChain.cpp
index 60bbf6f..7cd469b 100644
--- a/src/dawn/native/SwapChain.cpp
+++ b/src/dawn/native/SwapChain.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "dawn/native/SwapChain.h"
 
 #include <utility>
@@ -42,6 +37,7 @@
 #include "dawn/native/Surface.h"
 #include "dawn/native/Texture.h"
 #include "dawn/native/ValidationUtils_autogen.h"
+#include "src/utils/compiler.h"
 
 namespace dawn::native {
 
@@ -71,11 +67,11 @@
       mAlphaMode(config->alphaMode),
       mSurface(surface) {
     for (uint32_t i = 0; i < config->viewFormatCount; ++i) {
-        if (config->viewFormats[i] == config->format) {
+        if (DAWN_UNSAFE_TODO(config->viewFormats[i]) == config->format) {
             // Skip our own format, like texture creations does.
             continue;
         }
-        mViewFormats.push_back(config->viewFormats[i]);
+        mViewFormats.push_back(DAWN_UNSAFE_TODO(config->viewFormats[i]));
     }
 }
 
diff --git a/src/dawn/native/Texture.cpp b/src/dawn/native/Texture.cpp
index ee710f9..9dad6d1 100644
--- a/src/dawn/native/Texture.cpp
+++ b/src/dawn/native/Texture.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "dawn/native/Texture.h"
 
 #include <algorithm>
@@ -53,6 +48,7 @@
 #include "dawn/native/ResourceTable.h"
 #include "dawn/native/SharedTextureMemory.h"
 #include "dawn/native/ValidationUtils_autogen.h"
+#include "src/utils/compiler.h"
 
 namespace dawn::native {
 
@@ -795,9 +791,9 @@
     }
 
     for (uint32_t i = 0; i < descriptor->viewFormatCount; ++i) {
-        DAWN_TRY_CONTEXT(
+        DAWN_UNSAFE_TODO(DAWN_TRY_CONTEXT(
             ValidateTextureViewFormatCompatibility(device, *format, descriptor->viewFormats[i]),
-            "validating viewFormats[%u]", i);
+            "validating viewFormats[%u]", i));
     }
 
     DAWN_INVALID_IF(descriptor->usage == wgpu::TextureUsage::None,
@@ -1067,12 +1063,13 @@
     mIsSubresourceContentInitializedAtIndex = std::vector<bool>(subresourceCount, false);
 
     for (uint32_t i = 0; i < descriptor->viewFormatCount; ++i) {
-        if (descriptor->viewFormats[i] == descriptor->format) {
+        if (DAWN_UNSAFE_TODO(descriptor->viewFormats[i]) == descriptor->format) {
             // Skip our own format, so the backends don't allocate the texture for
             // reinterpretation if it's not needed.
             continue;
         }
-        mViewFormats[device->GetValidInternalFormat(descriptor->viewFormats[i])] = true;
+        mViewFormats[device->GetValidInternalFormat(DAWN_UNSAFE_TODO(descriptor->viewFormats[i]))] =
+            true;
     }
 
     if (auto* internalUsageDesc = descriptor.Get<DawnTextureInternalUsageDescriptor>()) {
diff --git a/src/dawn/native/webgpu/PhysicalDeviceWGPU.cpp b/src/dawn/native/webgpu/PhysicalDeviceWGPU.cpp
index e6f755e..f5be482 100644
--- a/src/dawn/native/webgpu/PhysicalDeviceWGPU.cpp
+++ b/src/dawn/native/webgpu/PhysicalDeviceWGPU.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "dawn/native/webgpu/PhysicalDeviceWGPU.h"
 
 #include <string>
@@ -44,6 +39,7 @@
 #include "dawn/native/webgpu/BackendWGPU.h"
 #include "dawn/native/webgpu/DeviceWGPU.h"
 #include "dawn/native/webgpu/SwapChainWGPU.h"
+#include "src/utils/compiler.h"
 
 namespace dawn::native::webgpu {
 
@@ -125,13 +121,15 @@
     PhysicalDeviceSurfaceCapabilities capabilities;
     capabilities.usages = static_cast<wgpu::TextureUsage>(innerCapabilities.usages);
     for (size_t i = 0; i < innerCapabilities.formatCount; ++i) {
-        capabilities.formats.push_back(FromAPI(innerCapabilities.formats[i]));
+        capabilities.formats.push_back(FromAPI(DAWN_UNSAFE_TODO(innerCapabilities.formats[i])));
     }
     for (size_t i = 0; i < innerCapabilities.presentModeCount; ++i) {
-        capabilities.presentModes.push_back(FromAPI(innerCapabilities.presentModes[i]));
+        capabilities.presentModes.push_back(
+            FromAPI(DAWN_UNSAFE_TODO(innerCapabilities.presentModes[i])));
     }
     for (size_t i = 0; i < innerCapabilities.alphaModeCount; ++i) {
-        capabilities.alphaModes.push_back(FromAPI(innerCapabilities.alphaModes[i]));
+        capabilities.alphaModes.push_back(
+            FromAPI(DAWN_UNSAFE_TODO(innerCapabilities.alphaModes[i])));
     }
 
     mBackend->GetFunctions().surfaceCapabilitiesFreeMembers(innerCapabilities);
diff --git a/src/dawn/samples/ManualSurfaceTest.cpp b/src/dawn/samples/ManualSurfaceTest.cpp
index 5da441f..d0a52ee 100644
--- a/src/dawn/samples/ManualSurfaceTest.cpp
+++ b/src/dawn/samples/ManualSurfaceTest.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/439062058): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 // This is an example to manually test surface code. Controls are the following, scoped to the
 // currently focused window:
 //  - W: creates a new window.
@@ -102,6 +97,7 @@
 #include "dawn/utils/WGPUHelpers.h"
 #include "dawn/webgpu_cpp_print.h"
 #include "partition_alloc/pointers/raw_ptr.h"
+#include "src/utils/compiler.h"
 #include "webgpu/webgpu_glfw.h"
 
 template <typename T>
@@ -229,9 +225,11 @@
     data->currentConfig = config;
     data->targetConfig = config;
     SyncFromWindow(data.get());
-    data->presentModes.assign(caps.presentModes, caps.presentModes + caps.presentModeCount);
-    data->alphaModes.assign(caps.alphaModes, caps.alphaModes + caps.alphaModeCount);
-    data->formats.assign(caps.formats, caps.formats + caps.formatCount);
+    data->presentModes.assign(caps.presentModes,
+                              DAWN_UNSAFE_TODO(caps.presentModes + caps.presentModeCount));
+    data->alphaModes.assign(caps.alphaModes,
+                            DAWN_UNSAFE_TODO(caps.alphaModes + caps.alphaModeCount));
+    data->formats.assign(caps.formats, DAWN_UNSAFE_TODO(caps.formats + caps.formatCount));
 
     windows[window] = std::move(data);
 }
diff --git a/src/dawn/tests/end2end/ComputeLayoutMemoryBufferTests.cpp b/src/dawn/tests/end2end/ComputeLayoutMemoryBufferTests.cpp
index a30c590..422bae5 100644
--- a/src/dawn/tests/end2end/ComputeLayoutMemoryBufferTests.cpp
+++ b/src/dawn/tests/end2end/ComputeLayoutMemoryBufferTests.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include <algorithm>
 #include <array>
 #include <functional>
@@ -39,6 +34,7 @@
 #include "dawn/common/Math.h"
 #include "dawn/tests/DawnTest.h"
 #include "dawn/utils/WGPUHelpers.h"
+#include "src/utils/compiler.h"
 
 namespace dawn {
 namespace {
@@ -515,7 +511,7 @@
             mUseDxcEnabledOrNonD3D12 = true;
         } else {
             for (auto* enabledToggle : GetParam().forceEnabledWorkarounds) {
-                if (strncmp(enabledToggle, "use_dxc", 7) == 0) {
+                if (DAWN_UNSAFE_TODO(strncmp(enabledToggle, "use_dxc", 7)) == 0) {
                     mUseDxcEnabledOrNonD3D12 = true;
                     break;
                 }
@@ -709,7 +705,8 @@
     // silently transformed into a quiet NaN). Having NaN and Inf floating point data in input may
     // result in bitwise mismatch.
     field.CheckData([&](uint32_t offset, uint32_t size) {
-        EXPECT_BUFFER_U8_RANGE_EQ(expectedData.data() + offset, outputBuf, offset, size)
+        DAWN_UNSAFE_TODO(
+            EXPECT_BUFFER_U8_RANGE_EQ(expectedData.data() + offset, outputBuf, offset, size))
             << "offset: " << offset << "\n Input buffer:" << inputData << "Shader:\n"
             << shader << "\n";
     });
@@ -791,7 +788,8 @@
     // silently transformed into a quiet NaN). Having NaN and Inf floating point data in input may
     // result in bitwise mismatch.
     field.CheckData([&](uint32_t offset, uint32_t size) {
-        EXPECT_BUFFER_U8_RANGE_EQ(expectedData.data() + offset, outputBuf, offset, size)
+        DAWN_UNSAFE_TODO(
+            EXPECT_BUFFER_U8_RANGE_EQ(expectedData.data() + offset, outputBuf, offset, size))
             << "offset: " << offset << "\n Input buffer:" << inputData << "Shader:\n"
             << shader << "\n";
     });
diff --git a/src/dawn/tests/end2end/InfiniteLoopTests.cpp b/src/dawn/tests/end2end/InfiniteLoopTests.cpp
index 08af942..2db560f 100644
--- a/src/dawn/tests/end2end/InfiniteLoopTests.cpp
+++ b/src/dawn/tests/end2end/InfiniteLoopTests.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include <optional>
 #include <ostream>
 #include <string>
@@ -37,6 +32,7 @@
 
 #include "dawn/tests/DawnTest.h"
 #include "dawn/utils/WGPUHelpers.h"
+#include "src/utils/compiler.h"
 
 namespace dawn {
 namespace {
@@ -249,17 +245,17 @@
 
         std::optional<size_t> whereFound;
         for (size_t i = 0; i < size / sizeof(T); i++) {
-            if (actual[i] == mValue) {
+            if (DAWN_UNSAFE_TODO(actual[i]) == mValue) {
                 if (whereFound.has_value()) {
                     return testing::AssertionFailure()
                            << "Found value " << mValue << " at data[" << whereFound.value()
                            << "] and data[" << i << "]\n";
                 }
                 whereFound = i;
-            } else if (actual[i] != 0) {
+            } else if (DAWN_UNSAFE_TODO(actual[i]) != 0) {
                 return testing::AssertionFailure()
-                       << "Found unexpected value data[" << i << "] = " << actual[i]
-                       << " instead of " << mValue << "\n";
+                       << "Found unexpected value data[" << i
+                       << "] = " << DAWN_UNSAFE_TODO(actual[i]) << " instead of " << mValue << "\n";
             }
         }
         if (!whereFound.has_value()) {
diff --git a/src/dawn/tests/end2end/MemoryHeapPropertiesTests.cpp b/src/dawn/tests/end2end/MemoryHeapPropertiesTests.cpp
index ae4fca4..911dfaf 100644
--- a/src/dawn/tests/end2end/MemoryHeapPropertiesTests.cpp
+++ b/src/dawn/tests/end2end/MemoryHeapPropertiesTests.cpp
@@ -25,14 +25,10 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include <vector>
 
 #include "dawn/tests/DawnTest.h"
+#include "src/utils/compiler.h"
 
 namespace dawn {
 namespace {
@@ -43,7 +39,7 @@
         EXPECT_GT(memoryHeapProperties.heapCount, 0u);
         for (size_t i = 0; i < memoryHeapProperties.heapCount; ++i) {
             // Check the heap is non-zero in size.
-            EXPECT_GT(memoryHeapProperties.heapInfo[i].size, 0ull);
+            DAWN_UNSAFE_TODO(EXPECT_GT(memoryHeapProperties.heapInfo[i].size, 0ull));
 
             constexpr wgpu::HeapProperty kValidProps =
                 wgpu::HeapProperty::DeviceLocal | wgpu::HeapProperty::HostVisible |
@@ -51,10 +47,11 @@
                 wgpu::HeapProperty::HostCached;
 
             // Check the heap properties only contain the set of valid enums.
-            EXPECT_EQ(memoryHeapProperties.heapInfo[i].properties & ~kValidProps, 0u);
+            DAWN_UNSAFE_TODO(
+                EXPECT_EQ(memoryHeapProperties.heapInfo[i].properties & ~kValidProps, 0u));
 
             // Check the heap properties have at least one bit.
-            EXPECT_NE(uint32_t(memoryHeapProperties.heapInfo[i].properties), 0u);
+            DAWN_UNSAFE_TODO(EXPECT_NE(uint32_t(memoryHeapProperties.heapInfo[i].properties), 0u));
         }
     }
 };
diff --git a/src/dawn/tests/end2end/PrimitiveTopologyTests.cpp b/src/dawn/tests/end2end/PrimitiveTopologyTests.cpp
index f025997..2a2ef8e 100644
--- a/src/dawn/tests/end2end/PrimitiveTopologyTests.cpp
+++ b/src/dawn/tests/end2end/PrimitiveTopologyTests.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include <vector>
 
 #include "dawn/common/Assert.h"
@@ -37,6 +32,7 @@
 #include "dawn/utils/ComboRenderPipelineDescriptor.h"
 #include "dawn/utils/WGPUHelpers.h"
 #include "partition_alloc/pointers/raw_ptr.h"
+#include "src/utils/compiler.h"
 
 namespace dawn {
 namespace {
@@ -242,10 +238,11 @@
                 // black
                 utils::RGBA8 color =
                     locationSpec.include ? utils::RGBA8::kGreen : utils::RGBA8::kZero;
-                EXPECT_PIXEL_RGBA8_EQ(color, renderPass.color, locationSpec.locations[i].x,
-                                      locationSpec.locations[i].y)
-                    << "Expected (" << locationSpec.locations[i].x << ", "
-                    << locationSpec.locations[i].y << ") to be " << color;
+                DAWN_UNSAFE_TODO(EXPECT_PIXEL_RGBA8_EQ(color, renderPass.color,
+                                                       locationSpec.locations[i].x,
+                                                       locationSpec.locations[i].y))
+                    << "Expected (" << DAWN_UNSAFE_TODO(locationSpec.locations[i]).x << ", "
+                    << DAWN_UNSAFE_TODO(locationSpec.locations[i]).y << ") to be " << color;
             }
         }
     }
diff --git a/src/dawn/tests/unittests/wire/WireInjectSurfaceTests.cpp b/src/dawn/tests/unittests/wire/WireInjectSurfaceTests.cpp
index 0ed1265..0e12c50 100644
--- a/src/dawn/tests/unittests/wire/WireInjectSurfaceTests.cpp
+++ b/src/dawn/tests/unittests/wire/WireInjectSurfaceTests.cpp
@@ -25,17 +25,13 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include <array>
 #include <utility>
 
 #include "dawn/tests/unittests/wire/WireTest.h"
 #include "dawn/wire/WireClient.h"
 #include "dawn/wire/WireServer.h"
+#include "src/utils/compiler.h"
 
 namespace dawn::wire {
 namespace {
@@ -197,19 +193,20 @@
 
     EXPECT_EQ(caps.formatCount, mCapabilities.formatCount);
     for (uint32_t i = 0; i < caps.formatCount; i++) {
-        EXPECT_EQ(static_cast<WGPUTextureFormat>(caps.formats[i]), mCapabilities.formats[i]);
+        DAWN_UNSAFE_TODO(
+            EXPECT_EQ(static_cast<WGPUTextureFormat>(caps.formats[i]), mCapabilities.formats[i]));
     }
 
     EXPECT_EQ(caps.presentModeCount, mCapabilities.presentModeCount);
     for (uint32_t i = 0; i < caps.presentModeCount; i++) {
-        EXPECT_EQ(static_cast<WGPUPresentMode>(caps.presentModes[i]),
-                  mCapabilities.presentModes[i]);
+        DAWN_UNSAFE_TODO(EXPECT_EQ(static_cast<WGPUPresentMode>(caps.presentModes[i]),
+                                   mCapabilities.presentModes[i]));
     }
 
     EXPECT_EQ(caps.alphaModeCount, mCapabilities.alphaModeCount);
     for (uint32_t i = 0; i < caps.alphaModeCount; i++) {
-        EXPECT_EQ(static_cast<WGPUCompositeAlphaMode>(caps.alphaModes[i]),
-                  mCapabilities.alphaModes[i]);
+        DAWN_UNSAFE_TODO(EXPECT_EQ(static_cast<WGPUCompositeAlphaMode>(caps.alphaModes[i]),
+                                   mCapabilities.alphaModes[i]));
     }
 
     EXPECT_EQ(static_cast<WGPUTextureUsage>(caps.usages), mCapabilities.usages);
diff --git a/src/dawn/wire/client/Surface.cpp b/src/dawn/wire/client/Surface.cpp
index 692d469..1b49ad8 100644
--- a/src/dawn/wire/client/Surface.cpp
+++ b/src/dawn/wire/client/Surface.cpp
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/439062058): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "dawn/wire/client/Surface.h"
 
 #include <algorithm>
@@ -41,6 +36,7 @@
 #include "dawn/wire/client/Device.h"
 #include "dawn/wire/client/Texture.h"
 #include "dawn/wire/client/webgpu.h"
+#include "src/utils/compiler.h"
 
 namespace dawn::wire::client {
 
@@ -49,11 +45,13 @@
     // Copy over the capabilities.
     mSupportedUsages = capabilities->usages;
     mSupportedFormats.assign(capabilities->formats,
-                             capabilities->formats + capabilities->formatCount);
-    mSupportedPresentModes.assign(capabilities->presentModes,
-                                  capabilities->presentModes + capabilities->presentModeCount);
-    mSupportedAlphaModes.assign(capabilities->alphaModes,
-                                capabilities->alphaModes + capabilities->alphaModeCount);
+                             DAWN_UNSAFE_TODO(capabilities->formats + capabilities->formatCount));
+    mSupportedPresentModes.assign(
+        capabilities->presentModes,
+        DAWN_UNSAFE_TODO(capabilities->presentModes + capabilities->presentModeCount));
+    mSupportedAlphaModes.assign(
+        capabilities->alphaModes,
+        DAWN_UNSAFE_TODO(capabilities->alphaModes + capabilities->alphaModeCount));
 
     DAWN_ASSERT(!mSupportedFormats.empty() && !mSupportedPresentModes.empty() &&
                 !mSupportedAlphaModes.empty());
diff --git a/src/utils/chromium_test_compat/BUILD.gn b/src/utils/chromium_test_compat/BUILD.gn
index 0323029..11ec8a0 100644
--- a/src/utils/chromium_test_compat/BUILD.gn
+++ b/src/utils/chromium_test_compat/BUILD.gn
@@ -47,4 +47,6 @@
   ]
 
   public_configs = [ ":internal_config" ]
+
+  deps = [ "../:utils" ]
 }
diff --git a/src/utils/chromium_test_compat/chromium_test_compat.cc b/src/utils/chromium_test_compat/chromium_test_compat.cc
index f7cc0cb..b28f28a 100644
--- a/src/utils/chromium_test_compat/chromium_test_compat.cc
+++ b/src/utils/chromium_test_compat/chromium_test_compat.cc
@@ -25,11 +25,6 @@
 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 
-#ifdef UNSAFE_BUFFERS_BUILD
-// TODO(crbug.com/40285824): Remove this and convert code to safer constructs.
-#pragma allow_unsafe_buffers
-#endif
-
 #include "src/utils/chromium_test_compat/chromium_test_compat.h"
 
 #include <cstdio>
@@ -38,12 +33,14 @@
 #include <string>
 #include <string_view>
 
+#include "src/utils/compiler.h"
+
 namespace dawn {
 void SubstituteChromiumArgs(int argc, char** argv) {
     std::string testSummaryOutputArg("--test-launcher-summary-output=");
 
     for (int i = 0; i < argc; i++) {
-        std::string_view argument(argv[i]);
+        std::string_view argument(DAWN_UNSAFE_TODO(argv[i]));
 
         // Look to replace "--test-launcher-summary-output=" with "--gtest_output=json:". The former
         // is a Chromium-specific flag for where to output results in a Chromium-specific format,
@@ -58,8 +55,9 @@
             replacementArg += argValue;
             std::cout << "Replacing " << argument << " with " << replacementArg << "\n";
             size_t bufferSize = replacementArg.length() + 1;
-            argv[i] = new char[bufferSize];
-            int charsWritten = std::snprintf(argv[i], bufferSize, "%s", replacementArg.c_str());
+            DAWN_UNSAFE_TODO(argv[i]) = new char[bufferSize];
+            int charsWritten =
+                DAWN_UNSAFE_TODO(std::snprintf(argv[i], bufferSize, "%s", replacementArg.c_str()));
 
             if (size_t(charsWritten) != replacementArg.length()) {
                 abort();