summaryrefslogtreecommitdiffstats
path: root/tests/diagnostics
diff options
context:
space:
mode:
Diffstat (limited to 'tests/diagnostics')
-rw-r--r--tests/diagnostics/array-out-of-bounds-2.slang29
-rw-r--r--tests/diagnostics/array-out-of-bounds.slang28
2 files changed, 57 insertions, 0 deletions
diff --git a/tests/diagnostics/array-out-of-bounds-2.slang b/tests/diagnostics/array-out-of-bounds-2.slang
new file mode 100644
index 000000000..978f61d9f
--- /dev/null
+++ b/tests/diagnostics/array-out-of-bounds-2.slang
@@ -0,0 +1,29 @@
+// array-out-of-bounds-2.slang
+
+// Test the specific scenario from the issue (array of size 3, accessing index 3)
+
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -entry computeMain -stage compute
+
+struct SH3_t
+{
+ float coeffs[4];
+};
+
+RWStructuredBuffer<float> outputBuffer;
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ SH3_t a[3];
+ SH3_t b;
+
+ for (int i = 0; i < 3; ++i)
+ {
+ // This should be fine
+ outputBuffer[i] = a[i].coeffs[0];
+ }
+
+ // This reproduces the issue - accessing index 3 in array of size 3
+ //CHECK: error 30029: array index '3' is out of bounds for array of size '3'.
+ outputBuffer[3] = a[3].coeffs[0];
+} \ No newline at end of file
diff --git a/tests/diagnostics/array-out-of-bounds.slang b/tests/diagnostics/array-out-of-bounds.slang
new file mode 100644
index 000000000..81c243031
--- /dev/null
+++ b/tests/diagnostics/array-out-of-bounds.slang
@@ -0,0 +1,28 @@
+// array-out-of-bounds.slang
+
+// Test that out-of-bounds array access with constant indices generates an error
+
+//TEST:SIMPLE(filecheck=CHECK): -target spirv -entry computeMain -stage compute
+
+RWStructuredBuffer<int> outputBuffer;
+
+[numthreads(1, 1, 1)]
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
+{
+ int a[3];
+ a[0] = 10;
+ a[1] = 20;
+ a[2] = 30;
+
+ // Valid access - should be fine
+ outputBuffer[0] = a[0];
+ outputBuffer[1] = a[2];
+
+ // Invalid access - index 3 is out of bounds for array of size 3
+ //CHECK: error 30029: array index '3' is out of bounds for array of size '3'.
+ outputBuffer[2] = a[3];
+
+ // Invalid access - negative index
+ //CHECK: error 30029: array index '-1' is out of bounds for array of size '3'.
+ outputBuffer[3] = a[-1];
+} \ No newline at end of file