KhronosGroup / KhronosGroup/SPIRV-Tools
[SpirvOpt] --eliminate-dead-code-aggressive causes a crash when DebugBuildIdentifier is used
- Dominant language
- C++
- Stars
- 1.4k
- Forks
- 709
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 28
Description
When DebugBuildIdentifier is used with a SpirvOpt option, `--eliminate-dead-code-aggressive`, it causes a crash in Release build; or fails an assertion in Debug build.
Here is the repro SpirvCode:
```
$ cat dump.2.spv-asm
OpCapability RayTracingKHR
OpCapability Shader
OpExtension "SPV_KHR_non_semantic_info"
OpExtension "SPV_KHR_ray_tracing"
%15 = OpExtInstImport "NonSemantic.Shader.DebugInfo.100"
OpMemoryModel Logical GLSL450
OpEntryPoint MissKHR %jkwak_1 "main" %c_pi %c_twoPi
%18 = OpString "01cfb4b77c321225f096da8ac72f29d42f0632a7"
OpSource Slang 1
%void = OpTypeVoid
%uint = OpTypeInt 32 0
%uint_0 = OpConstant %uint 0
%22 = OpTypeFunction %void
%float = OpTypeFloat 32
%_ptr_Private_float = OpTypePointer Private %float
%float_3_14159274 = OpConstant %float 3.14159274
%float_6_28318548 = OpConstant %float 6.28318548
%17 = OpExtInst %void %15 DebugBuildIdentifier %18 %uint_0
%c_pi = OpVariable %_ptr_Private_float Private
%c_twoPi = OpVariable %_ptr_Private_float Private
%jkwak_1 = OpFunction %void None %22
%23 = OpLabel
OpStore %c_pi %float_3_14159274
OpStore %c_twoPi %float_6_28318548
OpReturn
OpFunctionEnd
```
Then I compiled it to Spirv binary:
```
$ /c/vulkan-sdk-1.4.341/Debug/spirv-as.exe dump.2.spv-asm -o dump.2.spv-asm.spv
$ /c/vulkan-sdk-1.4.341/Debug/spirv-val.exe dump.2.spv-asm.spv && echo Good
Good
```
Then I ran spirv-opt with the option `--eliminate-dead-code-aggressive`:
```
$ /c/vulkan-sdk-1.4.341/Debug/spirv-opt.exe dump.2.spv-asm.spv -o dump.2.opt.spv --eliminate-dead-code-aggressive
Assertion failed: def && "Definition is not registered.", file D:\sbf\git\SPIRV-Tools\source\opt\def_use_manager.cpp, line 56
```
Contributor guide
Research direction
Reproduce the failure with the provided dump.2.spv-asm input by running spirv-as, spirv-val, and spirv-opt with --eliminate-dead-code-aggressive. Start in source/opt/def_use_manager.cpp at the reported assertion, then trace the optimizer path involved. Done means the repro completes without a Release crash or Debug assertion.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100