Skip to content

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

Closed
@Ecordonnier

Description

@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-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: 

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    clang:frontendLanguage frontend issues, e.g. anything involving "Sema"crashPrefer [crash-on-valid] or [crash-on-invalid]needs-reductionLarge reproducer that should be reduced into a simpler form

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions