<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/106898>106898</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Crash at llvm::Instruction::eraseFromParent()
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            new issue
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          yijan4845
      </td>
    </tr>
</table>

<pre>
    Compiler Explorer: [https://godbolt.org/z/5bs13Wd9j](https://godbolt.org/z/5bs13Wd9j)

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

```cpp
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)
```
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJzUWl1v2zrS_jXKDUFDoiRbusiFY8c5AXrwFidFe2lQ5EhmQ5ECSTnJ--sXFOXEcj7adL3AbpGmEj-GzzMznBlSpdaKRgFcRvlVlK8vaO922lw-iZ9UZUWWX1SaP12udNsJCQZdP3ZSGzBRukRRfrVzrrNRuozIJiKbRvNKSzfTponI5v8jsskrm6Q_ePkzytcRKX5_OCmjeB3Fy_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