diff options
| author | Julius Ikkala <julius.ikkala@gmail.com> | 2025-05-11 08:14:44 +0300 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2025-05-10 22:14:44 -0700 |
| commit | 7cd502256dde2fc32a1dd77462a69b6f8e84c288 (patch) | |
| tree | 8fa96d87219443b46b1cfceabe58ba9031e4fa09 /tests | |
| parent | 083eecee3f56b90c7011895f53aaafa9db15856e (diff) | |
Fix local constants in switch cases (#7053)
* Fix using local constants in switch cases
* Add test
* format code
* Always lower switch cases with exprVal
* Fix formatting
---------
Co-authored-by: slangbot <186143334+slangbot@users.noreply.github.com>
Co-authored-by: Yong He <yonghe@outlook.com>
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/bugs/switch-local-const.slang | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/bugs/switch-local-const.slang b/tests/bugs/switch-local-const.slang new file mode 100644 index 000000000..30cd8a814 --- /dev/null +++ b/tests/bugs/switch-local-const.slang @@ -0,0 +1,34 @@ +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -vk +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -dx12 +//TEST(compute):COMPARE_COMPUTE(filecheck-buffer=CHECK): -cpu + +// CHECK: 0 +// CHECK-NEXT: 1 +// CHECK-NEXT: 2 + +//TEST_INPUT:ubuffer(data=[0 0 0], stride=4):out,name=outputBuffer +RWStructuredBuffer<int> outputBuffer; + +uint testFunc(uint n) +{ + const uint CONST_A = 0; + const uint CONST_B = 1; + + switch (n) + { + case CONST_A: + return 0; + case CONST_B: + return 1; + } + + return 2; +} + +[numthreads(1, 1, 1)] +void computeMain(int3 dispatchThreadID: SV_DispatchThreadID) +{ + outputBuffer[0] = testFunc(0); + outputBuffer[1] = testFunc(1); + outputBuffer[2] = testFunc(2); +} |
