Clang crashes due to undeduced types when supplied with -g (original) (raw)
The following code triggers a crash only when clang is supplied with the -g flag. Some debugging shows that the root cause is UnwrapTypeForDebugInfo, where an assert fails with a message of "Undeduced types shouldn't reach here."
struct foo {};
template struct bar { using type = T;
template <foo>
inline static constexpr auto b = true;};
template concept C = requires(T a) { T::template b<foo{}>; };
template auto fn(T) { if constexpr (!C) return foo{}; else return T{}; }
int main() { auto a = decltype(fn(bar{})){}; }
Logs:
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: /usr/bin/clang-14 -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all --mrelax-relocations -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name test.cpp -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -mllvm -treat-scalable-fixed-error-as-warning -debug-info-kind=constructor -dwarf-version=5 -debugger-tuning=gdb -fcoverage-compilation-dir=/home/flowey/dev/cpp/comptime-config -resource-dir /usr/lib/clang/14.0.6 -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0 -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0/x86_64-pc-linux-gnu -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../include/c++/12.1.0/backward -internal-isystem /usr/lib/clang/14.0.6/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib64/gcc/x86_64-pc-linux-gnu/12.1.0/../../../../x86_64-pc-linux-gnu/include -internal-externc-isystem /include -internal-externc-isystem /usr/include -std=c++20 -fdeprecated-macro -fdebug-compilation-dir=/home/flowey/dev/cpp/comptime-config -ferror-limit 19 -stack-protector 2 -fgnuc-version=4.2.1 -fno-implicit-modules -fcxx-exceptions -fexceptions -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-5fc305.o -x c++ test.cpp 1. parser at end of file 2. test.cpp:26:5: LLVM IR generation of declaration 'main' 3. test.cpp:26:5: Generating code for declaration 'main' #0 0x00007f6b8f2d553a (/usr/lib/libLLVM-14.so+0xcd553a) #1 0x00007f6b8f2d2bcf llvm::sys::RunSignalHandlers() (/usr/lib/libLLVM-14.so+0xcd2bcf) #2 0x00007f6b8f2d2d1d (/usr/lib/libLLVM-14.so+0xcd2d1d) #3 0x00007f6b8de3e8e0 (/usr/lib/libc.so.6+0x3e8e0) #4 0x00007f6b96da94e9 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*, clang::TypeLoc) (/usr/lib/libclang-cpp.so.14+0x15a94e9) #5 0x00007f6b96dadd7d clang::CodeGen::CGDebugInfo::CreateRecordStaticField(clang::VarDecl const*, llvm::DIType*, clang::RecordDecl const*) (/usr/lib/libclang-cpp.so.14+0x15add7d) #6 0x00007f6b96dae57a clang::CodeGen::CGDebugInfo::CollectRecordFields(clang::RecordDecl const*, llvm::DIFile*, llvm::SmallVectorImplllvm::Metadata*&, llvm::DICompositeType*) (/usr/lib/libclang-cpp.so.14+0x15ae57a) #7 0x00007f6b96da8b3c clang::CodeGen::CGDebugInfo::CreateTypeDefinition(clang::RecordType const*) (/usr/lib/libclang-cpp.so.14+0x15a8b3c) #8 0x00007f6b96da9794 clang::CodeGen::CGDebugInfo::getOrCreateType(clang::QualType, llvm::DIFile*, clang::TypeLoc) (/usr/lib/libclang-cpp.so.14+0x15a9794) #9 0x00007f6b96dc1aad clang::CodeGen::CGDebugInfo::EmitDeclare(clang::VarDecl const*, llvm::Value*, llvm::Optional, clang::CodeGen::CGBuilderTy&, bool) (/usr/lib/libclang-cpp.so.14+0x15c1aad) #10 0x00007f6b96dec519 clang::CodeGen::CodeGenFunction::EmitAutoVarAlloca(clang::VarDecl const&) (/usr/lib/libclang-cpp.so.14+0x15ec519) #11 0x00007f6b96e07f2e clang::CodeGen::CodeGenFunction::EmitAutoVarDecl(clang::VarDecl const&) (/usr/lib/libclang-cpp.so.14+0x1607f2e) #12 0x00007f6b96e08132 clang::CodeGen::CodeGenFunction::EmitDecl(clang::Decl const&) (/usr/lib/libclang-cpp.so.14+0x1608132) #13 0x00007f6b96f25467 clang::CodeGen::CodeGenFunction::EmitDeclStmt(clang::DeclStmt const&) (/usr/lib/libclang-cpp.so.14+0x1725467) #14 0x00007f6b96f58905 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/libclang-cpp.so.14+0x1758905) #15 0x00007f6b96f53992 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/usr/lib/libclang-cpp.so.14+0x1753992) #16 0x00007f6b96f549e1 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/usr/lib/libclang-cpp.so.14+0x17549e1) #17 0x00007f6b96f82b8a clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/usr/lib/libclang-cpp.so.14+0x1782b8a)est-6a6088.sh.txt #18 0x00007f6b96f99e8e clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/usr/lib/libclang-cpp.so.14+0x1799e8e) #19 0x00007f6b96fcd97f clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/libclang-cpp.so.14+0x17cd97f) #20 0x00007f6b96fcaf84 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/usr/lib/libclang-cpp.so.14+0x17caf84) #21 0x00007f6b96fd54ff (/usr/lib/libclang-cpp.so.14+0x17d54ff) #22 0x00007f6b97026df9 (/usr/lib/libclang-cpp.so.14+0x1826df9) #23 0x00007f6b96f62188 (/usr/lib/libclang-cpp.so.14+0x1762188) #24 0x00007f6b95fd9e23 clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/libclang-cpp.so.14+0x7d9e23) #25 0x00007f6b975b3929 clang::FrontendAction::Execute() (/usr/lib/libclang-cpp.so.14+0x1db3929) #26 0x00007f6b97552df7 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/libclang-cpp.so.14+0x1d52df7) #27 0x00007f6b9760a78a clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/libclang-cpp.so.14+0x1e0a78a) #28 0x0000563d22d836f1 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/bin/clang-14+0x176f1) #29 0x0000563d22d85337 (/usr/bin/clang-14+0x19337) #30 0x0000563d22d79216 main (/usr/bin/clang-14+0xd216) #31 0x00007f6b8de29290 (/usr/lib/libc.so.6+0x29290) #32 0x00007f6b8de2934a __libc_start_main (/usr/lib/libc.so.6+0x2934a) #33 0x0000563d22d7b655 _start (/usr/bin/clang-14+0xf655) clang-14: error: unable to execute command: Segmentation fault (core dumped) clang-14: error: clang frontend command failed due to signal (use -v to see invocation) clang version 14.0.6 Target: x86_64-pc-linux-gnu Thread model: posix InstalledDir: /usr/bin clang-14: note: diagnostic msg:
PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT: Preprocessed source(s) and associated run script(s) are located at: clang-14: note: diagnostic msg: /tmp/test-236daf.cpp clang-14: note: diagnostic msg: /tmp/test-236daf.sh clang-14: note: diagnostic msg: