Repository: rust
Issue: LLVM ERROR: `Cannot lower invokes with arbitrary operand bundles yet!`
Labels: I-crash,A-LLVM,T-compiler,A-sanitizers,C-bug,requires-debug-assertions,PG-exploit-mitigations

<!--
ICE: Rustc ./foo.rs '-Zsanitizer=kcfi -Cpanic=abort -ooutputfile -Zdump-mir-dir=dir' 'rustc: /home/gh-matthiaskrgr/vcs/github/rust_debug_assertions/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:3137: void llvm::SelectionDAGBuilder::visitInvoke(const llvm::InvokeInst&): Assertion `!I.hasOperandBundlesOtherThan( {LLVMContext::OB_deopt, LLVMContext::OB_gc_transition, LLVMContext::OB_gc_live, LLVMContext::OB_funclet, LLVMContext::OB_cfguardtarget, LLVMContext::OB_clang_arc_attachedcall}) && "Cannot lower invokes with arbitrary operand bundles yet!"' failed.', 'rustc: /home/gh-matthiaskrgr/vcs/github/rust_debug_assertions/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:3137: void llvm::SelectionDAGBuilder::visitInvoke(const llvm::InvokeInst&): Assertion `!I.hasOperandBundlesOtherThan( {LLVMContext::OB_deopt, LLVMContext::OB_gc_transition, LLVMContext::OB_gc_live, LLVMContext::OB_funclet, LLVMContext::OB_cfguardtarget, LLVMContext::OB_clang_arc_attachedcall}) && "Cannot lower invokes with arbitrary operand bundles yet!"' failed.'
File: /home/gh-matthiaskrgr/tmp/foo.rs
-->


Code:
````rust
// Tests that C++ exceptions can unwind through Rust code run destructors and
// are caught by catch_unwind. Also tests that Rust panics can unwind through
// C++ code.

use std::panic::{catch_unwind, AssertUnwindSafe};

struct DropCheck<'a>(&'a mut bool);
impl<'a> Drop for DropCheck<'a> {
    fn drop(&mut self) {
        println!("DropCheck::drop");
        *self.0 = true;
    }
}

extern "C" {
    fn test_cxx_exception();
}

extern "C-unwind" {
    fn cxx_catch_callback(cb: extern "C-unwind" fn(), ok: *mut bool);
}

#[no_mangle]
extern "C-unwind" fn rust_catch_callback(cb: extern "C-unwind" fn(), rust_ok: &mut bool) {
    let _drop = DropCheck(rust_ok);
    cb();
    unreachable!("should have unwound instead of returned");
}

fn test_rust_panic() {
    extern "C-unwind" fn callback() {
        println!("throwing rust panic");
        panic!(1234i32);
    }

    let mut dropped = false;
    let mut cxx_ok = false;
    let caught_unwind = catch_unwind(AssertUnwindSafe(|| {
        let _drop = DropCheck(&mut dropped);
        unsafe {
            cxx_catch_callback(callback, &mut cxx_ok);
        }
        unreachable!("should have unwound instead of returned");
    }));
    println!("caught rust panic");
    assert!(dropped);
    assert!(caught_unwind.is_err());
    let panic_obj = caught_unwind.unwrap_err();
    let panic_int = *panic_obj.downcast_ref::<i32>().unwrap();
    assert_eq!(panic_int, 1234);
    assert!(cxx_ok);
}

fn main() {
    unsafe { test_cxx_exception() };
    test_rust_panic();
}

````
</p>
</details>

Version information
````
rustc 1.79.0-dev
binary: rustc
commit-hash: unknown
commit-date: unknown
host: x86_64-unknown-linux-gnu
release: 1.79.0-dev
LLVM version: 18.1.4

````

Command:
`/home/gh-matthiaskrgr/.rustup/toolchains/local-debug-assertions/bin/rustc -Zsanitizer=kcfi -Cpanic=abort`

<!--
Include a backtrace in the code block by setting `RUST_BACKTRACE=1` in your
environment. E.g. `RUST_BACKTRACE=1 cargo build`.
-->
<details><summary><strong>Program output</strong></summary>
<p>

```
warning: panic message is not a string literal
  --> foo.rs:33:16
   |
33 |         panic!(1234i32);
   |                ^^^^^^^
   |
   = note: this usage of `panic!()` is deprecated; it will be a hard error in Rust 2021
   = note: for more information, see <https://doc.rust-lang.org/nightly/edition-guide/rust-2021/panic-macro-consistency.html>
   = note: `#[warn(non_fmt_panics)]` on by default
help: add a "{}" format string to `Display` the message
   |
33 |         panic!("{}", 1234i32);
   |                +++++
help: or use std::panic::panic_any instead
   |
33 |         std::panic::panic_any(1234i32);
   |         ~~~~~~~~~~~~~~~~~~~~~

rustc: /home/gh-matthiaskrgr/vcs/github/rust_debug_assertions/src/llvm-project/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp:3137: void llvm::SelectionDAGBuilder::visitInvoke(const llvm::InvokeInst&): Assertion `!I.hasOperandBundlesOtherThan( {LLVMContext::OB_deopt, LLVMContext::OB_gc_transition, LLVMContext::OB_gc_live, LLVMContext::OB_funclet, LLVMContext::OB_cfguardtarget, LLVMContext::OB_clang_arc_attachedcall}) && "Cannot lower invokes with arbitrary operand bundles yet!"' failed.
Aborted (core dumped)
```

</p>
</details>

<!--
query stack:

-->