Skip to content

Commit 46f360a

Browse files
committed
Add regression test for dead code elimination with drop + panic
Dead code elimination used to fail when a Drop impl contained a panic and a potentially-panicking external function was called after the value was created. This was fixed since 1.82 but no regression test was added. The test verifies that foo() compiles to just a call to unknown() and ret void, with no panic or panicking call in the function body. Signed-off-by: Naveen R. Iyer <iyernaveenr@gmail.com>
1 parent 8317fef commit 46f360a

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
//@ compile-flags: -Copt-level=3
2+
#![crate_type = "lib"]
3+
4+
// Regression test for #114532.
5+
// Dead code elimination used to fail when a Drop impl contained a panic
6+
// and a potentially-panicking function was called after the value was created.
7+
8+
struct Foo(bool);
9+
10+
impl Drop for Foo {
11+
fn drop(&mut self) {
12+
if self.0 {
13+
return;
14+
}
15+
panic!("dead");
16+
}
17+
}
18+
19+
// CHECK-LABEL: @foo(
20+
// CHECK-NOT: panic
21+
// CHECK-NOT: call void @{{.*}}panicking
22+
// CHECK: call {{.*}} @unknown(
23+
// CHECK-NEXT: ret void
24+
#[no_mangle]
25+
pub fn foo() {
26+
let _a = Foo(true);
27+
unsafe {
28+
unknown(9);
29+
}
30+
}
31+
32+
extern "Rust" {
33+
fn unknown(x: i32) -> bool;
34+
}

0 commit comments

Comments
 (0)