Skip to content

Commit 4f8214c

Browse files
authored
Rollup merge of rust-lang#65346 - RalfJung:nounwind-tests, r=nagisa
nounwind tests and cleanup This is a follow-up to @pnkfelix' rust-lang#65020. In particular it adds some tests as @nagisa asked. It also does a cleanup that the original PR omitted to reduce backporting risks. I hope I finally managed to write an uncontroversial PR in this area. ;) This should not change any behavior, just test it better.
2 parents d10702b + 09d7be3 commit 4f8214c

File tree

5 files changed

+63
-48
lines changed

5 files changed

+63
-48
lines changed

src/librustc_codegen_llvm/attributes.rs

+3-23
Original file line numberDiff line numberDiff line change
@@ -270,23 +270,12 @@ pub fn from_fn_attrs(
270270
// optimize based on this!
271271
false
272272
} else if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::UNWIND) {
273-
// If a specific #[unwind] attribute is present, use that
273+
// If a specific #[unwind] attribute is present, use that.
274274
true
275275
} else if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_ALLOCATOR_NOUNWIND) {
276-
// Special attribute for allocator functions, which can't unwind
276+
// Special attribute for allocator functions, which can't unwind.
277277
false
278-
} else if let Some(_) = id {
279-
// rust-lang/rust#64655, rust-lang/rust#63909: to minimize
280-
// risk associated with changing cases where nounwind
281-
// attribute is attached, this code is deliberately mimicking
282-
// old control flow based on whether `id` is `Some` or `None`.
283-
//
284-
// However, in the long term we should either:
285-
// - fold this into final else (i.e. stop inspecting `id`)
286-
// - or, adopt Rust PR #63909.
287-
//
288-
// see also Rust RFC 2753.
289-
278+
} else {
290279
let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
291280
if sig.abi == Abi::Rust || sig.abi == Abi::RustCall {
292281
// Any Rust method (or `extern "Rust" fn` or `extern
@@ -312,15 +301,6 @@ pub fn from_fn_attrs(
312301
// In either case, we mark item as explicitly nounwind.
313302
false
314303
}
315-
} else {
316-
// assume this can possibly unwind, avoiding the application of a
317-
// `nounwind` attribute below.
318-
//
319-
// (But: See comments in previous branch. Specifically, it is
320-
// unclear whether there is real value in the assumption this
321-
// can unwind. The conservatism here may just be papering over
322-
// a real problem by making some UB a bit harder to hit.)
323-
true
324304
});
325305

326306
// Always annotate functions with the target-cpu they are compiled for.

src/test/codegen/extern-functions.rs

-19
This file was deleted.

src/test/codegen/nounwind-extern.rs

-6
This file was deleted.
+19
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// compile-flags: -C opt-level=0
2+
3+
#![crate_type = "lib"]
4+
#![feature(unwind_attributes)]
5+
6+
// Make sure these all do *not* get the attribute.
7+
// We disable optimizations to prevent LLVM from infering the attribute.
8+
// CHECK-NOT: nounwind
9+
10+
// "C" ABI
11+
// pub extern fn foo() {} // FIXME right now we don't abort-on-panic but add `nounwind` nevertheless
12+
#[unwind(allowed)]
13+
pub extern fn foo_allowed() {}
14+
15+
// "Rust"
16+
// (`extern "Rust"` could be removed as all `fn` get it implicitly; we leave it in for clarity.)
17+
pub extern "Rust" fn bar() {}
18+
#[unwind(allowed)]
19+
pub extern "Rust" fn bar_allowed() {}
+41
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
// compile-flags: -C no-prepopulate-passes
2+
3+
#![crate_type = "lib"]
4+
#![feature(unwind_attributes)]
5+
6+
extern {
7+
// CHECK: Function Attrs:{{.*}}nounwind
8+
// CHECK-NEXT: declare void @extern_fn
9+
fn extern_fn();
10+
// CHECK-NOT: Function Attrs:{{.*}}nounwind
11+
// CHECK: declare void @unwinding_extern_fn
12+
#[unwind(allowed)]
13+
fn unwinding_extern_fn();
14+
// CHECK-NOT: nounwind
15+
// CHECK: declare void @aborting_extern_fn
16+
#[unwind(aborts)]
17+
fn aborting_extern_fn(); // FIXME: we want to have the attribute here
18+
}
19+
20+
extern "Rust" {
21+
// CHECK-NOT: nounwind
22+
// CHECK: declare void @rust_extern_fn
23+
fn rust_extern_fn();
24+
// CHECK-NOT: nounwind
25+
// CHECK: declare void @rust_unwinding_extern_fn
26+
#[unwind(allowed)]
27+
fn rust_unwinding_extern_fn();
28+
// CHECK-NOT: nounwind
29+
// CHECK: declare void @rust_aborting_extern_fn
30+
#[unwind(aborts)]
31+
fn rust_aborting_extern_fn(); // FIXME: we want to have the attribute here
32+
}
33+
34+
pub unsafe fn force_declare() {
35+
extern_fn();
36+
unwinding_extern_fn();
37+
aborting_extern_fn();
38+
rust_extern_fn();
39+
rust_unwinding_extern_fn();
40+
rust_aborting_extern_fn();
41+
}

0 commit comments

Comments
 (0)