summaryrefslogtreecommitdiffstats
path: root/tests/language-feature
diff options
context:
space:
mode:
authorCopilot <198982749+Copilot@users.noreply.github.com>2025-07-17 20:58:02 -0700
committerGitHub <noreply@github.com>2025-07-18 03:58:02 +0000
commit85edfb178cd243134f4bb3d35ad71f154d76c81c (patch)
tree68f5340c8796f6c2d5ff343cabf3d96c7d387ac5 /tests/language-feature
parent447d73f8c2245d061b0e84890fb994a77816a736 (diff)
Add bounds checking for out-of-bounds array access with constant indices (#7814)
* Initial plan * Implement out-of-bounds array access checking Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Add tests and format code for array bounds checking Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Move checkForOutOfBoundAccess to separate file and refactor using InstPassBase Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Optimize out-of-bounds checker to use single IR traversal Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Fix DiagnosticSink forward declaration from struct to class Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Update 0-array-1 test to use runtime indices to avoid bounds checking diagnostic Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> * Use SV_DispatchThreadID for truly runtime array access in 0-array-1 test Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com> --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: csyonghe <2652293+csyonghe@users.noreply.github.com>
Diffstat (limited to 'tests/language-feature')
-rw-r--r--tests/language-feature/0-array-1.slang12
1 files changed, 8 insertions, 4 deletions
diff --git a/tests/language-feature/0-array-1.slang b/tests/language-feature/0-array-1.slang
index 327f71444..b02be1af0 100644
--- a/tests/language-feature/0-array-1.slang
+++ b/tests/language-feature/0-array-1.slang
@@ -10,7 +10,7 @@ uniform MyData* myData;
uniform int * output;
[numthreads(1, 1, 1)]
-void computeMain()
+void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
{
// These are all ill-formed, but we want to still ensure our backend
// can handle them gracefully without crashing.
@@ -18,9 +18,13 @@ void computeMain()
// 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];
+
+ // Use runtime values to access the 0-sized array to avoid triggering
+ // the new out-of-bounds diagnostic for constant indices
+ uint runtimeIndex = dispatchThreadID.x;
+ InterlockedAdd(myData.a[runtimeIndex][runtimeIndex][runtimeIndex], 1);
+ myData.a[runtimeIndex][runtimeIndex][runtimeIndex] += 1;
+ output[0] = myData.a[runtimeIndex][runtimeIndex][runtimeIndex];
}
//SPV: OpEntryPoint