summaryrefslogtreecommitdiffstats
path: root/tests/language-feature/0-array-1.slang
diff options
context:
space:
mode:
authorYong He <yonghe@outlook.com>2025-06-04 13:07:11 -0700
committerGitHub <noreply@github.com>2025-06-04 13:07:11 -0700
commit2d7106640addf0ac88e0a5462117cd90b13a5e73 (patch)
tree6ce27db4d6c5bf06db84dee755a82e09b1b3a2ca /tests/language-feature/0-array-1.slang
parent812e478989e27983b8dea7ab11964de751654ba2 (diff)
Add legalization for 0-sized arrays. (#7327)
* Add legalization for 0-sized arrays. * Allow 0-sized arrays in the front-end. * More tests. * Add `Conditional<T, hasValue>` type to core module. * Update toc. * Fix wording. * Update test.
Diffstat (limited to 'tests/language-feature/0-array-1.slang')
-rw-r--r--tests/language-feature/0-array-1.slang31
1 files changed, 31 insertions, 0 deletions
diff --git a/tests/language-feature/0-array-1.slang b/tests/language-feature/0-array-1.slang
new file mode 100644
index 000000000..327f71444
--- /dev/null
+++ b/tests/language-feature/0-array-1.slang
@@ -0,0 +1,31 @@
+//TEST:SIMPLE(filecheck=SPV): -target spirv
+//TEST:SIMPLE(filecheck=HLSL): -target hlsl -profile cs_6_0 -entry computeMain
+
+struct MyData
+{
+ int a[0][0][0];
+}
+
+uniform MyData* myData;
+uniform int * output;
+
+[numthreads(1, 1, 1)]
+void computeMain()
+{
+ // These are all ill-formed, but we want to still ensure our backend
+ // can handle them gracefully without crashing.
+ // In actual user code, any access to 0-sized arrays should be protected
+ // by a `if` statement that checks the size before accessing.
+ // The condition would then evaluate to false and causing all the accessing
+ // code to be optimized out.
+ InterlockedAdd(myData.a[0][0][0], 1);
+ myData.a[0][0][0] += 1;
+ output[0] = myData.a[0][0][0];
+}
+
+//SPV: OpEntryPoint
+//SPV-NOT: OpAtomic
+//SPV-NOT: OpStore
+//SPV-NOT: OpLoad
+
+//HLSL: computeMain