From ff064b9a0f1316007f46710432f854777a520fdf Mon Sep 17 00:00:00 2001 From: davli-nv Date: Thu, 16 Oct 2025 18:22:39 -0700 Subject: Fix infinite loop in SPIRVLegalizationContext::processWorkList (#8712) When slangc is invoked with -g, a source shader that has static infinite loop can generate IR that have branch to a block that contains a branch to the first block that contains the first branch, resulting in infinite loop. Change SPIRVLegalizationContext::processWorkList to only add branch target to work list via its parent, this avoids the infinite loop above. Also change addToWorkList to stop addUsersToWorkList, users should be added explicitly by logic for specific insts. Add regression test as tests/spirv/infinite-loop.slang Fixes #8669 --- tests/spirv/infinite-loop.slang | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 tests/spirv/infinite-loop.slang (limited to 'tests') diff --git a/tests/spirv/infinite-loop.slang b/tests/spirv/infinite-loop.slang new file mode 100644 index 000000000..1562f7334 --- /dev/null +++ b/tests/spirv/infinite-loop.slang @@ -0,0 +1,17 @@ +// Simple regression test for SPIRV compilation hang when there is cycle between unconditional branch and block. +// The -g was necessary to reproduce the hang prior to fix for https://github.com/shader-slang/slang/issues/8669 + +//TEST:SIMPLE(filecheck=CHECK): -target spirv -stage fragment -entry main -g +//CHECK: main +//CHECK: OpBranch +//CHECK: OpUnreachable + +layout(location = 0) out float4 output_color; +[shader("fragment")] +void main() +{ + while (true) { + int i = 0; + } + output_color = float4(1, 2, 3, 4); +} -- cgit v1.2.3