tint/transform: Strip unused atomic builtins

If a SPIR-V program declared spirv-atomic stubs, but didn't call them then the transform could be skipped, leaving stub functions behind. This could cause writers to vomit.

Ensure that these are correctly stripped.

Bug: oss-fuzz:54057
Change-Id: I27c89a621163b1a3cc5e2ef375f846a094434062
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/113023
Commit-Queue: Ben Clayton <bclayton@google.com>
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/transform/spirv_atomic.cc b/src/tint/transform/spirv_atomic.cc
index de3cdab..72304e6 100644
--- a/src/tint/transform/spirv_atomic.cc
+++ b/src/tint/transform/spirv_atomic.cc
@@ -64,6 +64,8 @@
     /// Runs the transform
     /// @returns the new program or SkipTransform if the transform is not required
     ApplyResult Run() {
+        bool made_changes = false;
+
         // Look for stub functions generated by the SPIR-V reader, which are used as placeholders
         // for atomic builtin calls.
         for (auto* fn : ctx.src->AST().Functions()) {
@@ -104,10 +106,11 @@
 
                 // Remove the stub from the output program
                 ctx.Remove(ctx.src->AST().GlobalDeclarations(), fn);
+                made_changes = true;
             }
         }
 
-        if (atomic_expressions.IsEmpty()) {
+        if (!made_changes) {
             return SkipTransform;
         }
 
diff --git a/src/tint/transform/spirv_atomic_test.cc b/src/tint/transform/spirv_atomic_test.cc
index d9371bf..36312f7 100644
--- a/src/tint/transform/spirv_atomic_test.cc
+++ b/src/tint/transform/spirv_atomic_test.cc
@@ -151,6 +151,19 @@
     std::vector<std::unique_ptr<Source::File>> files_;
 };
 
+TEST_F(SpirvAtomicTest, StripUnusedBuiltins) {
+    auto* src = R"(
+fn f() {
+}
+)";
+
+    auto* expect = src;
+
+    auto got = Run(src);
+
+    EXPECT_EQ(expect, str(got));
+}
+
 TEST_F(SpirvAtomicTest, ArrayOfU32) {
     auto* src = R"(
 var<workgroup> wg : array<u32, 4>;