| Issue |
204210
|
| Summary |
[clang] Assertion failure when using `-Wlifetime-safety` and a member function template with an explicit object
|
| Labels |
clang
|
| Assignees |
|
| Reporter |
davidstone
|
The following valid translation unit
```cxx
struct s {
template<typename T>
auto f(this s && x, T) -> int {
return x.m;
}
int m;
};
auto f() -> void {
s().f(0);
}
```
when compiled with `-std=c++23 -Wlifetime-safety-dangling-field` (or several other lifetime-safety warnings) causes clang to crash with
```console
PLEASE submit a bug report to https://github.com/llvm/llvm-project/issues/ and include the crash backtrace and dumped files.
Stack dump:
0. Program arguments: /opt/compiler-explorer/clang-assertions-trunk/bin/clang++ -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 -Wlifetime-safety-dangling-field <source>
1. <eof> parser at end of file
2. <source>:10:18: parsing function body 'f'
#0 0x000000000433b378 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x433b378)
#1 0x00000000043382b4 llvm::sys::RunSignalHandlers() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43382b4)
#2 0x00000000043388d4 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x43388d4)
#3 0x0000000004275e18 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#4 0x00007ce9b7445330 (/lib/x86_64-linux-gnu/libc.so.6+0x45330)
#5 0x0000000007a1c24d clang::lifetimes::internal::FactsGenerator::handleMovedArgsInCall(clang::FunctionDecl const*, llvm::ArrayRef<clang::Expr const*>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7a1c24d)
#6 0x0000000007a1fc72 clang::lifetimes::internal::FactsGenerator::handleFunctionCall(clang::Expr const*, clang::FunctionDecl const*, llvm::ArrayRef<clang::Expr const*>, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7a1fc72)
#7 0x0000000007a22117 clang::lifetimes::internal::FactsGenerator::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x7a22117)
#8 0x00000000079a528b clang::lifetimes::internal::LifetimeSafetyAnalysis::run() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79a528b)
#9 0x00000000079a62b3 clang::lifetimes::runLifetimeSafetyAnalysis(clang::AnalysisDeclContext&, clang::lifetimes::LifetimeSafetySemaHelper*, clang::lifetimes::LifetimeSafetyStats&, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x79a62b3)
#10 0x00000000078e0283 clang::sema::AnalysisBasedWarnings::IssueWarnings(clang::sema::AnalysisBasedWarnings::Policy, clang::sema::FunctionScopeInfo*, clang::Decl const*, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x78e0283)
#11 0x0000000006d9105a clang::Sema::PopFunctionScopeInfo(clang::sema::AnalysisBasedWarnings::Policy const*, clang::Decl*, clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d9105a)
#12 0x0000000006ff1270 clang::Sema::ActOnFinishFunctionBody(clang::Decl*, clang::Stmt*, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6ff1270)
#13 0x0000000006d06df4 clang::Parser::ParseFunctionStatementBody(clang::Decl*, clang::Parser::ParseScope&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6d06df4)
#14 0x0000000006c097f3 clang::Parser::ParseFunctionDefinition(clang::ParsingDeclarator&, clang::Parser::ParsedTemplateInfo const&, clang::LateParsedAttrList*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c097f3)
#15 0x0000000006c409c3 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+++0x6c409c3)
#16 0x0000000006bfcd6b clang::Parser::ParseDeclOrFunctionDefInternal(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec&, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6bfcd6b)
#17 0x0000000006bfd56f clang::Parser::ParseDeclarationOrFunctionDefinition(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*, clang::AccessSpecifier) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6bfd56f)
#18 0x0000000006c05021 clang::Parser::ParseExternalDeclaration(clang::ParsedAttributes&, clang::ParsedAttributes&, clang::ParsingDeclSpec*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c05021)
#19 0x0000000006c05f35 clang::Parser::ParseTopLevelDecl(clang::OpaquePtr<clang::DeclGroupRef>&, clang::Sema::ModuleImportState&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6c05f35)
#20 0x0000000006be6e1a clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6be6e1a)
#21 0x0000000004e2f718 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e2f718)
#22 0x0000000005167258 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x5167258)
#23 0x00000000050e30ed clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x50e30ed)
#24 0x000000000526606d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x526606d)
#25 0x0000000000dc69bc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc69bc)
#26 0x0000000000dbd65a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#27 0x0000000000dbd7dd 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
#28 0x0000000004ea1f49 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 0x0000000004276254 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4276254)
#30 0x0000000004ea2596 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 0x0000000004e5ef32 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e5ef32)
#32 0x0000000004e5fede 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+++0x4e5fede)
#33 0x0000000004e67715 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4e67715)
#34 0x0000000000dc2ef2 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdc2ef2)
#35 0x0000000000cc2f7a main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xcc2f7a)
#36 0x00007ce9b742a1ca (/lib/x86_64-linux-gnu/libc.so.6+0x2a1ca)
#37 0x00007ce9b742a28b __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x2a28b)
#38 0x0000000000dbd005 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdbd005)
clang++: error: clang frontend command failed due to signal (use -v to see invocation)
Compiler returned: 139
```
See it live: https://godbolt.org/z/xrhPx9W1x
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs