From 5f8475bee2589b8e851c856135cf10758e859e72 Mon Sep 17 00:00:00 2001 From: Sai Praveen Bangaru <31557731+saipraveenb25@users.noreply.github.com> Date: Mon, 28 Jul 2025 15:29:58 -0400 Subject: Fix issue in multi-level break elimination by handling multi-level continue statements (#7953) --- tests/bugs/gh-7748-switch-continue-bug.slang | 45 ++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 tests/bugs/gh-7748-switch-continue-bug.slang (limited to 'tests') diff --git a/tests/bugs/gh-7748-switch-continue-bug.slang b/tests/bugs/gh-7748-switch-continue-bug.slang new file mode 100644 index 000000000..4feca7180 --- /dev/null +++ b/tests/bugs/gh-7748-switch-continue-bug.slang @@ -0,0 +1,45 @@ +//TEST:COMPARE_COMPUTE(filecheck-buffer=CHECK):-output-using-type -cpu + +// Regression test for issue #7748: Dictionary key collision in multi-level break processing +// This test specifically exercises the case of "continue inside a switch that is inside a for loop" +// which was identified as the root cause of the dictionary collision issue. + +int testContinueInSwitchInLoop(int value) { + int result = 0; + + for (int i = 0; i < 3; ++i) { + switch (value) { + case 0: + result += 1; + continue; // This continue should go to the for loop + case 1: + result += 2; + break; // This break goes to the switch + default: + result += 3; + break; + } + result += 10; // This should be skipped when continue is used + } + + return result; +} + +int processValues() { + int sum = 0; + sum += testContinueInSwitchInLoop(0); // Should be 3 (1+1+1, no +10s due to continue) + sum += testContinueInSwitchInLoop(1); // Should be 36 (2+10, 2+10, 2+10) + sum += testContinueInSwitchInLoop(2); // Should be 39 (3+10, 3+10, 3+10) + return sum; +} + +//TEST_INPUT:ubuffer(data=[0], stride=4):out,name=outputBuffer +RWStructuredBuffer outputBuffer; + +[shader("compute")] +[numthreads(1, 1, 1)] +void computeMain() { + int result = processValues(); + outputBuffer[0] = result; + //CHECK: 78 +} \ No newline at end of file -- cgit v1.2.3