Skip to content

Commit

Permalink
fix and test attribute on extern declarations and functions
Browse files Browse the repository at this point in the history
  • Loading branch information
RalfJung committed Aug 26, 2019
1 parent de5c8d9 commit 2214932
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 14 deletions.
6 changes: 1 addition & 5 deletions src/librustc_codegen_llvm/attributes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -271,11 +271,7 @@ pub fn from_fn_attrs(
false
} else if let Some(id) = id {
let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
if cx.tcx.is_foreign_item(id) {
// Foreign items like `extern "C" { fn foo(); }` and `extern "Rust" { fn bar(); }`
// are assumed not to unwind.
false
} else if cx.tcx.abort_on_panic_shim(id, sig.abi) {
if cx.tcx.abort_on_panic_shim(id, sig.abi) {
// Since we are adding a shim to abort on panic, this cannot unwind.
false
} else {
Expand Down
18 changes: 9 additions & 9 deletions src/test/codegen/extern-functions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
#![feature(unwind_attributes)]

extern {
// CHECK: Function Attrs: nounwind
// CHECK-NEXT: declare void @extern_fn
fn extern_fn(); // assumed not to unwind
// CHECK-NOT: nounwind
// CHECK: declare void @extern_fn
fn extern_fn();
// CHECK-NOT: nounwind
// CHECK: declare void @unwinding_extern_fn
#[unwind(allowed)]
fn unwinding_extern_fn();
// CHECK-NOT: nounwind
// CHECK: declare void @aborting_extern_fn
// CHECK: Function Attrs: nounwind
// CHECK-NEXT: declare void @aborting_extern_fn
#[unwind(aborts)]
fn aborting_extern_fn(); // FIXME: we don't have the attribute here
fn aborting_extern_fn();
}

extern "Rust" {
Expand All @@ -25,10 +25,10 @@ extern "Rust" {
// CHECK: declare void @rust_unwinding_extern_fn
#[unwind(allowed)]
fn rust_unwinding_extern_fn();
// CHECK-NOT: nounwind
// CHECK: declare void @rust_aborting_extern_fn
// CHECK: Function Attrs: nounwind
// CHECK-NEXT: declare void @rust_aborting_extern_fn
#[unwind(aborts)]
fn rust_aborting_extern_fn(); // FIXME: we don't have the attribute here
fn rust_aborting_extern_fn();
}

pub unsafe fn force_declare() {
Expand Down

0 comments on commit 2214932

Please sign in to comment.