[tint][wgsl] Fix ICE in SingleEntryPoint transform

This wasn't handling ConstAsserts.
I don't think this affects production, as earlier transforms appear to be stripping these.

Bug: chromium:1501769
Change-Id: I8ce1b0dcc1462bcb72cf499bd6377791e148eaf9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/160561
Auto-Submit: Ben Clayton <bclayton@google.com>
Reviewed-by: James Price <jrprice@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/lang/wgsl/ast/transform/single_entry_point.cc b/src/tint/lang/wgsl/ast/transform/single_entry_point.cc
index 3311ce4..53b00d0 100644
--- a/src/tint/lang/wgsl/ast/transform/single_entry_point.cc
+++ b/src/tint/lang/wgsl/ast/transform/single_entry_point.cc
@@ -132,6 +132,7 @@
                 // Drop requires directives as they are optional, and it's non-trivial to determine
                 // which features are needed for which entry points.
             },
+            [&](const ConstAssert* ca) { b.AST().AddConstAssert(ctx.Clone(ca)); },
             [&](const DiagnosticDirective* d) { b.AST().AddDiagnosticDirective(ctx.Clone(d)); },  //
             TINT_ICE_ON_NO_MATCH);
     }
diff --git a/src/tint/lang/wgsl/ast/transform/single_entry_point_test.cc b/src/tint/lang/wgsl/ast/transform/single_entry_point_test.cc
index f22ddb5..4d4ede3 100644
--- a/src/tint/lang/wgsl/ast/transform/single_entry_point_test.cc
+++ b/src/tint/lang/wgsl/ast/transform/single_entry_point_test.cc
@@ -669,5 +669,50 @@
     EXPECT_EQ(expect, str(got));
 }
 
+TEST_F(SingleEntryPointTest, ConstAssert_ModuleScope) {
+    // module scope const_assert is preserved
+    auto* src = R"(
+const C = 42;
+
+const_assert (C == 42);
+
+@compute @workgroup_size(1)
+fn main() {
+}
+)";
+
+    auto* expect = src;
+
+    SingleEntryPoint::Config cfg("main");
+
+    DataMap data;
+    data.Add<SingleEntryPoint::Config>(cfg);
+    auto got = Run<SingleEntryPoint>(src, data);
+
+    EXPECT_EQ(expect, str(got));
+}
+
+TEST_F(SingleEntryPointTest, ConstAssert_FnScope) {
+    // function scope const_assert is preserved
+    auto* src = R"(
+const C = 42;
+
+@compute @workgroup_size(1)
+fn main() {
+  const_assert (C == 42);
+}
+)";
+
+    auto* expect = src;
+
+    SingleEntryPoint::Config cfg("main");
+
+    DataMap data;
+    data.Add<SingleEntryPoint::Config>(cfg);
+    auto got = Run<SingleEntryPoint>(src, data);
+
+    EXPECT_EQ(expect, str(got));
+}
+
 }  // namespace
 }  // namespace tint::ast::transform
diff --git a/test/tint/bug/chromium/1501769.wgsl b/test/tint/bug/chromium/1501769.wgsl
new file mode 100644
index 0000000..9705958
--- /dev/null
+++ b/test/tint/bug/chromium/1501769.wgsl
@@ -0,0 +1,5 @@
+@compute
+@workgroup_size(1)
+fn a() {}
+
+const_assert(true);
diff --git a/test/tint/bug/chromium/1501769.wgsl.expected.dxc.hlsl b/test/tint/bug/chromium/1501769.wgsl.expected.dxc.hlsl
new file mode 100644
index 0000000..657e9d1
--- /dev/null
+++ b/test/tint/bug/chromium/1501769.wgsl.expected.dxc.hlsl
@@ -0,0 +1,4 @@
+[numthreads(1, 1, 1)]
+void a() {
+  return;
+}
diff --git a/test/tint/bug/chromium/1501769.wgsl.expected.fxc.hlsl b/test/tint/bug/chromium/1501769.wgsl.expected.fxc.hlsl
new file mode 100644
index 0000000..657e9d1
--- /dev/null
+++ b/test/tint/bug/chromium/1501769.wgsl.expected.fxc.hlsl
@@ -0,0 +1,4 @@
+[numthreads(1, 1, 1)]
+void a() {
+  return;
+}
diff --git a/test/tint/bug/chromium/1501769.wgsl.expected.glsl b/test/tint/bug/chromium/1501769.wgsl.expected.glsl
new file mode 100644
index 0000000..f66fff3
--- /dev/null
+++ b/test/tint/bug/chromium/1501769.wgsl.expected.glsl
@@ -0,0 +1,10 @@
+#version 310 es
+
+void a() {
+}
+
+layout(local_size_x = 1, local_size_y = 1, local_size_z = 1) in;
+void main() {
+  a();
+  return;
+}
diff --git a/test/tint/bug/chromium/1501769.wgsl.expected.msl b/test/tint/bug/chromium/1501769.wgsl.expected.msl
new file mode 100644
index 0000000..dff2fde
--- /dev/null
+++ b/test/tint/bug/chromium/1501769.wgsl.expected.msl
@@ -0,0 +1,7 @@
+#include <metal_stdlib>
+
+using namespace metal;
+kernel void a() {
+  return;
+}
+
diff --git a/test/tint/bug/chromium/1501769.wgsl.expected.spvasm b/test/tint/bug/chromium/1501769.wgsl.expected.spvasm
new file mode 100644
index 0000000..1e24902
--- /dev/null
+++ b/test/tint/bug/chromium/1501769.wgsl.expected.spvasm
@@ -0,0 +1,16 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 5
+; Schema: 0
+               OpCapability Shader
+               OpMemoryModel Logical GLSL450
+               OpEntryPoint GLCompute %a "a"
+               OpExecutionMode %a LocalSize 1 1 1
+               OpName %a "a"
+       %void = OpTypeVoid
+          %1 = OpTypeFunction %void
+          %a = OpFunction %void None %1
+          %4 = OpLabel
+               OpReturn
+               OpFunctionEnd
diff --git a/test/tint/bug/chromium/1501769.wgsl.expected.wgsl b/test/tint/bug/chromium/1501769.wgsl.expected.wgsl
new file mode 100644
index 0000000..d0b21e3
--- /dev/null
+++ b/test/tint/bug/chromium/1501769.wgsl.expected.wgsl
@@ -0,0 +1,5 @@
+@compute @workgroup_size(1)
+fn a() {
+}
+
+const_assert true;