Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clang++18 segfaults on templated code using noexcept #92133

Closed
Ecordonnier opened this issue May 14, 2024 · 9 comments
Closed

clang++18 segfaults on templated code using noexcept #92133

Ecordonnier opened this issue May 14, 2024 · 9 comments
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] needs-reduction Large reproducer that should be reduced into a simpler form

Comments

@Ecordonnier
Copy link

Ecordonnier commented May 14, 2024

Hello, clang++18.1.6 is segfaulting on my Ubuntu 23.10 machine while attempting to compile this code. I originally reproduced with meta-clang on clang versions 18.1.4 and 18.1.5.

The code compiles fine with clang++17.0.2 (from the Ubuntu 23.10 package).
The zip file attached contains the c++ code involved reduced to a minimal example, as well as the clang segfault call-stack, and the files /tmp/test-XXXX.cpp and tmp/test-XXXX.sh which the clang logs requested to include with the bug report.

clang-bug-report.zip

Clang logs after segfault:

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/lib/llvm-18/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -dumpdir test- -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 -debugger-tuning=gdb -fdebug-compilation-dir=/home/ecordonnier/dev/clang-bug-report -fcoverage-compilation-dir=/home/ecordonnier/dev/clang-bug-report -resource-dir /usr/lib/llvm-18/lib/clang/18 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../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 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-b20392.o -x c++ ./test.cpp
1.	<eof> parser at end of file
2.	./test.cpp:23:5: instantiating function definition 'StaticIndestructible<std::shared_ptr<CallbackLogger>>::StaticIndestructible<std::shared_ptr<CallbackLogger>>'
3.	./test.cpp:14:5: instantiating function definition 'UndestructedNoexceptStorage<std::shared_ptr<CallbackLogger>>::UndestructedNoexceptStorage<std::shared_ptr<CallbackLogger>>'
 #0 0x000071dd17fa0ffa llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xda0ffa)
 #1 0x000071dd17f9f024 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xd9f024)
 #2 0x000071dd17fa16bb (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xda16bb)
 #3 0x000071dd16a42990 (/lib/x86_64-linux-gnu/libc.so.6+0x42990)
 #4 0x000071dd205a5a7e clang::Sema::CheckParameterPacksForExpansion(clang::SourceLocation, clang::SourceRange, llvm::ArrayRef<std::pair<llvm::PointerUnion<clang::TemplateTypeParmType const*, clang::NamedDecl*>, clang::SourceLocation>>, clang::MultiLevelTemplateArgumentList const&, bool&, bool&, std::optional<unsigned int>&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1ba5a7e)
 #5 0x000071dd20539f9a (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b39f9a)
 #6 0x000071dd20544a54 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b44a54)
 #7 0x000071dd205459ae (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b459ae)
 #8 0x000071dd2053bbe2 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b3bbe2)
 #9 0x000071dd20533ec2 clang::Sema::SubstExceptionSpec(clang::SourceLocation, clang::FunctionProtoType::ExceptionSpecInfo&, llvm::SmallVectorImpl<clang::QualType>&, clang::MultiLevelTemplateArgumentList const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b33ec2)
#10 0x000071dd204d6042 clang::Sema::SubstituteExplicitTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, llvm::SmallVectorImpl<clang::QualType>&, clang::QualType*, clang::sema::TemplateDeductionInfo&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1ad6042)
#11 0x000071dd2052c657 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b2c657)
#12 0x000071dd1fdd7991 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x13d7991)
#13 0x000071dd204d9d8b clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1ad9d8b)
#14 0x000071dd203b5e29 clang::Sema::ResolveAddressOfOverloadedFunction(clang::Expr*, clang::QualType, bool, clang::DeclAccessPair&, bool*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x19b5e29)
#15 0x000071dd203c48ac (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x19c48ac)
#16 0x000071dd20398c44 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1998c44)
#17 0x000071dd20398b9e clang::Sema::TryImplicitConversion(clang::Expr*, clang::QualType, bool, clang::Sema::AllowedExplicit, bool, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1998b9e)
#18 0x000071dd2028107f clang::InitializationSequence::InitializeFrom(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x188107f)
#19 0x000071dd1ff7b52e clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x157b52e)
#20 0x000071dd20576d79 clang::Sema::InstantiateVariableInitializer(clang::VarDecl*, clang::VarDecl*, clang::MultiLevelTemplateArgumentList const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b76d79)
#21 0x000071dd2056bb4f clang::Sema::BuildVariableInstantiation(clang::VarDecl*, clang::VarDecl*, clang::MultiLevelTemplateArgumentList const&, llvm::SmallVector<clang::Sema::LateInstantiatedAttribute, 16u>*, clang::DeclContext*, clang::LocalInstantiationScope*, bool, clang::VarTemplateSpecializationDecl*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b6bb4f)
#22 0x000071dd2056b2ac clang::TemplateDeclInstantiator::VisitVarDecl(clang::VarDecl*, bool, llvm::ArrayRef<clang::BindingDecl*>*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b6b2ac)
#23 0x000071dd205a3158 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1ba3158)
#24 0x000071dd1fdd7991 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x13d7991)
#25 0x000071dd20578277 clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b78277)
#26 0x000071dd2055d39a (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b5d39a)
#27 0x000071dd20548f4d (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b48f4d)
#28 0x000071dd20538768 clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b38768)
#29 0x000071dd20579dcb clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b79dcb)
#30 0x000071dd2057c45f clang::Sema::PerformPendingInstantiations(bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b7c45f)
#31 0x000071dd20579ee6 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b79ee6)
#32 0x000071dd2057c45f clang::Sema::PerformPendingInstantiations(bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b7c45f)
#33 0x000071dd1fdd93cf clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x13d93cf)
#34 0x000071dd1fdd9a29 clang::Sema::ActOnEndOfTranslationUnit() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x13d9a29)
#35 0x000071dd1f65ab7e clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xc5ab7e)
#36 0x000071dd1f59225e clang::ParseAST(clang::Sema&, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xb9225e)
#37 0x000071dd213f2f69 clang::FrontendAction::Execute() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x29f2f69)
#38 0x000071dd2136a824 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x296a824)
#39 0x000071dd2146e8fe clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x2a6e8fe)
#40 0x0000612db3104686 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/usr/lib/llvm-18/bin/clang+0x14686)
#41 0x0000612db3101935 (/usr/lib/llvm-18/bin/clang+0x11935)
#42 0x0000612db3100ae8 clang_main(int, char**, llvm::ToolContext const&) (/usr/lib/llvm-18/bin/clang+0x10ae8)
#43 0x0000612db310e8ba main (/usr/lib/llvm-18/bin/clang+0x1e8ba)
#44 0x000071dd16a28150 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#45 0x000071dd16a28209 call_init ./csu/../csu/libc-start.c:128:20
#46 0x000071dd16a28209 __libc_start_main ./csu/../csu/libc-start.c:347:5
#47 0x0000612db30fe295 _start (/usr/lib/llvm-18/bin/clang+0xe295)
clang++-18: error: unable to execute command: Segmentation fault (core dumped)
clang++-18: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 18.1.6 (++20240514123319+c5b3fa491f00-1~exp1~20240514003331.134)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang++-18: note: diagnostic msg: 
********************

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

********************
@github-actions github-actions bot added the clang Clang issues not falling into any other category label May 14, 2024
@EugeneZelenko EugeneZelenko added clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] and removed clang Clang issues not falling into any other category labels May 14, 2024
@llvmbot
Copy link
Collaborator

llvmbot commented May 14, 2024

@llvm/issue-subscribers-clang-frontend

Author: Etienne (Ecordonnier)

Hello, clang++18.1.6 is segfaulting on my Ubuntu 23.10 machine while attempting to compile this code. I originally reproduced with meta-clang on clang versions 18.1.4 and 18.1.5.

The code compiles fine with clang++17.0.2 (from the Ubuntu 23.10 package).
The zip file attached contains the c++ code involved reduced to a minimal example, as well as the clang segfault call-stack, and the files /tmp/test-0de7e8.cpp and tmp/test-0de7e8.sh which the clang logs requested to include with the bug report.

clang-bug-report.zip

Clang logs after segfault:

~/clang-bug-report$ ./build.sh 
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/lib/llvm-18/bin/clang -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -dumpdir test- -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 -debugger-tuning=gdb -fdebug-compilation-dir=/home/ecordonnier/dev/clang-bug-report -fcoverage-compilation-dir=/home/ecordonnier/dev/clang-bug-report -resource-dir /usr/lib/llvm-18/lib/clang/18 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/x86_64-linux-gnu/c++/13 -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../include/c++/13/backward -internal-isystem /usr/lib/llvm-18/lib/clang/18/include -internal-isystem /usr/local/include -internal-isystem /usr/bin/../lib/gcc/x86_64-linux-gnu/13/../../../../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 -fskip-odr-check-in-gmf -fcxx-exceptions -fexceptions -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/test-f43d6f.o -x c++ ./test.cpp
1.	&lt;eof&gt; parser at end of file
2.	./test.cpp:23:5: instantiating function definition 'StaticIndestructible&lt;std::shared_ptr&lt;CallbackLogger&gt;&gt;::StaticIndestructible&lt;std::shared_ptr&lt;CallbackLogger&gt;&gt;'
3.	./test.cpp:14:5: instantiating function definition 'UndestructedNoexceptStorage&lt;std::shared_ptr&lt;CallbackLogger&gt;&gt;::UndestructedNoexceptStorage&lt;std::shared_ptr&lt;CallbackLogger&gt;&gt;'
 #<!-- -->0 0x00007fcd88da0ffa llvm::sys::PrintStackTrace(llvm::raw_ostream&amp;, int) (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xda0ffa)
 #<!-- -->1 0x00007fcd88d9f024 llvm::sys::RunSignalHandlers() (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xd9f024)
 #<!-- -->2 0x00007fcd88da16bb (/usr/lib/llvm-18/bin/../lib/libLLVM.so.18.1+0xda16bb)
 #<!-- -->3 0x00007fcd87842990 (/lib/x86_64-linux-gnu/libc.so.6+0x42990)
 #<!-- -->4 0x00007fcd913a5a7e clang::Sema::CheckParameterPacksForExpansion(clang::SourceLocation, clang::SourceRange, llvm::ArrayRef&lt;std::pair&lt;llvm::PointerUnion&lt;clang::TemplateTypeParmType const*, clang::NamedDecl*&gt;, clang::SourceLocation&gt;&gt;, clang::MultiLevelTemplateArgumentList const&amp;, bool&amp;, bool&amp;, std::optional&lt;unsigned int&gt;&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1ba5a7e)
 #<!-- -->5 0x00007fcd91339f9a (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b39f9a)
 #<!-- -->6 0x00007fcd91344a54 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b44a54)
 #<!-- -->7 0x00007fcd9133bbe2 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b3bbe2)
 #<!-- -->8 0x00007fcd91333ec2 clang::Sema::SubstExceptionSpec(clang::SourceLocation, clang::FunctionProtoType::ExceptionSpecInfo&amp;, llvm::SmallVectorImpl&lt;clang::QualType&gt;&amp;, clang::MultiLevelTemplateArgumentList const&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b33ec2)
 #<!-- -->9 0x00007fcd912d6042 clang::Sema::SubstituteExplicitTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo&amp;, llvm::SmallVectorImpl&lt;clang::DeducedTemplateArgument&gt;&amp;, llvm::SmallVectorImpl&lt;clang::QualType&gt;&amp;, clang::QualType*, clang::sema::TemplateDeductionInfo&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1ad6042)
#<!-- -->10 0x00007fcd9132c657 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b2c657)
#<!-- -->11 0x00007fcd90bd7991 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref&lt;void ()&gt;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x13d7991)
#<!-- -->12 0x00007fcd912d9d8b clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::FunctionDecl*&amp;, clang::sema::TemplateDeductionInfo&amp;, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1ad9d8b)
#<!-- -->13 0x00007fcd911b5e29 clang::Sema::ResolveAddressOfOverloadedFunction(clang::Expr*, clang::QualType, bool, clang::DeclAccessPair&amp;, bool*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x19b5e29)
#<!-- -->14 0x00007fcd911c48ac (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x19c48ac)
#<!-- -->15 0x00007fcd91198c44 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1998c44)
#<!-- -->16 0x00007fcd91198b9e clang::Sema::TryImplicitConversion(clang::Expr*, clang::QualType, bool, clang::Sema::AllowedExplicit, bool, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1998b9e)
#<!-- -->17 0x00007fcd9108107f clang::InitializationSequence::InitializeFrom(clang::Sema&amp;, clang::InitializedEntity const&amp;, clang::InitializationKind const&amp;, llvm::MutableArrayRef&lt;clang::Expr*&gt;, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x188107f)
#<!-- -->18 0x00007fcd90d7b52e clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x157b52e)
#<!-- -->19 0x00007fcd91376d79 clang::Sema::InstantiateVariableInitializer(clang::VarDecl*, clang::VarDecl*, clang::MultiLevelTemplateArgumentList const&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b76d79)
#<!-- -->20 0x00007fcd9136bb4f clang::Sema::BuildVariableInstantiation(clang::VarDecl*, clang::VarDecl*, clang::MultiLevelTemplateArgumentList const&amp;, llvm::SmallVector&lt;clang::Sema::LateInstantiatedAttribute, 16u&gt;*, clang::DeclContext*, clang::LocalInstantiationScope*, bool, clang::VarTemplateSpecializationDecl*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b6bb4f)
#<!-- -->21 0x00007fcd9136b2ac clang::TemplateDeclInstantiator::VisitVarDecl(clang::VarDecl*, bool, llvm::ArrayRef&lt;clang::BindingDecl*&gt;*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b6b2ac)
#<!-- -->22 0x00007fcd913a3158 (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1ba3158)
#<!-- -->23 0x00007fcd90bd7991 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref&lt;void ()&gt;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x13d7991)
#<!-- -->24 0x00007fcd91378277 clang::Sema::SubstDecl(clang::Decl*, clang::DeclContext*, clang::MultiLevelTemplateArgumentList const&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b78277)
#<!-- -->25 0x00007fcd9135d39a (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b5d39a)
#<!-- -->26 0x00007fcd91348f4d (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b48f4d)
#<!-- -->27 0x00007fcd91338768 clang::Sema::SubstStmt(clang::Stmt*, clang::MultiLevelTemplateArgumentList const&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b38768)
#<!-- -->28 0x00007fcd91379dcb clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b79dcb)
#<!-- -->29 0x00007fcd9137c45f clang::Sema::PerformPendingInstantiations(bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b7c45f)
#<!-- -->30 0x00007fcd91379ee6 clang::Sema::InstantiateFunctionDefinition(clang::SourceLocation, clang::FunctionDecl*, bool, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b79ee6)
#<!-- -->31 0x00007fcd9137c45f clang::Sema::PerformPendingInstantiations(bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x1b7c45f)
#<!-- -->32 0x00007fcd90bd93cf clang::Sema::ActOnEndOfTranslationUnitFragment(clang::Sema::TUFragmentKind) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x13d93cf)
#<!-- -->33 0x00007fcd90bd9a29 clang::Sema::ActOnEndOfTranslationUnit() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x13d9a29)
#<!-- -->34 0x00007fcd9045ab7e clang::Parser::ParseTopLevelDecl(clang::OpaquePtr&lt;clang::DeclGroupRef&gt;&amp;, clang::Sema::ModuleImportState&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xc5ab7e)
#<!-- -->35 0x00007fcd9039225e clang::ParseAST(clang::Sema&amp;, bool, bool) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0xb9225e)
#<!-- -->36 0x00007fcd921f2f69 clang::FrontendAction::Execute() (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x29f2f69)
#<!-- -->37 0x00007fcd9216a824 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&amp;) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x296a824)
#<!-- -->38 0x00007fcd9226e8fe clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/usr/lib/llvm-18/bin/../lib/libclang-cpp.so.18.1+0x2a6e8fe)
#<!-- -->39 0x00005bfc2d624686 cc1_main(llvm::ArrayRef&lt;char const*&gt;, char const*, void*) (/usr/lib/llvm-18/bin/clang+0x14686)
#<!-- -->40 0x00005bfc2d621935 (/usr/lib/llvm-18/bin/clang+0x11935)
#<!-- -->41 0x00005bfc2d620ae8 clang_main(int, char**, llvm::ToolContext const&amp;) (/usr/lib/llvm-18/bin/clang+0x10ae8)
#<!-- -->42 0x00005bfc2d62e8ba main (/usr/lib/llvm-18/bin/clang+0x1e8ba)
#<!-- -->43 0x00007fcd87828150 __libc_start_call_main ./csu/../sysdeps/nptl/libc_start_call_main.h:74:3
#<!-- -->44 0x00007fcd87828209 call_init ./csu/../csu/libc-start.c:128:20
#<!-- -->45 0x00007fcd87828209 __libc_start_main ./csu/../csu/libc-start.c:347:5
#<!-- -->46 0x00005bfc2d61e295 _start (/usr/lib/llvm-18/bin/clang+0xe295)
clang++-18: error: unable to execute command: Segmentation fault (core dumped)
clang++-18: error: clang frontend command failed due to signal (use -v to see invocation)
Ubuntu clang version 18.1.6 (++20240514123319+c5b3fa491f00-1~exp1~20240514003331.134)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
clang++-18: note: diagnostic msg: 
********************

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

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

@zyn0217 zyn0217 added the needs-reduction Large reproducer that should be reduced into a simpler form label May 14, 2024
@Ecordonnier
Copy link
Author

Ecordonnier commented May 15, 2024

Note that if I comment out the nested noexcept, it compiles:

static T* execute(Args&&... with) /*noexcept(noexcept(T(std::forward<Args>(with)...)))*/ {

Also, I tested using "llvm.sh 19" and the code compiles with this version of clang19:

Setting up llvm-19-dev (1:19~++20240514083553+f83df080a817-1~exp1~20240514203735.501)

@Ecordonnier Ecordonnier changed the title clang++18 segfaults on templated code clang++18 segfaults on templated code using noexcept May 15, 2024
@sdkrystian
Copy link
Member

Reduced to:

template<typename T>
struct A 
{
    template<typename... Ts>
    static void f(Ts... ts) noexcept(noexcept((ts, ...)));
};

void (*x)(int) = A<int>::f<int>;
clang++: /root/llvm-project/clang/lib/Sema/SemaTemplateInstantiate.cpp:4261: llvm::PointerUnion<clang::Decl*, llvm::SmallVector<clang::VarDecl*, 4>*>* clang::LocalInstantiationScope::findInstantiationOf(const clang::Decl*): Assertion `isa<LabelDecl>(D) && "declaration not instantiated in this scope"' 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-18.1.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics -std=c++17 -pedantic-errors -ferror-limit=0 -fsyntax-only <source>
1.	<source>:8:32: current parser token ';'

[omitted]

#9 0x0000000006c21e2c clang::LocalInstantiationScope::findInstantiationOf(clang::Decl const*) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x6c21e2c)
#10 0x0000000006cca939 clang::Sema::CheckParameterPacksForExpansion(clang::SourceLocation, clang::SourceRange, llvm::ArrayRef<std::pair<llvm::PointerUnion<clang::TemplateTypeParmType const*, clang::NamedDecl*>, clang::SourceLocation>>, clang::MultiLevelTemplateArgumentList const&, bool&, bool&, std::optional<unsigned int>&) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x6cca939)
#11 0x0000000006c3524b clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCXXFoldExpr(clang::CXXFoldExpr*) SemaTemplateInstantiate.cpp:0:0
#12 0x0000000006c291d9 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#13 0x0000000006c3503a clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformCXXNoexceptExpr(clang::CXXNoexceptExpr*) SemaTemplateInstantiate.cpp:0:0
#14 0x0000000006c291f7 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExpr(clang::Expr*) SemaTemplateInstantiate.cpp:0:0
#15 0x0000000006c3de68 clang::TreeTransform<(anonymous namespace)::TemplateInstantiator>::TransformExceptionSpec(clang::SourceLocation, clang::FunctionProtoType::ExceptionSpecInfo&, llvm::SmallVectorImpl<clang::QualType>&, bool&) SemaTemplateInstantiate.cpp:0:0
#16 0x0000000006c3e5be clang::Sema::SubstExceptionSpec(clang::SourceLocation, clang::FunctionProtoType::ExceptionSpecInfo&, llvm::SmallVectorImpl<clang::QualType>&, clang::MultiLevelTemplateArgumentList const&) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x6c3e5be)
#17 0x0000000006ba0dcd clang::Sema::SubstituteExplicitTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo&, llvm::SmallVectorImpl<clang::DeducedTemplateArgument>&, llvm::SmallVectorImpl<clang::QualType>&, clang::QualType*, clang::sema::TemplateDeductionInfo&) (.constprop.0) SemaTemplateDeduction.cpp:0:0
#18 0x0000000006ba1141 void llvm::function_ref<void ()>::callback_fn<clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool)::'lambda'()>(long) SemaTemplateDeduction.cpp:0:0
#19 0x0000000006251ba1 clang::Sema::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x6251ba1)
#20 0x0000000006be0729 clang::Sema::DeduceTemplateArguments(clang::FunctionTemplateDecl*, clang::TemplateArgumentListInfo*, clang::QualType, clang::FunctionDecl*&, clang::sema::TemplateDeductionInfo&, bool) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x6be0729)
#21 0x00000000069f477c clang::Sema::ResolveAddressOfOverloadedFunction(clang::Expr*, clang::QualType, bool, clang::DeclAccessPair&, bool*) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x69f477c)
#22 0x00000000069f6932 IsStandardConversion(clang::Sema&, clang::Expr*, clang::QualType, bool, clang::StandardConversionSequence&, bool, bool) SemaOverload.cpp:0:0
#23 0x0000000006a04bee TryImplicitConversion(clang::Sema&, clang::Expr*, clang::QualType, bool, clang::Sema::AllowedExplicit, bool, bool, bool, bool) SemaOverload.cpp:0:0
#24 0x0000000006a04f12 clang::Sema::TryImplicitConversion(clang::Expr*, clang::QualType, bool, clang::Sema::AllowedExplicit, bool, bool, bool) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x6a04f12)
#25 0x000000000686662e clang::InitializationSequence::InitializeFrom(clang::Sema&, clang::InitializedEntity const&, clang::InitializationKind const&, llvm::MutableArrayRef<clang::Expr*>, bool, bool) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x686662e)
#26 0x0000000006460c39 clang::Sema::AddInitializerToDecl(clang::Decl*, clang::Expr*, bool) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x6460c39)
#27 0x0000000006127c73 clang::Parser::ParseDeclarationAfterDeclaratorAndAttributes(clang::Declarator&, clang::Parser::ParsedTemplateInfo const&, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x6127c73)
#28 0x00000000061354a9 clang::Parser::ParseDeclGroup(clang::ParsingDeclSpec&, clang::DeclaratorContext, clang::ParsedAttributes&, clang::SourceLocation*, clang::Parser::ForRangeInit*) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x61354a9)
#29 0x00000000060f4adb clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x60f4adb)
#30 0x00000000060f5261 clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x60f5261)
#31 0x00000000060fc516 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x60fc516)
#32 0x00000000060fd3bd clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x60fd3bd)
#33 0x00000000060f02ea clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-18.1.0/bin/clang+++0x60f02ea)

[omitted]

This crash goes all the way back to clang 4.0 (see godbolt link), but it no longer happens on main. Since this happens when we call SubstExceptionSpec from SubstituteExplicitTemplateArguments, I believe this was fixed by #90760. I'd like to see what @erichkeane and/or @shafik think.

@erichkeane
Copy link
Collaborator

template<typename T>
struct A 
{
    template<typename... Ts>
    static void f(Ts... ts) noexcept(noexcept((ts, ...)));
};

void (*x)(int) = A<int>::f<int>;

Yeah, that definitely looks like it would fix this. That is a somewhat common crash when we are trying to lookup a decl that isn't really there (the not LabelDecl is a pretty awful assert message). So we were presumably looking for a pack/type that wasn't actually inserted into the instantiated decls stack.

But if we're skipping the pack instantiation here, this is fixed.

Does the original reproducer still crash on Trunk? I fear that perhaps we missed instantiating/substituting a pack somewhere else, but if it is just in an exception specifier, I would consider this fixed.

@sdkrystian
Copy link
Member

Does the original reproducer still crash on Trunk? I fear that perhaps we missed instantiating/substituting a pack somewhere else, but if it is just in an exception specifier, I would consider this fixed.

It does not :) (godbolt link)

@erichkeane
Copy link
Collaborator

Does the original reproducer still crash on Trunk? I fear that perhaps we missed instantiating/substituting a pack somewhere else, but if it is just in an exception specifier, I would consider this fixed.

It does not :) (godbolt link)

Thanks for checking! Yeah, i think this is fixed in trunk. I don't think it qualifies for fix in the 18 branch (though perhaps I could be convinced), but at the moment I'm happy with "fixed in trunk".

@Ecordonnier
Copy link
Author

What is the criteria for not backporting vs not backporting? Is it based on the limited impact?
I don't know the project's backporting policy, however from end-user's point of view this is a regression between clang++17 and clang++18, since clang++17 (without assertions) was able to compile this code and clang++18 crashes.

@erichkeane
Copy link
Collaborator

What is the criteria for not backporting vs not backporting? Is it based on the limited impact? I don't know the project's backporting policy, however from end-user's point of view this is a regression between clang++17 and clang++18, since clang++17 (without assertions) was able to compile this code and clang++18 crashes.

Effectively, this comes down to codeowner opinion. We have to balance the impact of the bug/regression (which seems fairly limited here), the size/impact of the actual patch (which in this case, is pretty sizable impact wise), and amount of releases after this (this would at best get to 18.1.6, which is an 'if necessary' only patch), plus time to next release branch (which is roughly in ~2 months).

So from my perspective, we have:
-Impact of the regression: Limited
-Impact of patch: Sizable
-Remaining releases to 'fix' this: None (this would be the last 18.x branch)
-Time to next release branch: Likely early July, so right on 2 months.

So I have 3 against, and 1 'middling'. I could perhaps squint on the impact, and have it be 2 against, 2 'middling', but even then I'd have a hard time judging this.

So unless we (soon, as our last release date for 18 is on the 26th) have an outpouring of support from some large projects, I don't see this as being able to be cherry-picked to the release branch.

@cor3ntin
Copy link
Contributor

@erichkeane My understanding is that the deadline to backport is... today. this is another good reason not to.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" crash Prefer [crash-on-valid] or [crash-on-invalid] needs-reduction Large reproducer that should be reduced into a simpler form
Projects
None yet
Development

No branches or pull requests

7 participants