]> git.lizzy.rs Git - rust.git/blob - src/test/codegen/unwind-landingpad-inline.rs
Rollup merge of #94093 - tmiasko:pp-no-variants, r=oli-obk
[rust.git] / src / test / codegen / unwind-landingpad-inline.rs
1 // no-system-llvm: needs #92110 + patch for Rust alloc/dealloc functions
2 // compile-flags: -Copt-level=3
3 #![crate_type = "lib"]
4
5 // This test checks that we can inline drop_in_place in
6 // unwind landing pads.
7
8 // Without inlining, the box pointers escape via the call to drop_in_place,
9 // and LLVM will not optimize out the pointer comparison.
10 // With inlining, everything should be optimized out.
11 // See https://github.com/rust-lang/rust/issues/46515
12 // CHECK-LABEL: @check_no_escape_in_landingpad
13 // CHECK: start:
14 // CHECK-NEXT: ret void
15 #[no_mangle]
16 pub fn check_no_escape_in_landingpad(f: fn()) {
17     let x = &*Box::new(0);
18     let y = &*Box::new(0);
19
20     if x as *const _ == y as *const _ {
21         f();
22     }
23 }
24
25 // Without inlining, the compiler can't tell that
26 // dropping an empty string (in a landing pad) does nothing.
27 // With inlining, the landing pad should be optimized out.
28 // See https://github.com/rust-lang/rust/issues/87055
29 // CHECK-LABEL: @check_eliminate_noop_drop
30 // CHECK: start:
31 // CHECK-NEXT: call void %g()
32 // CHECK-NEXT: ret void
33 #[no_mangle]
34 pub fn check_eliminate_noop_drop(g: fn()) {
35     let _var = String::new();
36     g();
37 }