[test]: Add some test cases for for-loops
Bug: tint:952
Change-Id: I156e29a74ce3942a39f25dc5bfb3d5467e206fce
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/57201
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: James Price <jrprice@google.com>
diff --git a/test/statements/for/basic.wgsl b/test/statements/for/basic.wgsl
new file mode 100644
index 0000000..6e99291
--- /dev/null
+++ b/test/statements/for/basic.wgsl
@@ -0,0 +1,7 @@
+fn some_loop_body() {}
+
+fn f() {
+ for (var i : i32 = 0; i < 5; i = i + 1) {
+ some_loop_body();
+ }
+}
diff --git a/test/statements/for/basic.wgsl.expected.hlsl b/test/statements/for/basic.wgsl.expected.hlsl
new file mode 100644
index 0000000..c1e6281
--- /dev/null
+++ b/test/statements/for/basic.wgsl.expected.hlsl
@@ -0,0 +1,16 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+ return;
+}
+
+void some_loop_body() {
+}
+
+void f() {
+ {
+ int i = 0;
+ for(; !(!((i < 5))); i = (i + 1)) {
+ some_loop_body();
+ }
+ }
+}
diff --git a/test/statements/for/basic.wgsl.expected.msl b/test/statements/for/basic.wgsl.expected.msl
new file mode 100644
index 0000000..d2e498f
--- /dev/null
+++ b/test/statements/for/basic.wgsl.expected.msl
@@ -0,0 +1,21 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void some_loop_body() {
+}
+
+void f() {
+ {
+ int i = 0;
+ while (true) {
+ if (!((i < 5))) {
+ break;
+ }
+ some_loop_body();
+ {
+ i = (i + 1);
+ }
+ }
+ }
+}
+
diff --git a/test/statements/for/basic.wgsl.expected.spvasm b/test/statements/for/basic.wgsl.expected.spvasm
new file mode 100644
index 0000000..b537e54
--- /dev/null
+++ b/test/statements/for/basic.wgsl.expected.spvasm
@@ -0,0 +1,57 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 29
+; Schema: 0
+ OpCapability Shader
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+ OpExecutionMode %unused_entry_point LocalSize 1 1 1
+ OpName %unused_entry_point "unused_entry_point"
+ OpName %some_loop_body "some_loop_body"
+ OpName %f "f"
+ OpName %i "i"
+ %void = OpTypeVoid
+ %1 = OpTypeFunction %void
+ %int = OpTypeInt 32 1
+ %int_0 = OpConstant %int 0
+%_ptr_Function_int = OpTypePointer Function %int
+ %13 = OpConstantNull %int
+ %int_5 = OpConstant %int 5
+ %bool = OpTypeBool
+ %int_1 = OpConstant %int 1
+%unused_entry_point = OpFunction %void None %1
+ %4 = OpLabel
+ OpReturn
+ OpFunctionEnd
+%some_loop_body = OpFunction %void None %1
+ %6 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %f = OpFunction %void None %1
+ %8 = OpLabel
+ %i = OpVariable %_ptr_Function_int Function %13
+ OpStore %i %int_0
+ OpBranch %14
+ %14 = OpLabel
+ OpLoopMerge %15 %16 None
+ OpBranch %17
+ %17 = OpLabel
+ %19 = OpLoad %int %i
+ %21 = OpSLessThan %bool %19 %int_5
+ %18 = OpLogicalNot %bool %21
+ OpSelectionMerge %23 None
+ OpBranchConditional %18 %24 %23
+ %24 = OpLabel
+ OpBranch %15
+ %23 = OpLabel
+ %25 = OpFunctionCall %void %some_loop_body
+ OpBranch %16
+ %16 = OpLabel
+ %26 = OpLoad %int %i
+ %28 = OpIAdd %int %26 %int_1
+ OpStore %i %28
+ OpBranch %14
+ %15 = OpLabel
+ OpReturn
+ OpFunctionEnd
diff --git a/test/statements/for/basic.wgsl.expected.wgsl b/test/statements/for/basic.wgsl.expected.wgsl
new file mode 100644
index 0000000..6a66161
--- /dev/null
+++ b/test/statements/for/basic.wgsl.expected.wgsl
@@ -0,0 +1,18 @@
+fn some_loop_body() {
+}
+
+fn f() {
+ {
+ var i : i32 = 0;
+ loop {
+ if (!((i < 5))) {
+ break;
+ }
+ some_loop_body();
+
+ continuing {
+ i = (i + 1);
+ }
+ }
+ }
+}
diff --git a/test/statements/for/complex.wgsl b/test/statements/for/complex.wgsl
new file mode 100644
index 0000000..60c8a46
--- /dev/null
+++ b/test/statements/for/complex.wgsl
@@ -0,0 +1,9 @@
+fn some_loop_body() {}
+
+fn f() {
+ var j : i32;
+ for (var i : i32 = 0; i < 5 && j < 10; i = i + 1) {
+ some_loop_body();
+ j = i * 30;
+ }
+}
diff --git a/test/statements/for/complex.wgsl.expected.hlsl b/test/statements/for/complex.wgsl.expected.hlsl
new file mode 100644
index 0000000..a3197c1
--- /dev/null
+++ b/test/statements/for/complex.wgsl.expected.hlsl
@@ -0,0 +1,24 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+ return;
+}
+
+void some_loop_body() {
+}
+
+void f() {
+ int j = 0;
+ {
+ int i = 0;
+ while (true) {
+ bool tint_tmp = (i < 5);
+ if (tint_tmp) {
+ tint_tmp = (j < 10);
+ }
+ if (!(!(!((tint_tmp))))) { break; }
+ some_loop_body();
+ j = (i * 30);
+ i = (i + 1);
+ }
+ }
+}
diff --git a/test/statements/for/complex.wgsl.expected.msl b/test/statements/for/complex.wgsl.expected.msl
new file mode 100644
index 0000000..2030618
--- /dev/null
+++ b/test/statements/for/complex.wgsl.expected.msl
@@ -0,0 +1,23 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void some_loop_body() {
+}
+
+void f() {
+ int j = 0;
+ {
+ int i = 0;
+ while (true) {
+ if (!(((i < 5) && (j < 10)))) {
+ break;
+ }
+ some_loop_body();
+ j = (i * 30);
+ {
+ i = (i + 1);
+ }
+ }
+ }
+}
+
diff --git a/test/statements/for/complex.wgsl.expected.spvasm b/test/statements/for/complex.wgsl.expected.spvasm
new file mode 100644
index 0000000..725edbf
--- /dev/null
+++ b/test/statements/for/complex.wgsl.expected.spvasm
@@ -0,0 +1,72 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 39
+; Schema: 0
+ OpCapability Shader
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+ OpExecutionMode %unused_entry_point LocalSize 1 1 1
+ OpName %unused_entry_point "unused_entry_point"
+ OpName %some_loop_body "some_loop_body"
+ OpName %f "f"
+ OpName %j "j"
+ OpName %i "i"
+ %void = OpTypeVoid
+ %1 = OpTypeFunction %void
+ %int = OpTypeInt 32 1
+%_ptr_Function_int = OpTypePointer Function %int
+ %12 = OpConstantNull %int
+ %int_0 = OpConstant %int 0
+ %int_5 = OpConstant %int 5
+ %bool = OpTypeBool
+ %int_10 = OpConstant %int 10
+ %int_30 = OpConstant %int 30
+ %int_1 = OpConstant %int 1
+%unused_entry_point = OpFunction %void None %1
+ %4 = OpLabel
+ OpReturn
+ OpFunctionEnd
+%some_loop_body = OpFunction %void None %1
+ %6 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %f = OpFunction %void None %1
+ %8 = OpLabel
+ %j = OpVariable %_ptr_Function_int Function %12
+ %i = OpVariable %_ptr_Function_int Function %12
+ OpStore %i %int_0
+ OpBranch %15
+ %15 = OpLabel
+ OpLoopMerge %16 %17 None
+ OpBranch %18
+ %18 = OpLabel
+ %20 = OpLoad %int %i
+ %22 = OpSLessThan %bool %20 %int_5
+ OpSelectionMerge %24 None
+ OpBranchConditional %22 %25 %24
+ %25 = OpLabel
+ %26 = OpLoad %int %j
+ %28 = OpSLessThan %bool %26 %int_10
+ OpBranch %24
+ %24 = OpLabel
+ %29 = OpPhi %bool %22 %18 %28 %25
+ %19 = OpLogicalNot %bool %29
+ OpSelectionMerge %30 None
+ OpBranchConditional %19 %31 %30
+ %31 = OpLabel
+ OpBranch %16
+ %30 = OpLabel
+ %32 = OpFunctionCall %void %some_loop_body
+ %33 = OpLoad %int %i
+ %35 = OpIMul %int %33 %int_30
+ OpStore %j %35
+ OpBranch %17
+ %17 = OpLabel
+ %36 = OpLoad %int %i
+ %38 = OpIAdd %int %36 %int_1
+ OpStore %i %38
+ OpBranch %15
+ %16 = OpLabel
+ OpReturn
+ OpFunctionEnd
diff --git a/test/statements/for/complex.wgsl.expected.wgsl b/test/statements/for/complex.wgsl.expected.wgsl
new file mode 100644
index 0000000..1f3ce92
--- /dev/null
+++ b/test/statements/for/complex.wgsl.expected.wgsl
@@ -0,0 +1,20 @@
+fn some_loop_body() {
+}
+
+fn f() {
+ var j : i32;
+ {
+ var i : i32 = 0;
+ loop {
+ if (!(((i < 5) && (j < 10)))) {
+ break;
+ }
+ some_loop_body();
+ j = (i * 30);
+
+ continuing {
+ i = (i + 1);
+ }
+ }
+ }
+}
diff --git a/test/statements/for/condition.wgsl b/test/statements/for/condition.wgsl
new file mode 100644
index 0000000..7b577dc
--- /dev/null
+++ b/test/statements/for/condition.wgsl
@@ -0,0 +1,5 @@
+fn f() {
+ var i : i32;
+ for (;i < 4;) {
+ }
+}
diff --git a/test/statements/for/condition.wgsl.expected.hlsl b/test/statements/for/condition.wgsl.expected.hlsl
new file mode 100644
index 0000000..5f51493
--- /dev/null
+++ b/test/statements/for/condition.wgsl.expected.hlsl
@@ -0,0 +1,10 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+ return;
+}
+
+void f() {
+ int i = 0;
+ for(; !(!((i < 4))); ) {
+ }
+}
diff --git a/test/statements/for/condition.wgsl.expected.msl b/test/statements/for/condition.wgsl.expected.msl
new file mode 100644
index 0000000..c99148a
--- /dev/null
+++ b/test/statements/for/condition.wgsl.expected.msl
@@ -0,0 +1,12 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void f() {
+ int i = 0;
+ while (true) {
+ if (!((i < 4))) {
+ break;
+ }
+ }
+}
+
diff --git a/test/statements/for/condition.wgsl.expected.spvasm b/test/statements/for/condition.wgsl.expected.spvasm
new file mode 100644
index 0000000..392440a
--- /dev/null
+++ b/test/statements/for/condition.wgsl.expected.spvasm
@@ -0,0 +1,45 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 22
+; Schema: 0
+ OpCapability Shader
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+ OpExecutionMode %unused_entry_point LocalSize 1 1 1
+ OpName %unused_entry_point "unused_entry_point"
+ OpName %f "f"
+ OpName %i "i"
+ %void = OpTypeVoid
+ %1 = OpTypeFunction %void
+ %int = OpTypeInt 32 1
+%_ptr_Function_int = OpTypePointer Function %int
+ %10 = OpConstantNull %int
+ %int_4 = OpConstant %int 4
+ %bool = OpTypeBool
+%unused_entry_point = OpFunction %void None %1
+ %4 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %f = OpFunction %void None %1
+ %6 = OpLabel
+ %i = OpVariable %_ptr_Function_int Function %10
+ OpBranch %11
+ %11 = OpLabel
+ OpLoopMerge %12 %13 None
+ OpBranch %14
+ %14 = OpLabel
+ %16 = OpLoad %int %i
+ %18 = OpSLessThan %bool %16 %int_4
+ %15 = OpLogicalNot %bool %18
+ OpSelectionMerge %20 None
+ OpBranchConditional %15 %21 %20
+ %21 = OpLabel
+ OpBranch %12
+ %20 = OpLabel
+ OpBranch %13
+ %13 = OpLabel
+ OpBranch %11
+ %12 = OpLabel
+ OpReturn
+ OpFunctionEnd
diff --git a/test/statements/for/condition.wgsl.expected.wgsl b/test/statements/for/condition.wgsl.expected.wgsl
new file mode 100644
index 0000000..14f48d5
--- /dev/null
+++ b/test/statements/for/condition.wgsl.expected.wgsl
@@ -0,0 +1,8 @@
+fn f() {
+ var i : i32;
+ loop {
+ if (!((i < 4))) {
+ break;
+ }
+ }
+}
diff --git a/test/statements/for/continuing.wgsl b/test/statements/for/continuing.wgsl
new file mode 100644
index 0000000..e174e9a
--- /dev/null
+++ b/test/statements/for/continuing.wgsl
@@ -0,0 +1,4 @@
+fn f() {
+ var i : i32;
+ for (;;i = i + 1) {}
+}
diff --git a/test/statements/for/continuing.wgsl.expected.hlsl b/test/statements/for/continuing.wgsl.expected.hlsl
new file mode 100644
index 0000000..28b8b3b
--- /dev/null
+++ b/test/statements/for/continuing.wgsl.expected.hlsl
@@ -0,0 +1,13 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+ return;
+}
+
+void f() {
+ int i = 0;
+ while (true) {
+ {
+ i = (i + 1);
+ }
+ }
+}
diff --git a/test/statements/for/continuing.wgsl.expected.msl b/test/statements/for/continuing.wgsl.expected.msl
new file mode 100644
index 0000000..67a069f
--- /dev/null
+++ b/test/statements/for/continuing.wgsl.expected.msl
@@ -0,0 +1,12 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void f() {
+ int i = 0;
+ while (true) {
+ {
+ i = (i + 1);
+ }
+ }
+}
+
diff --git a/test/statements/for/continuing.wgsl.expected.spvasm b/test/statements/for/continuing.wgsl.expected.spvasm
new file mode 100644
index 0000000..572838e
--- /dev/null
+++ b/test/statements/for/continuing.wgsl.expected.spvasm
@@ -0,0 +1,39 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 18
+; Schema: 0
+ OpCapability Shader
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+ OpExecutionMode %unused_entry_point LocalSize 1 1 1
+ OpName %unused_entry_point "unused_entry_point"
+ OpName %f "f"
+ OpName %i "i"
+ %void = OpTypeVoid
+ %1 = OpTypeFunction %void
+ %int = OpTypeInt 32 1
+%_ptr_Function_int = OpTypePointer Function %int
+ %10 = OpConstantNull %int
+ %int_1 = OpConstant %int 1
+%unused_entry_point = OpFunction %void None %1
+ %4 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %f = OpFunction %void None %1
+ %6 = OpLabel
+ %i = OpVariable %_ptr_Function_int Function %10
+ OpBranch %11
+ %11 = OpLabel
+ OpLoopMerge %12 %13 None
+ OpBranch %14
+ %14 = OpLabel
+ OpBranch %13
+ %13 = OpLabel
+ %15 = OpLoad %int %i
+ %17 = OpIAdd %int %15 %int_1
+ OpStore %i %17
+ OpBranch %11
+ %12 = OpLabel
+ OpReturn
+ OpFunctionEnd
diff --git a/test/statements/for/continuing.wgsl.expected.wgsl b/test/statements/for/continuing.wgsl.expected.wgsl
new file mode 100644
index 0000000..f3faf03
--- /dev/null
+++ b/test/statements/for/continuing.wgsl.expected.wgsl
@@ -0,0 +1,9 @@
+fn f() {
+ var i : i32;
+ loop {
+
+ continuing {
+ i = (i + 1);
+ }
+ }
+}
diff --git a/test/statements/for/empty.wgsl b/test/statements/for/empty.wgsl
new file mode 100644
index 0000000..5e08648
--- /dev/null
+++ b/test/statements/for/empty.wgsl
@@ -0,0 +1,3 @@
+fn f() {
+ for (;;) {}
+}
diff --git a/test/statements/for/empty.wgsl.expected.hlsl b/test/statements/for/empty.wgsl.expected.hlsl
new file mode 100644
index 0000000..b642595
--- /dev/null
+++ b/test/statements/for/empty.wgsl.expected.hlsl
@@ -0,0 +1,9 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+ return;
+}
+
+void f() {
+ while (true) {
+ }
+}
diff --git a/test/statements/for/empty.wgsl.expected.msl b/test/statements/for/empty.wgsl.expected.msl
new file mode 100644
index 0000000..622427b
--- /dev/null
+++ b/test/statements/for/empty.wgsl.expected.msl
@@ -0,0 +1,8 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void f() {
+ while (true) {
+ }
+}
+
diff --git a/test/statements/for/empty.wgsl.expected.spvasm b/test/statements/for/empty.wgsl.expected.spvasm
new file mode 100644
index 0000000..4cbeee3
--- /dev/null
+++ b/test/statements/for/empty.wgsl.expected.spvasm
@@ -0,0 +1,30 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 11
+; Schema: 0
+ OpCapability Shader
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+ OpExecutionMode %unused_entry_point LocalSize 1 1 1
+ OpName %unused_entry_point "unused_entry_point"
+ OpName %f "f"
+ %void = OpTypeVoid
+ %1 = OpTypeFunction %void
+%unused_entry_point = OpFunction %void None %1
+ %4 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %f = OpFunction %void None %1
+ %6 = OpLabel
+ OpBranch %7
+ %7 = OpLabel
+ OpLoopMerge %8 %9 None
+ OpBranch %10
+ %10 = OpLabel
+ OpBranch %9
+ %9 = OpLabel
+ OpBranch %7
+ %8 = OpLabel
+ OpReturn
+ OpFunctionEnd
diff --git a/test/statements/for/empty.wgsl.expected.wgsl b/test/statements/for/empty.wgsl.expected.wgsl
new file mode 100644
index 0000000..3674ab1
--- /dev/null
+++ b/test/statements/for/empty.wgsl.expected.wgsl
@@ -0,0 +1,4 @@
+fn f() {
+ loop {
+ }
+}
diff --git a/test/statements/for/initializer.wgsl b/test/statements/for/initializer.wgsl
new file mode 100644
index 0000000..5f6ef9c
--- /dev/null
+++ b/test/statements/for/initializer.wgsl
@@ -0,0 +1,3 @@
+fn f() {
+ for (var i : i32 = 0;;) {}
+}
diff --git a/test/statements/for/initializer.wgsl.expected.hlsl b/test/statements/for/initializer.wgsl.expected.hlsl
new file mode 100644
index 0000000..8311c7b
--- /dev/null
+++ b/test/statements/for/initializer.wgsl.expected.hlsl
@@ -0,0 +1,12 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+ return;
+}
+
+void f() {
+ {
+ int i = 0;
+ while (true) {
+ }
+ }
+}
diff --git a/test/statements/for/initializer.wgsl.expected.msl b/test/statements/for/initializer.wgsl.expected.msl
new file mode 100644
index 0000000..70c5111
--- /dev/null
+++ b/test/statements/for/initializer.wgsl.expected.msl
@@ -0,0 +1,11 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void f() {
+ {
+ int i = 0;
+ while (true) {
+ }
+ }
+}
+
diff --git a/test/statements/for/initializer.wgsl.expected.spvasm b/test/statements/for/initializer.wgsl.expected.spvasm
new file mode 100644
index 0000000..d0158fb
--- /dev/null
+++ b/test/statements/for/initializer.wgsl.expected.spvasm
@@ -0,0 +1,37 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 16
+; Schema: 0
+ OpCapability Shader
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+ OpExecutionMode %unused_entry_point LocalSize 1 1 1
+ OpName %unused_entry_point "unused_entry_point"
+ OpName %f "f"
+ OpName %i "i"
+ %void = OpTypeVoid
+ %1 = OpTypeFunction %void
+ %int = OpTypeInt 32 1
+ %int_0 = OpConstant %int 0
+%_ptr_Function_int = OpTypePointer Function %int
+ %11 = OpConstantNull %int
+%unused_entry_point = OpFunction %void None %1
+ %4 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %f = OpFunction %void None %1
+ %6 = OpLabel
+ %i = OpVariable %_ptr_Function_int Function %11
+ OpStore %i %int_0
+ OpBranch %12
+ %12 = OpLabel
+ OpLoopMerge %13 %14 None
+ OpBranch %15
+ %15 = OpLabel
+ OpBranch %14
+ %14 = OpLabel
+ OpBranch %12
+ %13 = OpLabel
+ OpReturn
+ OpFunctionEnd
diff --git a/test/statements/for/initializer.wgsl.expected.wgsl b/test/statements/for/initializer.wgsl.expected.wgsl
new file mode 100644
index 0000000..e021556
--- /dev/null
+++ b/test/statements/for/initializer.wgsl.expected.wgsl
@@ -0,0 +1,7 @@
+fn f() {
+ {
+ var i : i32 = 0;
+ loop {
+ }
+ }
+}
diff --git a/test/statements/for/scoping.wgsl b/test/statements/for/scoping.wgsl
new file mode 100644
index 0000000..0db6a69
--- /dev/null
+++ b/test/statements/for/scoping.wgsl
@@ -0,0 +1,4 @@
+fn f() {
+ for (var must_not_collide : i32 = 0;;) {}
+ var must_not_collide : i32;
+}
diff --git a/test/statements/for/scoping.wgsl.expected.hlsl b/test/statements/for/scoping.wgsl.expected.hlsl
new file mode 100644
index 0000000..459eb43
--- /dev/null
+++ b/test/statements/for/scoping.wgsl.expected.hlsl
@@ -0,0 +1,13 @@
+[numthreads(1, 1, 1)]
+void unused_entry_point() {
+ return;
+}
+
+void f() {
+ {
+ int must_not_collide = 0;
+ while (true) {
+ }
+ }
+ int must_not_collide = 0;
+}
diff --git a/test/statements/for/scoping.wgsl.expected.msl b/test/statements/for/scoping.wgsl.expected.msl
new file mode 100644
index 0000000..d5c3f3a
--- /dev/null
+++ b/test/statements/for/scoping.wgsl.expected.msl
@@ -0,0 +1,12 @@
+#include <metal_stdlib>
+
+using namespace metal;
+void f() {
+ {
+ int must_not_collide = 0;
+ while (true) {
+ }
+ }
+ int must_not_collide = 0;
+}
+
diff --git a/test/statements/for/scoping.wgsl.expected.spvasm b/test/statements/for/scoping.wgsl.expected.spvasm
new file mode 100644
index 0000000..2733b61
--- /dev/null
+++ b/test/statements/for/scoping.wgsl.expected.spvasm
@@ -0,0 +1,39 @@
+; SPIR-V
+; Version: 1.3
+; Generator: Google Tint Compiler; 0
+; Bound: 17
+; Schema: 0
+ OpCapability Shader
+ OpMemoryModel Logical GLSL450
+ OpEntryPoint GLCompute %unused_entry_point "unused_entry_point"
+ OpExecutionMode %unused_entry_point LocalSize 1 1 1
+ OpName %unused_entry_point "unused_entry_point"
+ OpName %f "f"
+ OpName %must_not_collide "must_not_collide"
+ OpName %must_not_collide_0 "must_not_collide"
+ %void = OpTypeVoid
+ %1 = OpTypeFunction %void
+ %int = OpTypeInt 32 1
+ %int_0 = OpConstant %int 0
+%_ptr_Function_int = OpTypePointer Function %int
+ %11 = OpConstantNull %int
+%unused_entry_point = OpFunction %void None %1
+ %4 = OpLabel
+ OpReturn
+ OpFunctionEnd
+ %f = OpFunction %void None %1
+ %6 = OpLabel
+%must_not_collide = OpVariable %_ptr_Function_int Function %11
+%must_not_collide_0 = OpVariable %_ptr_Function_int Function %11
+ OpStore %must_not_collide %int_0
+ OpBranch %12
+ %12 = OpLabel
+ OpLoopMerge %13 %14 None
+ OpBranch %15
+ %15 = OpLabel
+ OpBranch %14
+ %14 = OpLabel
+ OpBranch %12
+ %13 = OpLabel
+ OpReturn
+ OpFunctionEnd
diff --git a/test/statements/for/scoping.wgsl.expected.wgsl b/test/statements/for/scoping.wgsl.expected.wgsl
new file mode 100644
index 0000000..ec202ae
--- /dev/null
+++ b/test/statements/for/scoping.wgsl.expected.wgsl
@@ -0,0 +1,8 @@
+fn f() {
+ {
+ var must_not_collide : i32 = 0;
+ loop {
+ }
+ }
+ var must_not_collide : i32;
+}