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

    <tr>
        <th>Summary</th>
        <td>
            llc crash in cfi-instr-inserter
        </td>
    </tr>

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

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

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

<pre>
    I'm trying to run llc on some bitcode. On debian stable (bookworm) with llc version 16.0.6, the following assertion is tripped:
```
llc: /home/aeden/jove/llvm-project/llvm/include/llvm/ADT/DenseMap.h:624: bool llvm::DenseMapBase<llvm::SmallDenseMap<unsigned int, (anonymous namespace)::CFIInstrInserter::CSRSavedLocation, 16>, unsigned int, (anonymous namespace)::CFIInstrInserter::CSRSavedLocation, llvm::DenseMapInfo<unsigned int>, llvm::detail::DenseMapPair<unsigned int, (anonymous namespace)::CFIInstrInserter::CSRSavedLocation>>::LookupBucketFor(const LookupKeyT &, const BucketT *&) const [DerivedT = llvm::SmallDenseMap<unsigned int, (anonymous namespace)::CFIInstrInserter::CSRSavedLocation, 16>, KeyT = unsigned int, ValueT = (anonymous namespace)::CFIInstrInserter::CSRSavedLocation, KeyInfoT = llvm::DenseMapInfo<unsigned int>, BucketT = llvm::detail::DenseMapPair<unsigned int, (anonymous namespace)::CFIInstrInserter::CSRSavedLocation>, LookupKeyT = unsigned int]: Assertion `!KeyInfoT::isEqual(Val, EmptyKey) && !KeyInfoT::isEqual(Val, TombstoneKey) && "Empty/Tombstone value shouldn't be inserted into map!"' failed.
```

On the newest llvm in Archlinux (17.0.6), I get a crash:
```
Program received signal SIGSEGV, Segmentation fault.
0x00007ffff06ad8c9 in llvm::BitVector::set () at /usr/src/debug/llvm/llvm-17.0.6.src/include/llvm/ADT/BitVector.h:359
Downloading source file /usr/src/debug/llvm/llvm-17.0.6.src/include/llvm/ADT/BitVector.h
359      Bits[Idx / BITWORD_SIZE] |= BitWord(1) << (Idx % BITWORD_SIZE); 
(gdb) bt
#0  0x00007ffff06ad8c9 in llvm::BitVector::set () at /usr/src/debug/llvm/llvm-17.0.6.src/include/llvm/ADT/BitVector.h:359
#1 calculateOutgoingCFAInfo () at /usr/src/debug/llvm/llvm-17.0.6.src/lib/CodeGen/CFIInstrInserter.cpp:261
#2 0x00007ffff06af2d6 in updateSuccCFAInfo () at /usr/src/debug/llvm/llvm-17.0.6.src/lib/CodeGen/CFIInstrInserter.cpp:285
#3 calculateCFAInfo () at /usr/src/debug/llvm/llvm-17.0.6.src/lib/CodeGen/CFIInstrInserter.cpp:173
#4 runOnMachineFunction () at /usr/src/debug/llvm/llvm-17.0.6.src/lib/CodeGen/CFIInstrInserter.cpp:55
#5 0x00007ffff08b1ddc in llvm::MachineFunctionPass::runOnFunction () at /usr/src/debug/llvm/llvm-17.0.6.src/lib/CodeGen/MachineFunctionPass.cpp:91
#6 0x00007ffff0528943 in llvm::FPPassManager::runOnFunction () at /usr/src/debug/llvm/llvm-17.0.6.src/lib/IR/LegacyPassManager.cpp:1435
#7 0x00007ffff0528d14 in llvm::FPPassManager::runOnModule () at /usr/src/debug/llvm/llvm-17.0.6.src/lib/IR/LegacyPassManager.cpp:1481
#8 0x00007ffff052a79f in runOnModule () at /usr/src/debug/llvm/llvm-17.0.6.src/lib/IR/LegacyPassManager.cpp:1550
#9 llvm::legacy::PassManagerImpl::run () at /usr/src/debug/llvm/llvm-17.0.6.src/lib/IR/LegacyPassManager.cpp:535
#10 0x000055555556aeaa in compileModule () at /usr/src/debug/llvm/llvm-17.0.6.src/tools/llc/llc.cpp:751
#11 0x0000555555561a41 in main () at /usr/src/debug/llvm/llvm-17.0.6.src/tools/llc/llc.cpp:416
```

The attached zip file contains the original bitcode assembly that prompted this issue, and the bitcode that the ArchLinux bugpoint produced (it was able to successfully reduce the bc).

[llbug.zip](https://github.com/user-attachments/files/16023855/llbug.zip)

</pre>
<img width="1px" height="1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