From 46f360abbd3c432add025cd2b15b81f0c786400c Mon Sep 17 00:00:00 2001 From: Naveen Iyer Date: Thu, 16 Apr 2026 00:56:47 +0000 Subject: [PATCH] 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 --- tests/codegen-llvm/issues/issue-114532.rs | 34 +++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 tests/codegen-llvm/issues/issue-114532.rs diff --git a/tests/codegen-llvm/issues/issue-114532.rs b/tests/codegen-llvm/issues/issue-114532.rs new file mode 100644 index 000000000000..41d9effbe4c9 --- /dev/null +++ b/tests/codegen-llvm/issues/issue-114532.rs @@ -0,0 +1,34 @@ +//@ compile-flags: -Copt-level=3 +#![crate_type = "lib"] + +// Regression test for #114532. +// Dead code elimination used to fail when a Drop impl contained a panic +// and a potentially-panicking function was called after the value was created. + +struct Foo(bool); + +impl Drop for Foo { + fn drop(&mut self) { + if self.0 { + return; + } + panic!("dead"); + } +} + +// CHECK-LABEL: @foo( +// CHECK-NOT: panic +// CHECK-NOT: call void @{{.*}}panicking +// CHECK: call {{.*}} @unknown( +// CHECK-NEXT: ret void +#[no_mangle] +pub fn foo() { + let _a = Foo(true); + unsafe { + unknown(9); + } +} + +extern "Rust" { + fn unknown(x: i32) -> bool; +}