| Issue |
109757
|
| Summary |
clang crashes on invalid input
|
| Labels |
clang:codegen,
crash-on-invalid
|
| Assignees |
|
| Reporter |
schenker
|
clang 19.1.0 crashes when trying to compile the following invalid program. The problem seems to exist since clang 6.
```
class C1 {
~C1();
};
template <typename T> class C2 {
public:
~C2() { delete p; }
T *p;
};
void f() { C2<C1[]>{}; }
```
Output:
```
<source>:11:12: warning: _expression_ result unused [-Wunused-value]
11 | void f() { C2<C1[]>{}; }
| ^ ~~
<source>:7:11: warning: deleting pointer to incomplete type 'C1[]' is incompatible with C++2c and may cause undefined behavior [-Wdelete-incomplete]
7 | ~C2() { delete p; }
| ^ ~
<source>:11:20: note: in instantiation of member function 'C2<C1[]>::~C2' requested here
11 | void f() { C2<C1[]>{}; }
| ^
<source>:7:11: warning: 'delete' applied to a pointer-to-array type 'C1 *[]' treated as 'delete[]'
7 | ~C2() { delete p; }
| ^ ~
| []
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-19.1.0/bin/clang++ -gdwarf-4 -g -o /app/output.s -mllvm --x86-asm-syntax=intel -fno-verbose-asm -S --gcc-toolchain=/opt/compiler-explorer/gcc-13.2.0 -fcolor-diagnostics -fno-crash-diagnostics --std=c++20 <source>
1. <eof> parser at end of file
2. Per-file LLVM IR generation
3. <source>:7:3: Generating code for declaration 'C2<C1[]>::~C2'
4. <source>:7:9: LLVM IR generation of compound statement ('{}')
#0 0x00000000036fdb08 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x36fdb08)
#1 0x00000000036fbc74 llvm::sys::CleanupOnSignal(unsigned long) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x36fbc74)
#2 0x0000000003647be8 CrashRecoverySignalHandler(int) CrashRecoveryContext.cpp:0:0
#3 0x00007b22ec442520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
#4 0x0000000006fb9726 clang::ASTContext::getUnresolvedUsingType(clang::UnresolvedUsingTypenameDecl const*) const (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x6fb9726)
#5 0x00000000071a136b clang::CXXRecordDecl::getDestructor() const (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x71a136b)
#6 0x0000000003ddcd32 clang::CodeGen::CodeGenFunction::destroyCXXObject(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3ddcd32)
#7 0x0000000003e0cba0 clang::CodeGen::CodeGenFunction::emitArrayDestroy(llvm::Value*, llvm::Value*, clang::QualType, clang::CharUnits, void (*)(clang::CodeGen::CodeGenFunction&, clang::CodeGen::Address, clang::QualType), bool, bool) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3e0cba0)
#8 0x0000000003e85207 clang::CodeGen::CodeGenFunction::EmitCXXDeleteExpr(clang::CXXDeleteExpr const*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3e85207)
#9 0x0000000003ea7add clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
#10 0x0000000003eac182 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3eac182)
#11 0x0000000003e405ce clang::CodeGen::CodeGenFunction::EmitAnyExpr(clang::Expr const*, clang::CodeGen::AggValueSlot, bool) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3e405ce)
#12 0x0000000003e5ee6d clang::CodeGen::CodeGenFunction::EmitIgnoredExpr(clang::Expr const*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3e5ee6d)
#13 0x0000000003a3a4da clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3a3a4da)
#14 0x0000000003a41059 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3a41059)
#15 0x0000000003a413f9 clang::CodeGen::CodeGenFunction::EmitCompoundStmt(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3a413f9)
#16 0x0000000003a4160e clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3a4160e)
#17 0x0000000003a3a472 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3a3a472)
#18 0x0000000003df0cdb clang::CodeGen::CodeGenFunction::EmitDestructorBody(clang::CodeGen::FunctionArgList&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3df0cdb)
#19 0x0000000003ab488d clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3ab488d)
#20 0x0000000003dab568 clang::CodeGen::CodeGenModule::codegenCXXStructor(clang::GlobalDecl) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3dab568)
#21 0x0000000003b789d2 (anonymous namespace)::ItaniumCXXABI::emitCXXStructor(clang::GlobalDecl) ItaniumCXXABI.cpp:0:0
#22 0x0000000003b09463 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3b09463)
#23 0x0000000003b141b1 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3b141b1)
#24 0x0000000003b141c9 clang::CodeGen::CodeGenModule::EmitDeferred() (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3b141c9)
#25 0x0000000003b16153 clang::CodeGen::CodeGenModule::Release() (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3b16153)
#26 0x0000000003fd013e (anonymous namespace)::CodeGeneratorImpl::HandleTranslationUnit(clang::ASTContext&) ModuleBuilder.cpp:0:0
#27 0x0000000003fcde35 clang::BackendConsumer::HandleTranslationUnit(clang::ASTContext&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3fcde35)
#28 0x0000000005f1899c clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x5f1899c)
#29 0x0000000003fce825 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3fce825)
#30 0x0000000004274201 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x4274201)
#31 0x00000000041f699b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x41f699b)
#32 0x000000000435a843 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x435a843)
#33 0x0000000000c874dc cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0xc874dc)
#34 0x0000000000c8146d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#35 0x0000000004017309 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
#36 0x0000000003648013 llvm::CrashRecoveryContext::RunSafely(llvm::function_ref<void ()>) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3648013)
#37 0x0000000004017529 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
#38 0x0000000003fdd947 clang::driver::Compilation::ExecuteCommand(clang::driver::Command const&, clang::driver::Command const*&, bool) const (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3fdd947)
#39 0x0000000003fde2fd clang::driver::Compilation::ExecuteJobs(clang::driver::JobList const&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&, bool) const (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3fde2fd)
#40 0x0000000003fe7d4c clang::driver::Driver::ExecuteCompilation(clang::driver::Compilation&, llvm::SmallVectorImpl<std::pair<int, clang::driver::Command const*>>&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0x3fe7d4c)
#41 0x0000000000c847f1 clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0xc847f1)
#42 0x0000000000b5c2d4 main (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0xb5c2d4)
#43 0x00007b22ec429d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#44 0x00007b22ec429e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#45 0x0000000000c80f0e _start (/opt/compiler-explorer/clang-19.1.0/bin/clang+++0xc80f0e)
clang++: error: clang frontend command failed with exit code 139 (use -v to see invocation)
Compiler returned: 139
```
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs