[clang] [HLSL] Diagnose dynamic indexing of struct arrays for resource access (PR #187132)
Helena Kotas via cfe-commits
cfe-commits at lists.llvm.org
Tue Apr 7 17:13:32 PDT 2026
================
@@ -0,0 +1,22 @@
+// RUN: %clang_cc1 -triple dxil-pc-shadermodel6.0-compute -finclude-default-header -verify %s
+
+struct A {
+ RWBuffer<float> Buf;
+ RWBuffer<float> ManyBufs[5];
+};
+
+A array[10] : register(u10);
+
+[numthreads(4,1,1)]
+void main(uint GI : SV_GroupThreadID) {
+
+ // expected-error at +1 {{index for struct array inside cbuffer that contains resources must be a literal expression}}
+ array[GI].Buf[0] = 1.0f;
+
+ array[2].Buf[GI] = 2.0f; // ok
+
+ // expected-error at +1 {{index for struct array inside cbuffer that contains resources must be a literal expression}}
+ array[GI].ManyBufs[3][0] = 3.0f;
+
+ array[1].ManyBufs[GI][0] = 4.0f; // ok
----------------
hekota wrote:
Ok, I see what you mean. The value of the local variable in this case is known at compile time, but that does not have to be the case everytime. If we add `if (GI > 2) x = 1;` then the value of 'x' it can no longer be determined, which makes it the same as the `GI` case. Since we are changing the behavior from DXC, I will add the test case for completeness.
https://github.com/llvm/llvm-project/pull/187132
More information about the cfe-commits
mailing list