Skip to content

Crash at llvm::Instruction::eraseFromParent() #106898

@yijan4845

Description

@yijan4845

Compiler Explorer: https://godbolt.org/z/5bs13Wd9j

Clang trunk crashes when compiling the following program, while this won't happen in earlier versions:

int main () { 
    while(1);
    int a = 0, b = 1;
    __attribute__((assume (a < b)));
}

Clang stack dump:

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-trunk-20240901/bin/clang-20 -cc1 -triple x86_64-unknown-linux-gnu -emit-obj -dumpdir /app/output.s- -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name example.c -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=all -fmath-errno -ffp-contract=on -fno-rounding-math -fno-verbose-asm -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debug-info-kind=constructor -dwarf-version=4 -debugger-tuning=gdb -fdebug-compilation-dir=/app -fcoverage-compilation-dir=/app -resource-dir /opt/compiler-explorer/clang-trunk-20240901/lib/clang/20 -internal-isystem /opt/compiler-explorer/clang-trunk-20240901/lib/clang/20/include -internal-isystem /usr/local/include -internal-isystem /opt/compiler-explorer/gcc-snapshot/lib/gcc/x86_64-linux-gnu/15.0.0/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O0 -ferror-limit 19 -fgnuc-version=4.2.1 -fskip-odr-check-in-gmf -fcolor-diagnostics -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/example-50ebb7.o -x c <source>
1.	<eof> parser at end of file
2.	<source>:1:5: LLVM IR generation of declaration 'main'
3.	<source>:1:5: Generating code for declaration 'main'
 #0 0x00000000038a45e8 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x38a45e8)
 #1 0x00000000038a1f8c SignalHandler(int) Signals.cpp:0:0
 #2 0x00007a8b0fe42520 (/lib/x86_64-linux-gnu/libc.so.6+0x42520)
 #3 0x00000000031f3e3e llvm::Instruction::eraseFromParent() (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x31f3e3e)
 #4 0x0000000004093cf1 (anonymous namespace)::ScalarExprEmitter::VisitCastExpr(clang::CastExpr*) CGExprScalar.cpp:0:0
 #5 0x000000000408b682 clang::StmtVisitorBase<std::add_pointer, (anonymous namespace)::ScalarExprEmitter, llvm::Value*>::Visit(clang::Stmt*) CGExprScalar.cpp:0:0
 #6 0x00000000040901f2 clang::CodeGen::CodeGenFunction::EmitScalarExpr(clang::Expr const*, bool) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x40901f2)
 #7 0x0000000004024430 clang::CodeGen::CodeGenFunction::EvaluateExprAsBool(clang::Expr const*) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x4024430)
 #8 0x0000000003bea5d1 clang::CodeGen::CodeGenFunction::EmitAttributedStmt(clang::AttributedStmt const&) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x3bea5d1)
 #9 0x0000000003beab99 clang::CodeGen::CodeGenFunction::EmitSimpleStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x3beab99)
#10 0x0000000003be3af2 clang::CodeGen::CodeGenFunction::EmitStmt(clang::Stmt const*, llvm::ArrayRef<clang::Attr const*>) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x3be3af2)
#11 0x0000000003bea729 clang::CodeGen::CodeGenFunction::EmitCompoundStmtWithoutScope(clang::CompoundStmt const&, bool, clang::CodeGen::AggValueSlot) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x3bea729)
#12 0x0000000003c5214a clang::CodeGen::CodeGenFunction::EmitFunctionBody(clang::Stmt const*) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x3c5214a)
#13 0x0000000003c5f088 clang::CodeGen::CodeGenFunction::GenerateCode(clang::GlobalDecl, llvm::Function*, clang::CodeGen::CGFunctionInfo const&) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x3c5f088)
#14 0x0000000003cb95cb clang::CodeGen::CodeGenModule::EmitGlobalFunctionDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x3cb95cb)
#15 0x0000000003cb4de5 clang::CodeGen::CodeGenModule::EmitGlobalDefinition(clang::GlobalDecl, llvm::GlobalValue*) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x3cb4de5)
#16 0x0000000003cb5770 clang::CodeGen::CodeGenModule::EmitGlobal(clang::GlobalDecl) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x3cb5770)
#17 0x0000000003cbeef7 clang::CodeGen::CodeGenModule::EmitTopLevelDecl(clang::Decl*) (.part.0) CodeGenModule.cpp:0:0
#18 0x00000000041b6e9e (anonymous namespace)::CodeGeneratorImpl::HandleTopLevelDecl(clang::DeclGroupRef) ModuleBuilder.cpp:0:0
#19 0x00000000041a8989 clang::BackendConsumer::HandleTopLevelDecl(clang::DeclGroupRef) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x41a8989)
#20 0x0000000006177ab4 clang::ParseAST(clang::Sema&, bool, bool) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x6177ab4)
#21 0x00000000041b4cb5 clang::CodeGenAction::ExecuteAction() (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x41b4cb5)
#22 0x000000000445c5a1 clang::FrontendAction::Execute() (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x445c5a1)
#23 0x00000000043def2b clang::CompilerInstance::ExecuteAction(clang::FrontendAction&) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x43def2b)
#24 0x0000000004543ed3 clang::ExecuteCompilerInvocation(clang::CompilerInstance*) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0x4543ed3)
#25 0x0000000000cb854c cc1_main(llvm::ArrayRef<char const*>, char const*, void*) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0xcb854c)
#26 0x0000000000cb248d ExecuteCC1Tool(llvm::SmallVectorImpl<char const*>&, llvm::ToolContext const&) driver.cpp:0:0
#27 0x0000000000cb56af clang_main(int, char**, llvm::ToolContext const&) (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0xcb56af)
#28 0x0000000000b8b124 main (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0xb8b124)
#29 0x00007a8b0fe29d90 (/lib/x86_64-linux-gnu/libc.so.6+0x29d90)
#30 0x00007a8b0fe29e40 __libc_start_main (/lib/x86_64-linux-gnu/libc.so.6+0x29e40)
#31 0x0000000000cb1f2e _start (/opt/compiler-explorer/clang-trunk-20240901/bin/clang-20+0xcb1f2e)
clang: error: unable to execute command: Segmentation fault (core dumped)
clang: error: clang frontend command failed due to signal (use -v to see invocation)

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions