Front end crash on short (66 byte) code snippet (original) (raw)

Running clang++ a.cpp with up to date build (987087df90026605fc8d03ebda5a1cd31b71e609, 2024-01-23) on:

template <typename = int> struct a; auto f() { a c; return c; }

(demonstrated: https://godbolt.org/z/4jv8E7ns8)

…gives:

a.cpp:3:4: error: implicit instantiation of undefined template 'a<>'
    3 |         a c;
      |           ^
a.cpp:1:34: note: template is declared here
    1 | template <typename = int> struct a;
      |                                  ^
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: /the-llvm-dir/bin/clang-19 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -mrelax-all -dumpdir a- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name a.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 -debugger-tuning=gdb -fdebug-compilation-dir=/tmp -fcoverage-compilation-dir=/tmp -resource-dir /the-llvm-dir/lib/clang/19 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/x86_64-linux-gnu/c++/12 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../include/c++/12/backward -internal-isystem /the-llvm-dir/lib/clang/19/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/12/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/a-a3d6fd.o -x c++ a.cpp
1.	a.cpp:4:10: current parser token ';'
2.	a.cpp:2:10: parsing function body 'f'
3.	a.cpp:2:10: in compound statement ('{}')
 #0 0x000055ec1be34450 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/the-llvm-dir/bin/clang-19+0x37c5450)
 #1 0x000055ec1be31a1e SignalHandler(int) Signals.cpp:0:0
 #2 0x00007fc8d5e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x000055ec1f08070c clang::ASTContext::getASTRecordLayout(clang::RecordDecl const*) const (/the-llvm-dir/bin/clang-19+0x6a1170c)
 #4 0x000055ec1ec1d0c4 clang::ASTContext::getTypeInfoImpl(clang::Type const*) const (/the-llvm-dir/bin/clang-19+0x65ae0c4)
 #5 0x000055ec1ec06f42 clang::ASTContext::getTypeInfo(clang::Type const*) const (/the-llvm-dir/bin/clang-19+0x6597f42)
 #6 0x000055ec1ec06f42 clang::ASTContext::getTypeInfo(clang::Type const*) const (/the-llvm-dir/bin/clang-19+0x6597f42)
 #7 0x000055ec1ec06f42 clang::ASTContext::getTypeInfo(clang::Type const*) const (/the-llvm-dir/bin/clang-19+0x6597f42)
 #8 0x000055ec1ec1d729 clang::ASTContext::getTypeAlignInChars(clang::QualType) const (/the-llvm-dir/bin/clang-19+0x65ae729)
 #9 0x000055ec1e71591c clang::Sema::getNamedReturnInfo(clang::VarDecl const*) (/the-llvm-dir/bin/clang-19+0x60a691c)
#10 0x000055ec1e7159a2 clang::Sema::getNamedReturnInfo(clang::Expr*&, clang::Sema::SimplerImplicitMoveMode) (/the-llvm-dir/bin/clang-19+0x60a69a2)
#11 0x000055ec1e73e0a4 clang::Sema::BuildReturnStmt(clang::SourceLocation, clang::Expr*, bool) (/the-llvm-dir/bin/clang-19+0x60cf0a4)
#12 0x000055ec1e73f8c7 clang::Sema::ActOnReturnStmt(clang::SourceLocation, clang::Expr*, clang::Scope*) (/the-llvm-dir/bin/clang-19+0x60d08c7)
#13 0x000055ec1df53718 clang::Parser::ParseStatementOrDeclarationAfterAttributes(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*, clang::ParsedAttributes&, clang::ParsedAttributes&) (/the-llvm-dir/bin/clang-19+0x58e4718)
#14 0x000055ec1df546c8 clang::Parser::ParseStatementOrDeclaration(llvm::SmallVector<clang::Stmt*, 32u>&, clang::Parser::ParsedStmtContext, clang::SourceLocation*) (/the-llvm-dir/bin/clang-19+0x58e56c8)
#15 0x000055ec1df554c1 clang::Parser::ParseCompoundStatementBody(bool) (/the-llvm-dir/bin/clang-19+0x58e64c1)
#16 0x000055ec1df5844a clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/the-llvm-dir/bin/clang-19+0x58e944a)
#17 0x000055ec1de73ae6 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::LateParsedAttrList*) (/the-llvm-dir/bin/clang-19+0x5804ae6)
#18 0x000055ec1dead3df clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/the-llvm-dir/bin/clang-19+0x583e3df)
#19 0x000055ec1de6e4f6 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/the-llvm-dir/bin/clang-19+0x57ff4f6)
#20 0x000055ec1de75c42 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/the-llvm-dir/bin/clang-19+0x5806c42)
#21 0x000055ec1de77627 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/the-llvm-dir/bin/clang-19+0x5808627)
#22 0x000055ec1de67d2a clang::ParseAST(clang::Sema&, bool, bool) (/the-llvm-dir/bin/clang-19+0x57f8d2a)
#23 0x000055ec1c8c6b31 clang::FrontendAction::Execute() (/the-llvm-dir/bin/clang-19+0x4257b31)
#24 0x000055ec1c8454f9 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/the-llvm-dir/bin/clang-19+0x41d64f9)
#25 0x000055ec1c989113 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/the-llvm-dir/bin/clang-19+0x431a113)
#26 0x000055ec194cc833 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/the-llvm-dir/bin/clang-19+0xe5d833)
#27 0x000055ec194c4c9d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x000055ec194c88fa clang_main(int, char**, llvm::ToolContext const&) (/the-llvm-dir/bin/clang-19+0xe598fa)
#29 0x000055ec193c9e9b main (/the-llvm-dir/bin/clang-19+0xd5ae9b)
#30 0x00007fc8d5e29d90 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:58:16
#31 0x00007fc8d5e29e40 call_init ./csu/../csu/libc-start.c:128:20
#32 0x00007fc8d5e29e40 __libc_start_main ./csu/../csu/libc-start.c:379:5
#33 0x000055ec194c4115 _start (/the-llvm-dir/bin/clang-19+0xe55115)
clang++: error: unable to execute command: Segmentation fault (core dumped)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 19.0.0git (https://github.com/llvm/llvm-project.git 987087df90026605fc8d03ebda5a1cd31b71e609)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /the-llvm-dir/bin
clang++: note: diagnostic msg: 
********************

PLEASE ATTACH THE FOLLOWING FILES TO THE BUG REPORT:
Preprocessed source(s) and associated run script(s) are located at:
clang++: note: diagnostic msg: /tmp/a-f4ce2e.cpp
clang++: note: diagnostic msg: /tmp/a-f4ce2e.sh
clang++: note: diagnostic msg: 

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