yum-mirror/slang

Making it easier to work with shaders

git clone https://git.yummers.dev/yum-mirror/slang

CopilotAdd bounds checking for out-of-bounds array access with constant indices (#7814)85edfb178

master
817 B28 linesraw
1// array-out-of-bounds.slang
2
3// Test that out-of-bounds array access with constant indices generates an error
4
5//TEST:SIMPLE(filecheck=CHECK): -target spirv -entry computeMain -stage compute
6
7RWStructuredBuffer<int> outputBuffer;
8
9[numthreads(1, 1, 1)]
10void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
11{
12    int a[3];
13    a[0] = 10;
14    a[1] = 20;
15    a[2] = 30;
16    
17    // Valid access - should be fine
18    outputBuffer[0] = a[0];
19    outputBuffer[1] = a[2];
20    
21    // Invalid access - index 3 is out of bounds for array of size 3
22    //CHECK: error 30029: array index '3' is out of bounds for array of size '3'.
23    outputBuffer[2] = a[3];
24    
25    // Invalid access - negative index
26    //CHECK: error 30029: array index '-1' is out of bounds for array of size '3'.
27    outputBuffer[3] = a[-1];
28}