| #include <metal_stdlib> |
| using namespace metal; |
| |
| struct S { |
| int a; |
| float4 b; |
| float2x2 c; |
| }; |
| |
| struct tint_module_vars_struct { |
| device S* v; |
| thread uint* i; |
| }; |
| |
| template<typename T, size_t N> |
| struct tint_array { |
| const constant T& operator[](size_t i) const constant { return elements[i]; } |
| device T& operator[](size_t i) device { return elements[i]; } |
| const device T& operator[](size_t i) const device { return elements[i]; } |
| thread T& operator[](size_t i) thread { return elements[i]; } |
| const thread T& operator[](size_t i) const thread { return elements[i]; } |
| threadgroup T& operator[](size_t i) threadgroup { return elements[i]; } |
| const threadgroup T& operator[](size_t i) const threadgroup { return elements[i]; } |
| T elements[N]; |
| }; |
| |
| #define TINT_ISOLATE_UB(VOLATILE_NAME) \ |
| volatile bool VOLATILE_NAME = true; \ |
| if (VOLATILE_NAME) |
| |
| int idx1(tint_module_vars_struct tint_module_vars) { |
| (*tint_module_vars.i) = ((*tint_module_vars.i) + 1u); |
| return 1; |
| } |
| |
| int idx2(tint_module_vars_struct tint_module_vars) { |
| (*tint_module_vars.i) = ((*tint_module_vars.i) + 2u); |
| return 1; |
| } |
| |
| int idx3(tint_module_vars_struct tint_module_vars) { |
| (*tint_module_vars.i) = ((*tint_module_vars.i) + 3u); |
| return 1; |
| } |
| |
| void foo(tint_module_vars_struct tint_module_vars) { |
| tint_array<float, 4> a = tint_array<float, 4>{}; |
| { |
| thread float* const v_1 = (&a[idx1(tint_module_vars)]); |
| (*v_1) = ((*v_1) * 2.0f); |
| TINT_ISOLATE_UB(tint_volatile_true) while(true) { |
| if ((a[idx2(tint_module_vars)] < 10.0f)) { |
| } else { |
| break; |
| } |
| { |
| thread float* const v_2 = (&a[idx3(tint_module_vars)]); |
| (*v_2) = ((*v_2) + 1.0f); |
| } |
| continue; |
| } |
| } |
| } |