microsoft / microsoft/DirectXShaderCompiler
[SPIR-V] Compilation error: generated SPIR-V is invalid.
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 3.7k
- Forks
- 900
- Avg merge
- 2d 11h
- Merged PRs (30d)
- 44
Description
Description
When building an hlsl file (for a vulkan compute shader) to spirv, I got an compiler error message:
fatal error: generated SPIR-V is invalid: Expected int scalar or vector type as operand: IAdd operand index 3
%77 = OpIAdd %int %67 %75
No output spv file was generated.
Steps to Reproduce
My file on godbolt.org - produces the same crash.
Actual Behavior
On latest release (dxcompiler.dll: 1.9(5184-21d28f72)(1.9.2602.17) - 1.9.2602.17 (21d28f727)) of dxc I get this message:
fatal error: generated SPIR-V is invalid: Expected int scalar or vector type as operand: IAdd operand index 3
%78 = OpIAdd %int %68 %76
On build of version dxcompiler.dll: 1.8 - 1.8.0.4575 (4f4bb4208) which was installed with vulkan SDK, I got segfault:
Internal compiler error: access violation. Attempted to read from address 0x0000000000000030
After running it under lldb I got this backtrace
* thread #1, stop reason = Exception 0xc0000005 encountered at address 0x7ffd5821b320: Access violation reading location 0x00000030
* frame #0: 0x00007ffd5821b320 dxcompiler.dll`void spvtools::opt::AggressiveDCEPass::AddToWorklist(this=0x0000018ddae9d9b0, inst=0x0000000000000000) at aggressive_dead_code_elim_pass.h:93
frame #1: 0x00007ffd582038bb dxcompiler.dll`bool std::_Func_impl_no_alloc<class <lambda_0deb3abbf969e53bb02ac7506598fb03>, bool, unsigned int const *>::_Do_call(this=<unavailable>, <_Args_0>=<unavailable>) at xmemory:905
frame #2: 0x00007ffd5821c440 dxcompiler.dll`spvtools::opt::Instruction::WhileEachInId at functional:869 [inlined]
frame #3: 0x00007ffd5821c3f7 dxcompiler.dll`void spvtools::opt::Instruction::ForEachInId(this=<unavailable>, f=<unavailable>) const at instruction.h:838
frame #4: 0x00007ffd5821b1a8 dxcompiler.dll`void spvtools::opt::AggressiveDCEPass::AddOperandsToWorkList(this=0x0000018ddae9d9b0, inst=0x0000018ddaf05ce0) at aggressive_dead_code_elim_pass.cpp:514
frame #5: 0x00007ffd58220087 dxcompiler.dll`void spvtools::opt::AggressiveDCEPass::ProcessWorkList(this=0x0000018ddae9d9b0, func=0x0000018ddaeb5fa0) at aggressive_dead_code_elim_pass.cpp:333
frame #6: 0x00007ffd5821b961 dxcompiler.dll`bool spvtools::opt::AggressiveDCEPass::AggressiveDCE(this=0x0000018ddae9d9b0, func=0x0000018ddaeb5fa0) at aggressive_dead_code_elim_pass.cpp:269
frame #7: 0x00007ffd5821f1e0 dxcompiler.dll`enum spvtools::opt::Pass::Status spvtools::opt::AggressiveDCEPass::Process(this=0x0000018ddae9d9b0) at aggressive_dead_code_elim_pass.cpp:682
frame #8: 0x00007ffd5820e08d dxcompiler.dll`enum spvtools::opt::Pass::Status spvtools::opt::Pass::Run(this=0x0000018ddae9d9b0, ctx=0x0000018ddae9e210) at pass.cpp:37
frame #9: 0x00007ffd5821831f dxcompiler.dll`enum spvtools::opt::Pass::Status spvtools::opt::PassManager::Run(this=0x0000018ddae9b078, context=<unavailable>) at pass_manager.cpp:58
frame #10: 0x00007ffd5820057a dxcompiler.dll`bool spvtools::Optimizer::Run(this=0x000000823a58b250, original_binary=0x0000018ddae98300, original_binary_size=<unavailable>, optimized_binary=size=2891, opt_options=0x0000018ddae910c0) const at optimizer.cpp:684
frame #11: 0x00007ffd5811566c dxcompiler.dll`bool clang::spirv::SpirvEmitter::spirvToolsLegalize(this=0x0000018dd956e5f0, mod=size=2891, messages=<unavailable>, dsetbindingsToCombineImageSampler=size=0) at SpirvEmitter.cpp:14447
frame #12: 0x00007ffd580e1951 dxcompiler.dll`void clang::spirv::SpirvEmitter::HandleTranslationUnit(this=0x0000018dd956e5f0, context=0x0000018dd9557e90) at SpirvEmitter.cpp:902
frame #13: 0x00007ffd58187e98 dxcompiler.dll`void clang::ParseAST(S=0x0000018dd9570e60, PrintStats=<unavailable>, SkipFunctionBodies=<unavailable>) at ParseAST.cpp:164
frame #14: 0x00007ffd57b0c21f dxcompiler.dll`void clang::ASTFrontendAction::ExecuteAction(this=0x000000823a58cf30) at FrontendAction.cpp:554
frame #15: 0x00007ffd57b0c16c dxcompiler.dll`bool clang::FrontendAction::Execute(this=0x000000823a58cf30) at FrontendAction.cpp:455
frame #16: 0x00007ffd575972ca dxcompiler.dll`long DxcCompiler::Compile(this=0x00007ffde48b3900, pSource=0x0000018dd952c910, pArguments=0x0000018dd952c910, argCount=8, pIncludeHandler=0x0000018dd952ac90, riid=0x00007ffd585a0b78) at dxcompilerobj.cpp:973
frame #17: 0x00007ffd5759f15c dxcompiler.dll`long hlsl::DxcCompilerAdapter::WrapCompile(this=<unavailable>, bPreprocess=<unavailable>, pSource=<unavailable>, pSourceName=unable to read data, pEntryPoint=<unavailable>, pTargetProfile=<unavailable>, pArguments=<unavailable>, argCount=<unavailable>, pDefines=<unavailable>, defineCount=<unavailable>, pIncludeHandler=<unavailable>, ppResult=<unavailable>, ppDebugBlobName=<unavailable>, ppDebugBlob=0x0000000000000000) at dxcompilerobj.cpp:1845
frame #18: 0x00007ffd575998ff dxcompiler.dll`long hlsl::DxcCompilerAdapter::CompileWithDebug(this=0x0000018dd952ac40, pSource=0x0000018dd952bb00, pSourceName=L"kernel.hlsl", pEntryPoint=L"main", pTargetProfile=<unavailable>, pArguments=<unavailable>, argCount=978889776, pDefines=<unavailable>, defineCount=<unavailable>, pIncludeHandler=<unavailable>, ppResult=<unavailable>, ppDebugBlobName=<unavailable>, ppDebugBlob=<unavailable>) at dxcompilerobj.cpp:1748
frame #19: 0x00007ffd575997f7 dxcompiler.dll`long hlsl::DxcCompilerAdapter::Compile(this=0x0000018dd952ac40, pSource=<unavailable>, pSourceName=<unavailable>, pEntryPoint=<unavailable>, pTargetProfile=<unavailable>, pArguments=<unavailable>, argCount=<unavailable>, pDefines=<unavailable>, defineCount=<unavailable>, pIncludeHandler=<unavailable>, ppResult=<unavailable>) at dxcompileradapter.h:75
frame #20: 0x00007ff738e550a0 dxc.exe`int DxcContext::Compile(this=0x000000823a58f048) at xstring:2274
frame #21: 0x00007ff738e5cd59 dxc.exe`int dxc::main(argc=978889776, argv_=<unavailable>) at dxc.cpp:1502
frame #22: 0x00007ff738e6ce38 dxc.exe`__scrt_common_main_seh at exe_common.inl:288
frame #23: 0x00007ffde2e7e8d7 kernel32.dll`BaseThreadInitThunk + 23
frame #24: 0x00007ffde49ec3fc ntdll.dll`RtlUserThreadStart + 44
Environment
- DXC version:
dxcompiler.dll: 1.9(5184-21d28f72)(1.9.2602.17) - 1.9.2602.17 (21d28f727)/dxcompiler.dll: 1.8 - 1.8.0.4575 (4f4bb4208)/ latest on godbolt.com (all them have this issue) - Host Operating System: Windows 26200.8246
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Reproduce the failure using the linked Godbolt HLSL input and inspect SpirvEmitter.cpp at spirvToolsLegalize, along with the AggressiveDCEPass locations shown in the backtrace. Trace the generated IAdd operands through SPIR-V legalization and verify that the reproducer no longer emits invalid SPIR-V or crashes on the affected compiler versions.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp
- Domain
- compilers
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Quiet
- Clarity
- Needs clarification
- Newbie friendliness
- 45/100