Skip to content

Commit 8beec01

Browse files
Rollup merge of #155370 - iyernaveenr:naveen_r_iyer/issue-114532-needs-test, r=Mark-Simulacrum
Add regression test for dead code elimination with drop + panic Add a codegen test for #114532. The bug was that dead code elimination failed 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()` + `ret void`, with no panic or panicking call in the function body. Closes #114532
2 parents ec2d669 + 46f360a commit 8beec01

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)