llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.81k stars 11.91k forks source link

clang crash when evaluating invalid initalized #104767

Open kadircet opened 2 months ago

kadircet commented 2 months ago

$ cat preprocessed.cc

template <a> long b();
template <typename f = int> struct g {
  using h = decltype(b<f>());
  h m_fn1();
};
auto o = g();
long a(o.m_fn1());
$ ~/repos/llvm/build/bin/clang -Wno-everything -std=c++20 -xc++ preprocessed.cc
preprocessed.cc:1:11: error: unknown type name 'a'
    1 | template <a> long b();
      |           ^
preprocessed.cc:3:22: error: no matching function for call to 'b'
    3 |   using h = decltype(b<f>());
      |                      ^~~~
preprocessed.cc:6:10: note: in instantiation of template class 'g<>' requested here
    6 | auto o = g();
      |          ^
preprocessed.cc:1:19: note: candidate template ignored: invalid explicitly-specified argument for 1st template parameter
    1 | template <a> long b();
      |                   ^
clang-20: /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/AST/Type.h:957: const ExtQualsTypeCommonBase *clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' 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: /usr/local/google/home/kadircet/repos/llvm/build/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name preprocessed.cc -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=/usr/local/google/home/kadircet/repos/tmp/clangd_crashes/68c6c10f-0000-2aaf-8985-3c286d3cf65a/0 -fcoverage-compilation-dir=/usr/local/google/home/kadircet/repos/tmp/clangd_crashes/68c6c10f-0000-2aaf-8985-3c286d3cf65a/0 -resource-dir /usr/local/google/home/kadircet/repos/llvm/build/lib/clang/20 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/local/google/home/kadircet/repos/llvm/build/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-everything -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/preprocessed-1b3d70.o -x c++ preprocessed.cc
1.      preprocessed.cc:7:18: current parser token ';'
 #0 0x00005624ec1b76e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:723:13
 #1 0x00005624ec1b52be llvm::sys::RunSignalHandlers() /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Signals.cpp:106:18
 #2 0x00005624ec1b7d98 SignalHandler(int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:413:1
 #3 0x00007f29f32591a0 (/lib/x86_64-linux-gnu/libc.so.6+0x3d1a0)
 #4 0x00007f29f32a70ec __pthread_kill_implementation ./nptl/pthread_kill.c:44:76
 #5 0x00007f29f3259102 gsignal ./signal/../sysdeps/posix/raise.c:27:6
 #6 0x00007f29f32424f2 abort ./stdlib/abort.c:81:7
 #7 0x00007f29f3242415 _nl_load_domain ./intl/loadmsgcat.c:1177:9
 #8 0x00007f29f3251d32 (/lib/x86_64-linux-gnu/libc.so.6+0x35d32)
 #9 0x00005624ef975993 doit /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:109:5
#10 0x00005624ef975993 doit /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:137:12
#11 0x00005624ef975993 doit /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:127:12
#12 0x00005624ef975993 isPossible /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:255:12
#13 0x00005624ef975993 isPossible /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:509:12
#14 0x00005624ef975993 isa<clang::ArrayType, clang::QualType> /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:549:10
#15 0x00005624ef975993 isArrayType /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/AST/Type.h:8076:10
#16 0x00005624ef975993 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:0:0
#17 0x00005624ef976097 clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:16312:12
#18 0x00005624ef8d3fbf clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/Decl.cpp:2572:32
#19 0x00005624ef8d4117 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/Decl.cpp:2640:35
#20 0x00005624eeb10f68 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDecl.cpp:0:27
#21 0x00005624eeb0fc1f clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDecl.cpp:0:3
#22 0x00005624ee8344b0 InitializerScopeRAII /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDecl.cpp:2670:11
#23 0x00005624ee8344b0 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDecl.cpp:2842:26
#24 0x00005624ee831ac0 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDecl.cpp:2523:7
#25 0x00005624ee7ba579 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:0:10
#26 0x00005624ee7b9d92 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:1266:12
#27 0x00005624ee7b8b79 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:0:14
#28 0x00005624ee7b6bba clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:758:10
#29 0x00005624ee7b210e clang::ParseAST(clang::Sema&, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseAST.cpp:170:5
#30 0x00005624ece66a3f clang::FrontendAction::Execute() /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/FrontendAction.cpp:1082:10
#31 0x00005624ecdd1a9d getPtr /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Error.h:279:42
#32 0x00005624ecdd1a9d operator bool /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Error.h:242:16
#33 0x00005624ecdd1a9d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/CompilerInstance.cpp:1061:23
#34 0x00005624ecf4ebfe clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:280:25
#35 0x00005624e9a4ae2b cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/cc1_main.cpp:285:15
#36 0x00005624e9a4750d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:215:12
#37 0x00005624e9a462b8 clang_main(int, char**, llvm::ToolContext const&) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:256:12
#38 0x00005624e9a57c67 main /usr/local/google/home/kadircet/repos/llvm/build/tools/clang/tools/driver/clang-driver.cpp:17:10
#39 0x00007f29f3243b8a __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#40 0x00007f29f3243c45 call_init ./csu/../csu/libc-start.c:128:20
#41 0x00007f29f3243c45 __libc_start_main ./csu/../csu/libc-start.c:347:5
#42 0x00005624e9a44e61 _start (/usr/local/google/home/kadircet/repos/llvm/build/bin/clang-20+0x56c0e61)
clang: error: unable to execute command: Aborted
clang: error: clang frontend command failed due to signal (use -v to see invocation)
clang version 20.0.0git (git@github.com:kadircet/llvm-project.git 48b7a2c9ebbb5d8ea6be53ef034d2e67558ef97c)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/local/google/home/kadircet/repos/llvm/build/bin
Build config: +assertions
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/preprocessed-ca391b.cpp
clang: note: diagnostic msg: /tmp/preprocessed-ca391b.sh
clang: note: diagnostic msg:

********************
llvmbot commented 2 months ago

@llvm/issue-subscribers-clang-frontend

Author: kadir çetinkaya (kadircet)

```cpp $ cat preprocessed.cc template <a> long b(); template <typename f = int> struct g { using h = decltype(b<f>()); h m_fn1(); }; auto o = g(); long a(o.m_fn1()); ``` ``` $ ~/repos/llvm/build/bin/clang -Wno-everything -std=c++20 -xc++ preprocessed.cc preprocessed.cc:1:11: error: unknown type name 'a' 1 | template <a> long b(); | ^ preprocessed.cc:3:22: error: no matching function for call to 'b' 3 | using h = decltype(b<f>()); | ^~~~ preprocessed.cc:6:10: note: in instantiation of template class 'g<>' requested here 6 | auto o = g(); | ^ preprocessed.cc:1:19: note: candidate template ignored: invalid explicitly-specified argument for 1st template parameter 1 | template <a> long b(); | ^ clang-20: /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/AST/Type.h:957: const ExtQualsTypeCommonBase *clang::QualType::getCommonPtr() const: Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' 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: /usr/local/google/home/kadircet/repos/llvm/build/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir a- -disable-free -clear-ast-before-backend -main-file-name preprocessed.cc -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=/usr/local/google/home/kadircet/repos/tmp/clangd_crashes/68c6c10f-0000-2aaf-8985-3c286d3cf65a/0 -fcoverage-compilation-dir=/usr/local/google/home/kadircet/repos/tmp/clangd_crashes/68c6c10f-0000-2aaf-8985-3c286d3cf65a/0 -resource-dir /usr/local/google/home/kadircet/repos/llvm/build/lib/clang/20 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/local/google/home/kadircet/repos/llvm/build/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -Wno-everything -std=c++20 -fdeprecated-macro -ferror-limit 19 -fgnuc-version=4.2.1 -fno-implicit-modules -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/preprocessed-1b3d70.o -x c++ preprocessed.cc 1. preprocessed.cc:7:18: current parser token ';' #0 0x00005624ec1b76e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:723:13 #1 0x00005624ec1b52be llvm::sys::RunSignalHandlers() /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Signals.cpp:106:18 #2 0x00005624ec1b7d98 SignalHandler(int) /usr/local/google/home/kadircet/repos/llvm/llvm/lib/Support/Unix/Signals.inc:413:1 #3 0x00007f29f32591a0 (/lib/x86_64-linux-gnu/libc.so.6+0x3d1a0) #4 0x00007f29f32a70ec __pthread_kill_implementation ./nptl/pthread_kill.c:44:76 #5 0x00007f29f3259102 gsignal ./signal/../sysdeps/posix/raise.c:27:6 #6 0x00007f29f32424f2 abort ./stdlib/abort.c:81:7 #7 0x00007f29f3242415 _nl_load_domain ./intl/loadmsgcat.c:1177:9 #8 0x00007f29f3251d32 (/lib/x86_64-linux-gnu/libc.so.6+0x35d32) #9 0x00005624ef975993 doit /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:109:5 #10 0x00005624ef975993 doit /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:137:12 #11 0x00005624ef975993 doit /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:127:12 #12 0x00005624ef975993 isPossible /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:255:12 #13 0x00005624ef975993 isPossible /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:509:12 #14 0x00005624ef975993 isa<clang::ArrayType, clang::QualType> /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Casting.h:549:10 #15 0x00005624ef975993 isArrayType /usr/local/google/home/kadircet/repos/llvm/clang/include/clang/AST/Type.h:8076:10 #16 0x00005624ef975993 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:0:0 #17 0x00005624ef976097 clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/ExprConstant.cpp:16312:12 #18 0x00005624ef8d3fbf clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/Decl.cpp:2572:32 #19 0x00005624ef8d4117 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const /usr/local/google/home/kadircet/repos/llvm/clang/lib/AST/Decl.cpp:2640:35 #20 0x00005624eeb10f68 clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDecl.cpp:0:27 #21 0x00005624eeb0fc1f clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Sema/SemaDecl.cpp:0:3 #22 0x00005624ee8344b0 InitializerScopeRAII /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDecl.cpp:2670:11 #23 0x00005624ee8344b0 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDecl.cpp:2842:26 #24 0x00005624ee831ac0 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseDecl.cpp:2523:7 #25 0x00005624ee7ba579 clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:0:10 #26 0x00005624ee7b9d92 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:1266:12 #27 0x00005624ee7b8b79 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:0:14 #28 0x00005624ee7b6bba clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/Parser.cpp:758:10 #29 0x00005624ee7b210e clang::ParseAST(clang::Sema&, bool, bool) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Parse/ParseAST.cpp:170:5 #30 0x00005624ece66a3f clang::FrontendAction::Execute() /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/FrontendAction.cpp:1082:10 #31 0x00005624ecdd1a9d getPtr /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Error.h:279:42 #32 0x00005624ecdd1a9d operator bool /usr/local/google/home/kadircet/repos/llvm/llvm/include/llvm/Support/Error.h:242:16 #33 0x00005624ecdd1a9d clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) /usr/local/google/home/kadircet/repos/llvm/clang/lib/Frontend/CompilerInstance.cpp:1061:23 #34 0x00005624ecf4ebfe clang::ExecuteCompilerInvocation(clang::CompilerInstance*) /usr/local/google/home/kadircet/repos/llvm/clang/lib/FrontendTool/ExecuteCompilerInvocation.cpp:280:25 #35 0x00005624e9a4ae2b cc1_main(llvm::ArrayRef<char const*>, char const*, void*) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/cc1_main.cpp:285:15 #36 0x00005624e9a4750d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:215:12 #37 0x00005624e9a462b8 clang_main(int, char**, llvm::ToolContext const&) /usr/local/google/home/kadircet/repos/llvm/clang/tools/driver/driver.cpp:256:12 #38 0x00005624e9a57c67 main /usr/local/google/home/kadircet/repos/llvm/build/tools/clang/tools/driver/clang-driver.cpp:17:10 #39 0x00007f29f3243b8a __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3 #40 0x00007f29f3243c45 call_init ./csu/../csu/libc-start.c:128:20 #41 0x00007f29f3243c45 __libc_start_main ./csu/../csu/libc-start.c:347:5 #42 0x00005624e9a44e61 _start (/usr/local/google/home/kadircet/repos/llvm/build/bin/clang-20+0x56c0e61) clang: error: unable to execute command: Aborted clang: error: clang frontend command failed due to signal (use -v to see invocation) clang version 20.0.0git (git@github.com:kadircet/llvm-project.git 48b7a2c9ebbb5d8ea6be53ef034d2e67558ef97c) Target: x86_64-unknown-linux-gnu Thread model: posix InstalledDir: /usr/local/google/home/kadircet/repos/llvm/build/bin Build config: +assertions 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/preprocessed-ca391b.cpp clang: note: diagnostic msg: /tmp/preprocessed-ca391b.sh clang: note: diagnostic msg: ******************** ```
shafik commented 2 months ago

Looks like a clang-18 regression since this does not crash on clang-17: https://godbolt.org/z/4MfKj1G7n

Assertion:

clang++: /root/llvm-project/clang/include/clang/AST/Type.h:957:
const clang::ExtQualsTypeCommonBase* clang::QualType::getCommonPtr() const:
Assertion `!isNull() && "Cannot retrieve a NULL type pointer"' failed.

Backtrace:

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 -std=c++23 <source>
1.  <source>:7:18: current parser token ';'
 #0 0x0000000003ade538 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3ade538)
 #1 0x0000000003adc22c llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3adc22c)
 #2 0x0000000003a25208 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x000072aa28842520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x000072aa288969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x000072aa28842476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x000072aa288287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x000072aa2882871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x000072aa28839e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x00000000078d6178 EvaluateInPlace(clang::APValue&, (anonymous namespace)::EvalInfo&, (anonymous namespace)::LValue const&, clang::Expr const*, bool) ExprConstant.cpp:0:0
#10 0x00000000079125b3 clang::Expr::EvaluateAsInitializer(clang::APValue&, clang::ASTContext const&, clang::VarDecl const*, llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79125b3)
#11 0x00000000077e7082 clang::VarDecl::evaluateValueImpl(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x77e7082)
#12 0x00000000077e73d1 clang::VarDecl::checkForConstantInitialization(llvm::SmallVectorImpl<std::pair<clang::SourceLocation, clang::PartialDiagnostic>>&) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x77e73d1)
#13 0x000000000689940e clang::Sema::CheckCompleteVariableDeclaration(clang::VarDecl*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x689940e)
#14 0x000000000689fdba clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x689fdba)
#15 0x0000000006530609 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6530609)
#16 0x000000000653eeea clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::Parser::ParsedTemplateInfo&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x653eeea)
#17 0x00000000064fe5ee clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64fe5ee)
#18 0x00000000064fed9e clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64fed9e)
#19 0x0000000006505417 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6505417)
#20 0x00000000065062ed clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x65062ed)
#21 0x00000000064f978a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x64f978a)
#22 0x00000000043f3508 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43f3508)
#23 0x000000000467fe69 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x467fe69)
#24 0x000000000460439e clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x460439e)
#25 0x000000000476929e clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x476929e)
#26 0x0000000000c927ef cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc927ef)
#27 0x0000000000c8ba3a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#28 0x0000000004436b79 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
#29 0x0000000003a256b4 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x3a256b4)
#30 0x000000000443716f 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
#31 0x00000000043fcd05 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43fcd05)
#32 0x00000000043fd76d 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+++0x43fd76d)
#33 0x0000000004405385 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4405385)
#34 0x0000000000c8fbe5 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc8fbe5)
#35 0x0000000000b634c4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xb634c4)
#36 0x000072aa28829d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#37 0x000072aa28829e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#38 0x0000000000c8b4ee _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc8b4ee)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
ammar2199 commented 2 months ago

I've never worked on clang's frontend, but I'm happy to take a look and try to fix the crash if it's open. :)

shafik commented 2 months ago

I've never worked on clang's frontend, but I'm happy to take a look and try to fix the crash if it's open. :)

Since this looks like a regression, a git bisect: https://llvm.org/docs/GitBisecting.html

probably makes the most sense, if we can narrow it down to a commit then usually we can tag in the author of the commit to help debug the problem.

ammar2199 commented 2 months ago

@shafik I've bisected to the following commit: 20a05677f9394d4bc9467fe7bc93a4ebd3aeda61

The commit seems to have fixed a previous issue, the discussion is right here: 71015

The issue seems a bit hairy. Also tagging @Fznamznon