Issue 176395
Summary [Clang] Assertion `!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!"` failed with `-O2` flag.
Labels clang
Assignees
Reporter Xniao
    ***Generated by fuzzer.***
Clang trunk crashed on following valid code and goes back to 19.1 with `-O2` flag.
Compiler Explorer: https://godbolt.org/z/erasnohnP

## Program
```cpp
struct E {
 ~E();
};
E::~E() {
  struct {
    int anotherValue = [] { return 2; }();
  } obj;
}
```

## Stack Dump
```bash
clang++: /root/llvm-project/llvm/tools/clang/include/clang/AST/GlobalDecl.h:63: void clang::GlobalDecl::Init(const clang::Decl*): Assertion `!isa<CXXDestructorDecl>(D) && "Use other ctor with dtor decls!"' 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-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 -O2 <source>
1.	<eof> parser at end of file
2.	Per-file LLVM IR generation
3.	<source>:5:3: Generating code for declaration 'E::~E()::(unnamed struct)::(unnamed struct at <source>:5:3)'
 #0 0x000000000430a6b8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x430a6b8)
 #1 0x0000000004307b14 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4307b14)
 #2 0x0000000004249de8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
 #3 0x00007a1144e42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #4 0x00007a1144e969fc pthread_kill (/lib/x86_64-linux-gnu/libc.so.6+0x969fc)
 #5 0x00007a1144e42476 gsignal (/lib/x86_64-linux-gnu/libc.so.6+0x42476)
 #6 0x00007a1144e287f3 abort (/lib/x86_64-linux-gnu/libc.so.6+0x287f3)
 #7 0x00007a1144e2871b (/lib/x86_64-linux-gnu/libc.so.6+0x2871b)
 #8 0x00007a1144e39e96 (/lib/x86_64-linux-gnu/libc.so.6+0x39e96)
 #9 0x000000000464c948 clang::GlobalDecl::Init(clang::Decl const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x464c948)
#10 0x000000000802fb2b (anonymous namespace)::CXXNameMangler::manglePrefix(clang::DeclContext const*, bool) ItaniumMangle.cpp:0:0
#11 0x000000000802fcad (anonymous namespace)::CXXNameMangler::manglePrefix(clang::DeclContext const*, bool) ItaniumMangle.cpp:0:0
#12 0x0000000008049595 (anonymous namespace)::CXXNameMangler::mangleClosurePrefix(clang::NamedDecl const*, bool) ItaniumMangle.cpp:0:0
#13 0x0000000008030e85 (anonymous namespace)::CXXNameMangler::mangleNameWithAbiTags(clang::GlobalDecl, llvm::SmallVector<llvm::StringRef, 4u> const*) ItaniumMangle.cpp:0:0
#14 0x0000000008031bd7 (anonymous namespace)::CXXNameMangler::mangleName(clang::GlobalDecl) ItaniumMangle.cpp:0:0
#15 0x00000000080334ba (anonymous namespace)::CXXNameMangler::mangleType(clang::QualType) ItaniumMangle.cpp:0:0
#16 0x000000000803ba9b (anonymous namespace)::ItaniumMangleContextImpl::mangleCXXRTTIName(clang::QualType, llvm::raw_ostream&, bool) ItaniumMangle.cpp:0:0
#17 0x000000000494c6d8 clang::CodeGen::CodeGenTBAA::getBaseTypeInfoHelper(clang::Type const*) (.part.0) CodeGenTBAA.cpp:0:0
#18 0x000000000494d986 clang::CodeGen::CodeGenTBAA::getValidBaseTypeInfo(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x494d986)
#19 0x000000000494e2bb clang::CodeGen::CodeGenTBAA::getTypeInfo(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x494e2bb)
#20 0x000000000495025a clang::CodeGen::CodeGenTBAA::getAccessInfo(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x495025a)
#21 0x00000000048aeced clang::CodeGen::CodeGenModule::getTBAAAccessInfo(clang::QualType) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48aeced)
#22 0x000000000464d4b8 clang::CodeGen::CodeGenFunction::MakeAddrLValue(clang::CodeGen::Address, clang::QualType, clang::CodeGen::AlignmentSource) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x464d4b8)
#23 0x0000000004691c56 (anonymous namespace)::AggExprEmitter::VisitLambdaExpr(clang::LambdaExpr*) CGExprAgg.cpp:0:0
#24 0x00000000046998ed (anonymous namespace)::AggExprEmitter::Visit(clang::Expr*) CGExprAgg.cpp:0:0
#25 0x000000000469a17e clang::CodeGen::CodeGenFunction::EmitAggExpr(clang::Expr const*, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x469a17e)
#26 0x00000000046776d5 clang::CodeGen::CodeGenFunction::EmitAnyExprToMem(clang::Expr const*, clang::CodeGen::Address, clang::Qualifiers, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46776d5)
#27 0x000000000468862c clang::CodeGen::CodeGenFunction::EmitMaterializeTemporaryExpr(clang::MaterializeTemporaryExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x468862c)
#28 0x00000000046891ac clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46891ac)
#29 0x0000000004689777 void llvm::function_ref<void ()>::callback_fn<clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t)::'lambda'()>(long) CGExpr.cpp:0:0
#30 0x00000000085535d1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x85535d1)
#31 0x0000000004650fcc clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4650fcc)
#32 0x000000000466ba27 clang::CodeGen::CodeGenFunction::EmitCastLValue(clang::CastExpr const*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x466ba27)
#33 0x0000000004688c16 clang::CodeGen::CodeGenFunction::EmitLValueHelper(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4688c16)
#34 0x0000000004689777 void llvm::function_ref<void ()>::callback_fn<clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t)::'lambda'()>(long) CGExpr.cpp:0:0
#35 0x00000000085535d1 clang::StackExhaustionHandler::runWithSufficientStackSpace(clang::SourceLocation, llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x85535d1)
#36 0x0000000004650fcc clang::CodeGen::CodeGenFunction::EmitLValue(clang::Expr const*, clang::CodeGen::KnownNonNull_t) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4650fcc)
#37 0x00000000046a7082 clang::CodeGen::CodeGenFunction::EmitCXXMemberOrOperatorMemberCallExpr(clang::CallExpr const*, clang::CXXMethodDecl const*, clang::CodeGen::ReturnValueSlot, bool, clang::NestedNameSpecifier, bool, clang::Expr const*, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46a7082)
#38 0x00000000046a9048 clang::CodeGen::CodeGenFunction::EmitCXXOperatorMemberCallExpr(clang::CXXOperatorCallExpr const*, clang::CXXMethodDecl const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46a9048)
#39 0x000000000466e616 clang::CodeGen::CodeGenFunction::EmitCallExpr(clang::CallExpr const*, clang::CodeGen::ReturnValueSlot, llvm::CallBase**) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x466e616)
#40 0x00000000046f4bb4 (anonymous namespace)::ScalarExprEmitter::VisitCallExpr(clang::CallExpr const*) CGExprScalar.cpp:0:0
#41 0x00000000046e81c0 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#42 0x00000000046f8a6a (anonymous namespace)::ScalarExprEmitter::VisitExprWithCleanups(clang::ExprWithCleanups*) CGExprScalar.cpp:0:0
#43 0x00000000046e894f clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#44 0x00000000046e86bf clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#45 0x00000000046ed55c clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x46ed55c)
#46 0x0000000004bbfb69 clang::CodeGen::CodeGenFunction::EmitScalarInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bbfb69)
#47 0x0000000004bc1987 clang::CodeGen::CodeGenFunction::EmitExprAsInit(clang::Expr const*, clang::ValueDecl const*, clang::CodeGen::LValue, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4bc1987)
#48 0x0000000004b942c5 clang::CodeGen::CodeGenFunction::EmitInitializerForField(clang::FieldDecl*, clang::CodeGen::LValue, clang::Expr*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b942c5)
#49 0x0000000004b94a57 EmitMemberInitializer(clang::CodeGen::CodeGenFunction&, clang::CXXRecordDecl const*, clang::CXXCtorInitializer*, clang::CXXConstructorDecl const*, clang::CodeGen::FunctionArgList&) CGClass.cpp:0:0
#50 0x0000000004ba1601 clang::CodeGen::CodeGenFunction::EmitCtorPrologue(clang::CXXConstructorDecl const*, clang::CXXCtorType, clang::CodeGen::FunctionArgList&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ba1601)
#51 0x0000000004ba5507 clang::CodeGen::CodeGenFunction::EmitConstructorBody(clang::CodeGen::FunctionArgList&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ba5507)
#52 0x00000000048982ed clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48982ed)
#53 0x0000000004b5837f clang::CodeGen::CodeGenModule::codegenCXXStructor(clang::GlobalDecl) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4b5837f)
#54 0x000000000497c240 (anonymous namespace)::ItaniumCXXABI::emitCXXStructor(clang::GlobalDecl) ItaniumCXXABI.cpp:0:0
#55 0x00000000048ffd86 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x48ffd86)
#56 0x000000000490d40c clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x490d40c)
#57 0x000000000490d328 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x490d328)
#58 0x00000000049110a3 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x49110a3)
#59 0x0000000004c740ae (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#60 0x0000000004c71ac5 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c71ac5)
#61 0x0000000006a4ef8c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x6a4ef8c)
#62 0x0000000004c722a8 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4c722a8)
#63 0x0000000004f6bc55 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4f6bc55)
#64 0x0000000004eeb8de clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4eeb8de)
#65 0x000000000506698d clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x506698d)
#66 0x0000000000ddcf9e cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xddcf9e)
#67 0x0000000000dd396a ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&, llvm::IntrusiveRefCntPtr<llvm::vfs::FileSystem>) driver.cpp:0:0
#68 0x0000000000dd3aed 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
#69 0x0000000004ce55a9 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
#70 0x000000000424a284 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x424a284)
#71 0x0000000004ce5bbf 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
#72 0x0000000004ca6592 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4ca6592)
#73 0x0000000004ca753e 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+++0x4ca753e)
#74 0x0000000004cae985 clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0x4cae985)
#75 0x0000000000dd9311 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdd9311)
#76 0x0000000000c969c4 main (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xc969c4)
#77 0x00007a1144e29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#78 0x00007a1144e29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#79 0x0000000000dd3405 _start (/opt/compiler-explorer/clang-assertions-trunk/bin/clang+++0xdd3405)
clang++: error: clang frontend command failed with exit code 134 (use -v to see invocation)
Compiler returned: 134
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to