Skip to content

Commit

Permalink
add test for noop drop in landing pad
Browse files Browse the repository at this point in the history
  • Loading branch information
erikdesjardins committed Dec 30, 2021
1 parent e4463b2 commit 64da730
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions src/test/codegen/unwind-landingpad-inline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
#![crate_type = "lib"]

// This test checks that we can inline drop_in_place in
// unwind landing pads. Without this, the box pointers escape,
// unwind landing pads.

// Without inlining, the box pointers escape via the call to drop_in_place,
// and LLVM will not optimize out the pointer comparison.
// With inlining, everything should be optimized out.
// See https://github.com/rust-lang/rust/issues/46515

// Everything should be optimized out.
// CHECK-LABEL: @check_no_escape_in_landingpad
// CHECK: start:
// CHECK-NEXT: ret void
Expand All @@ -20,3 +21,17 @@ pub fn check_no_escape_in_landingpad(f: fn()) {
f();
}
}

// Without inlining, the compiler can't tell that
// dropping an empty string (in a landing pad) does nothing.
// With inlining, the landing pad should be optimized out.
// See https://github.com/rust-lang/rust/issues/87055
// CHECK-LABEL: @check_eliminate_noop_drop
// CHECK: start:
// CHECK-NEXT: call void %g()
// CHECK-NEXT: ret void
#[no_mangle]
pub fn check_eliminate_noop_drop(g: fn()) {
let _var = String::new();
g();
}

0 comments on commit 64da730

Please sign in to comment.