diff options
| author | Ellie Hermaszewska <ellieh@nvidia.com> | 2025-07-29 20:38:08 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-07-29 12:38:08 +0000 |
| commit | ea6f8551ad38f2bcc32b542fd52ce17f3829cbeb (patch) | |
| tree | 42a01a628d7d0c42255239c8e8eae8dbf681a616 /tests | |
| parent | 1da9019e9d3150502264365668156edf64ddfab1 (diff) | |
Detect uses of uninitialized resource fields (#7962)
Closes https://github.com/shader-slang/slang/issues/3386
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/diagnostics/uninitialized-resource-field.slang | 26 |
1 files changed, 26 insertions, 0 deletions
diff --git a/tests/diagnostics/uninitialized-resource-field.slang b/tests/diagnostics/uninitialized-resource-field.slang new file mode 100644 index 000000000..b2e87effb --- /dev/null +++ b/tests/diagnostics/uninitialized-resource-field.slang @@ -0,0 +1,26 @@ +//DIAGNOSTIC_TEST:SIMPLE(filecheck=CHECK): -stage compute -entry computeMain -target hlsl + +RWStructuredBuffer<int> outputBuffer; + +void useStruct(SomeStruct s) +{ + outputBuffer[0] = s.value; +} + +[shader("compute")] +[numthreads(1,1,1)] +void computeMain(uint3 threadId : SV_DispatchThreadID) +{ + // CHECK: ([[# @LINE+1]]): error {{.*}} cannot default-initialize struct 'SomeStruct' with '{}' because it contains an uninitialized texture field + SomeStruct s = {}; + + s.value = 10 + threadId.x; + useStruct(s); +} + +// CHECK: ([[# @LINE+1]]): note: see definition of struct 'SomeStruct' +struct SomeStruct +{ + int value; + Texture1D<float> tex; +} |
