Skip to content

[DirectX] DXIL Embedder triggers assertion "Value not in slotcalculator!" when writing switch statements #174485

@Icohedron

Description

@Icohedron

An assertion error started appearing after PR #170984 was merged when compiling HLSL with switch statements.

72 DML shaders are failing to compile on a debug/assertions build due to hitting this assertion.

Given the following shader

RWBuffer<float32_t4> input;
RWBuffer<float32_t4> output;
cbuffer Constants { uint32_t op; }
[numthreads(6, 1, 1)]
void CSMain() {
  switch (op) {
  case 1:
    output[0] = input[0];
  case 3:
    output[0] = input[1];
  default:
    output[0] = 0;
  }
}

Compiling to DXIL hits an assertion:

❯ /workspace/llvm-project/build/bin/clang-dxc -E CSMain -T cs_6_8 -Vd -Fo - Reproduce.hlsl
clang-dxc: /workspace/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp:522: unsigned int llvm::dxil::ValueEnumerator::getValueID(const Value *) const: Assertion `I != ValueMap.end() && "Value not in slotcalculator!"' failed.
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace, preprocessed source, and associated run script.
Stack dump:
0.      Program arguments: /workspace/llvm-project/build/bin/clang-dxc -E CSMain -T cs_6_8 -Vd -Fo - Reproduce.hlsl
1.      <eof> parser at end of file
2.      Code generation
3.      Running pass 'DXIL Embedder' on module 'Reproduce.hlsl'.
 #0 0x00005e670ac2b61b llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /workspace/llvm-project/llvm/lib/Support/Unix/Signals.inc:834:13
 #1 0x00005e670ac28fb3 llvm::sys::RunSignalHandlers() /workspace/llvm-project/llvm/lib/Support/Signals.cpp:105:18
 #2 0x00005e670ab93910 (anonymous namespace)::CrashRecoveryContextImpl::HandleCrash(int, unsigned long) /workspace/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:73:5
 #3 0x00005e670ab93910 CrashRecoverySignalHandler(int) /workspace/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:390:51
 #4 0x00007f0e46e419c0 __restore_rt (/nix/store/xx7cm72qy2c0643cm1ipngd87aqwkcdp-glibc-2.40-66/lib/libc.so.6+0x419c0)
 #5 0x00007f0e46e9caac __pthread_kill_implementation (/nix/store/xx7cm72qy2c0643cm1ipngd87aqwkcdp-glibc-2.40-66/lib/libc.so.6+0x9caac)
 #6 0x00007f0e46e4190e gsignal (/nix/store/xx7cm72qy2c0643cm1ipngd87aqwkcdp-glibc-2.40-66/lib/libc.so.6+0x4190e)
 #7 0x00007f0e46e28942 abort (/nix/store/xx7cm72qy2c0643cm1ipngd87aqwkcdp-glibc-2.40-66/lib/libc.so.6+0x28942)
 #8 0x00007f0e46e2885e _nl_load_domain.cold (/nix/store/xx7cm72qy2c0643cm1ipngd87aqwkcdp-glibc-2.40-66/lib/libc.so.6+0x2885e)
 #9 0x00007f0e46e396f7 (/nix/store/xx7cm72qy2c0643cm1ipngd87aqwkcdp-glibc-2.40-66/lib/libc.so.6+0x396f7)
#10 0x00005e670bb9a9fc llvm::DenseMapIterator<llvm::Value const*, unsigned int, llvm::DenseMapInfo<llvm::Value const*, void>, llvm::detail::DenseMapPair<llvm::Value const*, unsigned int>, true>::operator*() const /workspace/llvm-project/llvm/include/llvm/ADT/DenseMap.h:1212:5
#11 0x00005e670bb9a9fc llvm::DenseMapIterator<llvm::Value const*, unsigned int, llvm::DenseMapInfo<llvm::Value const*, void>, llvm::detail::DenseMapPair<llvm::Value const*, unsigned int>, true>::operator->() const /workspace/llvm-project/llvm/include/llvm/ADT/DenseMap.h:1215:54
#12 0x00005e670bb9a9fc llvm::dxil::ValueEnumerator::getValueID(llvm::Value const*) const /workspace/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILValueEnumerator.cpp:523:10
#13 0x00005e670bb8fce2 llvm::SmallVectorBase<unsigned int>::size() const /workspace/llvm-project/llvm/include/llvm/ADT/SmallVector.h:80:32
#14 0x00005e670bb8fce2 unsigned int const* llvm::SmallVectorTemplateCommon<unsigned int, void>::reserveForParamAndGetAddressImpl<llvm::SmallVectorTemplateBase<unsigned int, true>>(llvm::SmallVectorTemplateBase<unsigned int, true>*, unsigned int const&, unsigned long) /workspace/llvm-project/llvm/include/llvm/ADT/SmallVector.h:235:28
#15 0x00005e670bb8fce2 llvm::SmallVectorTemplateBase<unsigned int, true>::reserveForParamAndGetAddress(unsigned int&, unsigned long) /workspace/llvm-project/llvm/include/llvm/ADT/SmallVector.h:538:9
#16 0x00005e670bb8fce2 llvm::SmallVectorTemplateBase<unsigned int, true>::push_back(unsigned int) /workspace/llvm-project/llvm/include/llvm/ADT/SmallVector.h:563:23
#17 0x00005e670bb8fce2 llvm::dxil::DXILBitcodeWriter::writeInstruction(llvm::Instruction const&, unsigned int, llvm::SmallVectorImpl<unsigned int>&) /workspace/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp:2354:12
#18 0x00005e670bb9347b llvm::ilist_detail::node_base_prevnext<llvm::ilist_node_base<true, llvm::BasicBlock>, true>::isSentinel() const /workspace/llvm-project/llvm/include/llvm/ADT/ilist_node_base.h:44:36
#19 0x00005e670bb9347b llvm::ilist_detail::node_base_prevnext<llvm::ilist_node_base<true, llvm::BasicBlock>, true>::isKnownSentinel() const /workspace/llvm-project/llvm/include/llvm/ADT/ilist_node_base.h:45:41
#20 0x00005e670bb9347b llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, true>::operator*() const /workspace/llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:322:5
#21 0x00005e670bb9347b llvm::ilist_iterator_w_bits<llvm::ilist_detail::node_options<llvm::Instruction, true, false, void, true, llvm::BasicBlock>, false, true>::operator->() const /workspace/llvm-project/llvm/include/llvm/ADT/ilist_iterator.h:325:40
#22 0x00005e670bb9347b llvm::dxil::DXILBitcodeWriter::writeFunction(llvm::Function const&) /workspace/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp:2653:12
#23 0x00005e670bb7f281 llvm::dxil::DXILBitcodeWriter::write() /workspace/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp:0:7
#24 0x00005e670bb7ec6c llvm::DenseMap<llvm::Value const*, llvm::Type*, llvm::DenseMapInfo<llvm::Value const*, void>, llvm::detail::DenseMapPair<llvm::Value const*, llvm::Type*>>::deallocateBuckets() /workspace/llvm-project/llvm/include/llvm/ADT/DenseMap.h:826:23
#25 0x00005e670bb7ec6c llvm::DenseMap<llvm::Value const*, llvm::Type*, llvm::DenseMapInfo<llvm::Value const*, void>, llvm::detail::DenseMapPair<llvm::Value const*, llvm::Type*>>::~DenseMap() /workspace/llvm-project/llvm/include/llvm/ADT/DenseMap.h:788:5
#26 0x00005e670bb7ec6c llvm::dxil::DXILBitcodeWriter::~DXILBitcodeWriter() /workspace/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp:65:7
#27 0x00005e670bb7ec6c llvm::dxil::BitcodeWriter::writeModule(llvm::Module const&) /workspace/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp:437:1
#28 0x00005e670bb7eb00 llvm::SmallVectorBase<unsigned long>::empty() const /workspace/llvm-project/llvm/include/llvm/ADT/SmallVector.h:83:46
#29 0x00005e670bb7eb00 llvm::dxil::WriteDXILToFile(llvm::Module const&, llvm::raw_ostream&) /workspace/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILBitcodeWriter.cpp:409:15
#30 0x00005e670bb7e274 (anonymous namespace)::removeLifetimeIntrinsics(llvm::Module&) /workspace/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp:123:33
#31 0x00005e670bb7e274 (anonymous namespace)::EmbedDXILPass::runOnModule(llvm::Module&) /workspace/llvm-project/llvm/lib/Target/DirectX/DXILWriter/DXILWriterPass.cpp:161:5
#32 0x00005e670a6c4774 (anonymous namespace)::MPPassManager::runOnModule(llvm::Module&) /workspace/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:0:27
#33 0x00005e670a6c4774 llvm::legacy::PassManagerImpl::run(llvm::Module&) /workspace/llvm-project/llvm/lib/IR/LegacyPassManager.cpp:531:44
#34 0x00005e670b3980eb (anonymous namespace)::EmitAssemblyHelper::RunCodegenPipeline(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>&, std::unique_ptr<llvm::ToolOutputFile, std::default_delete<llvm::ToolOutputFile>>&) /workspace/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1311:9
#35 0x00005e670b3980eb (anonymous namespace)::EmitAssemblyHelper::emitAssembly(clang::BackendAction, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /workspace/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1334:3
#36 0x00005e670b3980eb clang::emitBackendOutput(clang::CompilerInstance&, clang::CodeGenOptions&, llvm::StringRef, llvm::Module*, clang::BackendAction, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>, std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>, clang::BackendConsumer*) /workspace/llvm-project/clang/lib/CodeGen/BackendUtil.cpp:1504:13
#37 0x00005e670b3ac048 std::unique_ptr<llvm::raw_pwrite_stream, std::default_delete<llvm::raw_pwrite_stream>>::~unique_ptr() /nix/store/kzq78n13l8w24jn8bx4djj79k5j717f1-gcc-14.3.0/include/c++/14.3.0/bits/unique_ptr.h:398:6
#38 0x00005e670b3ac048 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) /workspace/llvm-project/clang/lib/CodeGen/CodeGenAction.cpp:312:3
#39 0x00005e670cf0ba29 __gnu_cxx::__normal_iterator<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback>>*, std::vector<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback>>, std::allocator<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback>>>>>::__normal_iterator(std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback>>* const&) /nix/store/kzq78n13l8w24jn8bx4djj79k5j717f1-gcc-14.3.0/include/c++/14.3.0/bits/stl_iterator.h:1068:20
#40 0x00005e670cf0ba29 std::vector<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback>>, std::allocator<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback>>>>::begin() /nix/store/kzq78n13l8w24jn8bx4djj79k5j717f1-gcc-14.3.0/include/c++/14.3.0/bits/stl_vector.h:887:16
#41 0x00005e670cf0ba29 void clang::finalize<std::vector<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback>>, std::allocator<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback>>>>>(std::vector<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback>>, std::allocator<std::unique_ptr<clang::TemplateInstantiationCallback, std::default_delete<clang::TemplateInstantiationCallback>>>>&, clang::Sema const&) /workspace/llvm-project/clang/include/clang/Sema/TemplateInstCallback.h:54:16
#42 0x00005e670cf0ba29 clang::ParseAST(clang::Sema&, bool, bool) /workspace/llvm-project/clang/lib/Parse/ParseAST.cpp:190:3
#43 0x00005e670b8f4bcf clang::HLSLFrontendAction::ExecuteAction() /workspace/llvm-project/clang/lib/Frontend/FrontendActions.cpp:0:35
#44 0x00005e670b8be3d7 clang::FrontendAction::Execute() /workspace/llvm-project/clang/lib/Frontend/FrontendAction.cpp:1316:10
#45 0x00005e670b8291fd llvm::Error::getPtr() const /workspace/llvm-project/llvm/include/llvm/Support/Error.h:278:42
#46 0x00005e670b8291fd llvm::Error::operator bool() /workspace/llvm-project/llvm/include/llvm/Support/Error.h:241:16
#47 0x00005e670b8291fd clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /workspace/llvm-project/clang/lib/Frontend/CompilerInstance.cpp:1003:23
#48 0x00005e670b9b3cd2 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /workspace/llvm-project/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:310:25
#49 0x00005e670972eb58 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /workspace/llvm-project/clang/tools/driver/cc1_main.cpp:301:15
#50 0x00005e670972af22 ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) /workspace/llvm-project/clang/tools/driver/driver.cpp:225:12
#51 0x00005e670972d2ec clang_main(int, char**, llvm::ToolContext const&)::$_0::operator()(llvm::SmallVectorImpl<char const*>&) const /workspace/llvm-project/clang/tools/driver/driver.cpp:0:12
#52 0x00005e670972d2ec int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::$_0>(long, llvm::SmallVectorImpl<char const*>&) /workspace/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#53 0x00005e670b69a71e clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*,bool*) const::$_0::operator()() const /workspace/llvm-project/clang/lib/Driver/Job.cpp:437:30
#54 0x00005e670b69a71e void llvm::function_ref<void ()>::callback_fn<clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const::$_0>(long) /workspace/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:46:12
#55 0x00005e670ab93509 llvm::function_ref<void ()>::operator()() const /workspace/llvm-project/llvm/include/llvm/ADT/STLFunctionalExtras.h:0:12
#56 0x00005e670ab93509 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) /workspace/llvm-project/llvm/lib/Support/CrashRecoveryContext.cpp:426:3
#57 0x00005e670b699cf9 clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*,bool*) const /workspace/llvm-project/clang/lib/Driver/Job.cpp:437:7
#58 0x00005e670b65aa26 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const /workspace/llvm-project/clang/lib/Driver/Compilation.cpp:196:15
#59 0x00005e670b65ac98 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const /workspace/llvm-project/clang/lib/Driver/Compilation.cpp:246:13
#60 0x00005e670b6742a9 llvm::SmallVectorBase<unsigned int>::empty() const /workspace/llvm-project/llvm/include/llvm/ADT/SmallVector.h:83:46
#61 0x00005e670b6742a9 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) /workspace/llvm-project/clang/lib/Driver/Driver.cpp:2263:23
#62 0x00005e670972a8a3 clang_main(int, char**, llvm::ToolContext const&) /workspace/llvm-project/clang/tools/driver/driver.cpp:407:21
#63 0x00005e670973ab7f main /workspace/llvm-project/build/tools/clang/tools/driver/clang-driver.cpp:17:10
#64 0x00007f0e46e2a4d8 __libc_start_call_main (/nix/store/xx7cm72qy2c0643cm1ipngd87aqwkcdp-glibc-2.40-66/lib/libc.so.6+0x2a4d8)
#65 0x00007f0e46e2a59b __libc_start_main@GLIBC_2.2.5 (/nix/store/xx7cm72qy2c0643cm1ipngd87aqwkcdp-glibc-2.40-66/lib/libc.so.6+0x2a59b)
#66 0x00005e6709728825 _start (/workspace/llvm-project/build/bin/clang-dxc+0x2e58825)
clang-dxc: error: clang frontend command failed with exit code 134 (use -v to see invocation)
clang version 22.0.0git ([email protected]:Icohedron/llvm-project.git 6813f8f037124c53c54d5fe86abe50d71c81d42a)
Target: dxilv1.8-unknown-shadermodel6.8-compute
Thread model: posix
InstalledDir: /workspace/llvm-project/build/bin
Build config: +assertions
clang-dxc: note: diagnostic msg:
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang-dxc: note: diagnostic msg: /tmp/nix-shell-1588868-4206495458/Reproduce-d77412.hlsl
clang-dxc: note: diagnostic msg: /tmp/nix-shell-1588868-4206495458/Reproduce-d77412.sh
clang-dxc: note: diagnostic msg:

********************

Metadata

Metadata

Assignees

Labels

clang:HLSL:DXClang HLSL DX(IL|BC) support

Type

Projects

Status

Active

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions