Issue 113803
Summary Clang-20 : Assertion `!DT.isNull() && "Undeduced types shouldn't reach here."' failed.
Labels new issue
Assignees
Reporter iamanonymouscs
    ### Description
I encountered a crash in Clang-20 when compiling the following code snippet:

```cpp
 char myfunc();
 
 template<typename T> T my_templated_func();
 
 template<> auto my_templated_func()
 {
   return myfunc();
 }

```

###  Error Message
The compilation fails with the following assertion error:
```sh
clang++: /root/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp:3681: clang::QualType UnwrapTypeForDebugInfo(clang::QualType, const clang::ASTContext&): Assertion !DT.isNull() && "Undeduced types shouldn't reach here." failed.

```

### Command
```sh
clang++ bug.cpp -O3 -ffast-math -Wall -Wextra -fno-strict-aliasing -fwrapv -g -fsanitize=address -c -o bug.o

clang++: /root/llvm-project/clang/lib/CodeGen/CGDebugInfo.cpp:3681: clang::QualType UnwrapTypeForDebugInfo(clang::QualType, const clang::ASTContext&): Assertion `!DT.isNull() && "Undeduced types shouldn't reach here."' 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: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-snapshot -fcolor-diagnostics -fno-crash-diagnostics -O3 -ffast-math -Wall -Wextra -fno-strict-aliasing -fwrapv -g -fsanitize=address <source>
1.	<eof> parser at end of file
2.	<source>:5:18: LLVM IR generation of declaration 'my_templated_func'
3.	<source>:5:18: Generating code for declaration 'my_templated_func'
 #0 0x0000000003bd52c8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bd52c8)
 #1 0x0000000003bd2fcc llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3bd2fcc)
 #2 0x0000000003b209a8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007032d0e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007032d0e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007032d0e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007032d0e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007032d0e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007032d0e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x0000000003e86e5b UnwrapTypeForDebugInfo(clang::QualType, clang::ASTContext const&) CGDebugInfo.cpp:0:0
#10 0x0000000003ecf54c clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ecf54c)
#11 0x0000000003ed5a01 clang::CodeGen::CGDebugInfo::CollectTemplateParams(std::optional<clang::CodeGen::CGDebugInfo::TemplateArgs>, llvm::DIFile*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ed5a01)
#12 0x0000000003ee2be2 clang::CodeGen::CGDebugInfo::collectFunctionDeclProps(clang::GlobalDecl, llvm::DIFile*, llvm::StringRef&, llvm::StringRef&, llvm::DIScope*&, llvm::MDTupleTypedArrayWrapper<llvm::DINode>&, llvm::DINode::DIFlags&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ee2be2)
#13 0x0000000003ee3667 clang::CodeGen::CGDebugInfo::emitFunctionStart(clang::GlobalDecl, clang::SourceLocation, clang::SourceLocation, clang::QualType, llvm::Function*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ee3667)
#14 0x0000000003fb4bd6 clang::CodeGen::CodeGenFunction::StartFunction(clang::GlobalDecl, clang::QualType, llvm::Function*, clang::CodeGen::CGFunctionInfo const&, clang::CodeGen::FunctionArgList const&, clang::SourceLocation, clang::SourceLocation) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3fb4bd6)
#15 0x0000000003fba589 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3fba589)
#16 0x00000000040230aa clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x40230aa)
#17 0x000000000401dfd5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x401dfd5)
#18 0x000000000401e3bb clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x401e3bb)
#19 0x00000000040287b3 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#20 0x000000000454d106 (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#21 0x000000000453de38 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x453de38)
#22 0x00000000066a1884 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x66a1884)
#23 0x000000000454acb8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x454acb8)
#24 0x00000000048045d9 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48045d9)
#25 0x00000000047837be clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x47837be)
#26 0x00000000048e9cee clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48e9cee)
#27 0x0000000000ce2b8f cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xce2b8f)
#28 0x0000000000cda84a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#29 0x000000000458e0c9 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::'lambda'()>(long) Job.cpp:0:0
#30 0x0000000003b20e54 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3b20e54)
#31 0x000000000458e6bf clang::driver::CC1Command::Execute(llvm::ArrayRef<std::optional<llvm::StringRef>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>*, bool*) const (.part.0) Job.cpp:0:0
#32 0x000000000455487d clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455487d)
#33 0x000000000455596d clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455596d)
#34 0x000000000455cd25 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x455cd25)
#35 0x0000000000cdfa29 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcdfa29)
#36 0x0000000000baddb4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xbaddb4)
#37 0x00007032d0e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#38 0x00007032d0e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#39 0x0000000000cda2fe _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcda2fe)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```


The issue can also be reproduced on Compiler Explorer: https://godbolt.org/z/r9hhKz8zq
### Steps to Reproduce:

Compile the provided code snippet using Clang-20.
Observe the crash and assertion failure.

###  Additional Information
Please let me know if you need any more details.

Thank you for your assistance.
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to