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
713 B29 linesraw
1// array-out-of-bounds-2.slang
2
3// Test the specific scenario from the issue (array of size 3, accessing index 3)
4
5//TEST:SIMPLE(filecheck=CHECK): -target spirv -entry computeMain -stage compute
6
7struct SH3_t
8{
9    float coeffs[4];
10};
11
12RWStructuredBuffer<float> outputBuffer;
13
14[numthreads(1, 1, 1)]
15void computeMain(uint3 dispatchThreadID : SV_DispatchThreadID)
16{
17    SH3_t a[3];
18    SH3_t b;
19    
20    for (int i = 0; i < 3; ++i)
21    {
22        // This should be fine
23        outputBuffer[i] = a[i].coeffs[0];
24    }
25    
26    // This reproduces the issue - accessing index 3 in array of size 3
27    //CHECK: error 30029: array index '3' is out of bounds for array of size '3'.
28    outputBuffer[3] = a[3].coeffs[0];
29}