llvm-project
llvm-project copied to clipboard
[LifetimeSafety] -Wlifetime-safety-suggestions dumps on parenthesised function name and trailing reference return type
The following code dumps on Clang23 and up:
struct S
{
// OK
//auto operator++() & -> S&
//S& (operator++)() &
// Crash
auto (operator++)() & -> S&
{
return *this;
}
};
Compile with clang++-23 -Wlifetime-safety-suggestions. It works fine without the warning flag, with different formatting or with the requested [[clang::lifetimebound]] attributed already declared.
See also https://godbolt.org/z/dKhbKKbeb
Dump:
0. Program arguments: /opt/compiler-explorer/clang-23.1.0/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-15.2.0 -fcolor-diagnostics -fno-crash-diagnostics -Wlifetime-safety-suggestions <source>
1. <eof> parser at end of file
2. <source>:1:1: parsing struct/union/class body 'S'
3. <source>:8:5: parsing function body 'S::operator++'
#0 0x0000000003c063a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x3c063a8)
#1 0x0000000003c03cec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x3c03cec)
#2 0x0000000003b479d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007b4c1ee45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#4 0x0000000006eb32b1 clang::lifetimes::LifetimeSafetySemaHelperImpl::getLifetimeBoundFixIt[abi:cxx11](clang::CXXMethodDecl const*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6eb32b1)
#5 0x0000000006eb92d8 clang::lifetimes::LifetimeSafetySemaHelperImpl::suggestLifetimeboundToImplicitThis(clang::lifetimes::WarningScope, clang::CXXMethodDecl const*, clang::Expr const*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6eb92d8)
#6 0x0000000006ff2ef7 clang::lifetimes::internal::runLifetimeChecker(clang::lifetimes::internal::LoanPropagationAnalysis const&, clang::lifetimes::internal::MovedLoansAnalysis const&, clang::lifetimes::internal::LiveOriginsAnalysis const&, clang::lifetimes::internal::FactManager&, clang::AnalysisDeclContext&, clang::lifetimes::LifetimeSafetySemaHelper*, clang::lifetimes::LifetimeSafetyOpts const&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6ff2ef7)
#7 0x0000000006f803da clang::lifetimes::internal::LifetimeSafetyAnalysis::run() (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6f803da)
#8 0x0000000006f808b8 clang::lifetimes::runLifetimeSafetyAnalysis(clang::AnalysisDeclContext&, clang::lifetimes::LifetimeSafetySemaHelper*, clang::lifetimes::LifetimeSafetyOpts const&, clang::lifetimes::LifetimeSafetyStats&, bool) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6f808b8)
#9 0x0000000006ec67e0 clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy, clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::QualType) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6ec67e0)
#10 0x00000000063ab51a clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy const*, clang::Decl*, clang::QualType) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x63ab51a)
#11 0x0000000006608e2e clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool, bool) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6608e2e)
#12 0x000000000631ae04 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x631ae04)
#13 0x000000000621b2ca clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x621b2ca)
#14 0x000000000621a37d clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x621a37d)
#15 0x00000000062741d0 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x62741d0)
#16 0x000000000627607a clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x627607a)
#17 0x00000000062405f1 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x62405f1)
#18 0x00000000061f7f8b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x61f7f8b)
#19 0x00000000061f8a2f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x61f8a2f)
#20 0x00000000062040ef clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x62040ef)
#21 0x0000000006205057 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6205057)
#22 0x00000000062053c0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x62053c0)
#23 0x00000000061de6f3 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x61de6f3)
#24 0x00000000045dd405 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x45dd405)
#25 0x00000000049113e1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x49113e1)
#26 0x00000000048a2965 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x48a2965)
#27 0x00000000049e612b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x49e612b)
#28 0x0000000000debce8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xdebce8)
#29 0x0000000000de3b7b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#30 0x0000000000de3c1d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#31 0x0000000004658a19 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
#32 0x0000000003b47d93 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x3b47d93)
#33 0x000000000465945d 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
#34 0x00000000046144a2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x46144a2)
#35 0x0000000004618755 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x4618755)
#36 0x00000000046235dc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x46235dc)
#37 0x0000000000de86a1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xde86a1)
#38 0x0000000000d0d14a main (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xd0d14a)
#39 0x00007b4c1ee2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#40 0x00007b4c1ee2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#41 0x0000000000de3625 _start (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xde3625)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGSEGV (11)
Compiler returned: 139
@llvm/issue-subscribers-clang-temporal-safety
Author: Kai Müller (kaimfrai)
The following code dumps on Clang23 and up:
```
struct S
{
// OK
//auto operator++() & -> S&
//S& (operator++)() &
// Crash
auto (operator++)() & -> S&
{
return *this;
}
};
```
Compile with `clang++-23 -Wlifetime-safety-suggestions`. It works fine without the warning flag, with different formatting or with the requested `[[clang::lifetimebound]]` attributed already declared.
See also https://godbolt.org/z/dKhbKKbeb
Dump:
0. Program arguments: /opt/compiler-explorer/clang-23.1.0/bin/clang++ -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-15.2.0 -fcolor-diagnostics -fno-crash-diagnostics -Wlifetime-safety-suggestions <source>
1. <eof> parser at end of file
2. <source>:1:1: parsing struct/union/class body 'S'
3. <source>:8:5: parsing function body 'S::operator++'
#<!-- -->0 0x0000000003c063a8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x3c063a8)
#<!-- -->1 0x0000000003c03cec llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x3c03cec)
#<!-- -->2 0x0000000003b479d8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#<!-- -->3 0x00007b4c1ee45330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#<!-- -->4 0x0000000006eb32b1 clang::lifetimes::LifetimeSafetySemaHelperImpl::getLifetimeBoundFixIt[abi:cxx11](clang::CXXMethodDecl const*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6eb32b1)
#<!-- -->5 0x0000000006eb92d8 clang::lifetimes::LifetimeSafetySemaHelperImpl::suggestLifetimeboundToImplicitThis(clang::lifetimes::WarningScope, clang::CXXMethodDecl const*, clang::Expr const*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6eb92d8)
#<!-- -->6 0x0000000006ff2ef7 clang::lifetimes::internal::runLifetimeChecker(clang::lifetimes::internal::LoanPropagationAnalysis const&, clang::lifetimes::internal::MovedLoansAnalysis const&, clang::lifetimes::internal::LiveOriginsAnalysis const&, clang::lifetimes::internal::FactManager&, clang::AnalysisDeclContext&, clang::lifetimes::LifetimeSafetySemaHelper*, clang::lifetimes::LifetimeSafetyOpts const&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6ff2ef7)
#<!-- -->7 0x0000000006f803da clang::lifetimes::internal::LifetimeSafetyAnalysis::run() (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6f803da)
#<!-- -->8 0x0000000006f808b8 clang::lifetimes::runLifetimeSafetyAnalysis(clang::AnalysisDeclContext&, clang::lifetimes::LifetimeSafetySemaHelper*, clang::lifetimes::LifetimeSafetyOpts const&, clang::lifetimes::LifetimeSafetyStats&, bool) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6f808b8)
#<!-- -->9 0x0000000006ec67e0 clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy, clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::QualType) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6ec67e0)
#<!-- -->10 0x00000000063ab51a clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy const*, clang::Decl*, clang::QualType) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x63ab51a)
#<!-- -->11 0x0000000006608e2e clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool, bool) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6608e2e)
#<!-- -->12 0x000000000631ae04 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x631ae04)
#<!-- -->13 0x000000000621b2ca clang::Parser::ParseLexedMethodDef(clang::Parser::LexedMethod&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x621b2ca)
#<!-- -->14 0x000000000621a37d clang::Parser::ParseLexedMethodDefs(clang::Parser::ParsingClass&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x621a37d)
#<!-- -->15 0x00000000062741d0 clang::Parser::ParseCXXMemberSpecification(clang::SourceLocation, clang::SourceLocation, clang::ParsedAttributes&, unsigned int, clang::Decl*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x62741d0)
#<!-- -->16 0x000000000627607a clang::Parser::ParseClassSpecifier(clang::tok::TokenKind, clang::SourceLocation, clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, bool, clang::Parser::DeclSpecContext, clang::ParsedAttributes&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x627607a)
#<!-- -->17 0x00000000062405f1 clang::Parser::ParseDeclarationSpecifiers(clang::DeclSpec&, clang::Parser::ParsedTemplateInfo&, clang::AccessSpecifier, clang::Parser::DeclSpecContext, clang::LateParsedAttrList*, clang::ImplicitTypenameContext) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x62405f1)
#<!-- -->18 0x00000000061f7f8b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x61f7f8b)
#<!-- -->19 0x00000000061f8a2f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x61f8a2f)
#<!-- -->20 0x00000000062040ef clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x62040ef)
#<!-- -->21 0x0000000006205057 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x6205057)
#<!-- -->22 0x00000000062053c0 clang::Parser::ParseFirstTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x62053c0)
#<!-- -->23 0x00000000061de6f3 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x61de6f3)
#<!-- -->24 0x00000000045dd405 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x45dd405)
#<!-- -->25 0x00000000049113e1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x49113e1)
#<!-- -->26 0x00000000048a2965 clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x48a2965)
#<!-- -->27 0x00000000049e612b clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x49e612b)
#<!-- -->28 0x0000000000debce8 cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xdebce8)
#<!-- -->29 0x0000000000de3b7b ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#<!-- -->30 0x0000000000de3c1d int llvm::function_ref<int (llvm::SmallVectorImpl<char const*>&)>::callback_fn<clang_main(int, char**, llvm::ToolContext const&)::'lambda'(llvm::SmallVectorImpl<char const*>&)>(long, llvm::SmallVectorImpl<char const*>&) driver.cpp:0:0
#<!-- -->31 0x0000000004658a19 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
#<!-- -->32 0x0000000003b47d93 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x3b47d93)
#<!-- -->33 0x000000000465945d 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
#<!-- -->34 0x00000000046144a2 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x46144a2)
#<!-- -->35 0x0000000004618755 clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x4618755)
#<!-- -->36 0x00000000046235dc clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0x46235dc)
#<!-- -->37 0x0000000000de86a1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xde86a1)
#<!-- -->38 0x0000000000d0d14a main (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xd0d14a)
#<!-- -->39 0x00007b4c1ee2a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#<!-- -->40 0x00007b4c1ee2a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#<!-- -->41 0x0000000000de3625 _start (/opt/compiler-explorer/clang-23.1.0/bin/clang+++0xde3625)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Program terminated with signal SIGSEGV (11)
Compiler returned: 139