test: Add a test case for tint:1321

It's surprising that the fuzzers didn't find this, but I've confirmed that at least one of the fuzzers will fail with this case.
By adding a e2e test case, this will be used as a seed for the fuzzer corpus.

Bug: tint:1321
Change-Id: Ibf4bfa50bf376ae4cba401dfc31a2498fa3b9eec
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/70982
Reviewed-by: James Price <jrprice@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
Ben Clayton 2021-11-25 18:02:36 +00:00 committed by Tint LUCI CQ
parent 401d694d03
commit 0079a597e6
5 changed files with 107 additions and 0 deletions

12
test/bug/tint/1321.wgsl Normal file
View File

@ -0,0 +1,12 @@
fn foo() -> i32 {
return 1;
}
[[stage(fragment)]]
fn main() {
var arr = array<f32, 4>();
for (let a = &arr[foo()]; ;) {
let x = *a;
break;
}
}

View File

@ -0,0 +1,15 @@
int foo() {
return 1;
}
void main() {
float arr[4] = (float[4])0;
const int a_save = foo();
{
for(; ; ) {
const float x = arr[a_save];
break;
}
}
return;
}

View File

@ -0,0 +1,21 @@
#include <metal_stdlib>
using namespace metal;
struct tint_array_wrapper {
float arr[4];
};
int foo() {
return 1;
}
fragment void tint_symbol() {
tint_array_wrapper arr = {.arr={}};
int const a_save = foo();
for(; ; ) {
float const x = arr.arr[a_save];
break;
}
return;
}

View File

@ -0,0 +1,47 @@
; SPIR-V
; Version: 1.3
; Generator: Google Tint Compiler; 0
; Bound: 25
; Schema: 0
OpCapability Shader
OpMemoryModel Logical GLSL450
OpEntryPoint Fragment %main "main"
OpExecutionMode %main OriginUpperLeft
OpName %foo "foo"
OpName %main "main"
OpName %arr "arr"
OpDecorate %_arr_float_uint_4 ArrayStride 4
%int = OpTypeInt 32 1
%1 = OpTypeFunction %int
%int_1 = OpConstant %int 1
%void = OpTypeVoid
%6 = OpTypeFunction %void
%float = OpTypeFloat 32
%uint = OpTypeInt 32 0
%uint_4 = OpConstant %uint 4
%_arr_float_uint_4 = OpTypeArray %float %uint_4
%14 = OpConstantNull %_arr_float_uint_4
%_ptr_Function__arr_float_uint_4 = OpTypePointer Function %_arr_float_uint_4
%_ptr_Function_float = OpTypePointer Function %float
%foo = OpFunction %int None %1
%4 = OpLabel
OpReturnValue %int_1
OpFunctionEnd
%main = OpFunction %void None %6
%9 = OpLabel
%arr = OpVariable %_ptr_Function__arr_float_uint_4 Function %14
OpStore %arr %14
%17 = OpFunctionCall %int %foo
OpBranch %18
%18 = OpLabel
OpLoopMerge %19 %20 None
OpBranch %21
%21 = OpLabel
%23 = OpAccessChain %_ptr_Function_float %arr %17
%24 = OpLoad %float %23
OpBranch %19
%20 = OpLabel
OpBranch %18
%19 = OpLabel
OpReturn
OpFunctionEnd

View File

@ -0,0 +1,12 @@
fn foo() -> i32 {
return 1;
}
[[stage(fragment)]]
fn main() {
var arr = array<f32, 4>();
for(let a = &(arr[foo()]); ; ) {
let x = *(a);
break;
}
}