Skip to content

Commit dcf3a47

Browse files
committed
fix nounwind on extern "C" declarations
1 parent edcfc26 commit dcf3a47

File tree

2 files changed

+5
-17
lines changed

2 files changed

+5
-17
lines changed

src/librustc_codegen_llvm/attributes.rs

+2-14
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,14 @@ use rustc::hir::{CodegenFnAttrFlags, CodegenFnAttrs};
66
use rustc::hir::def_id::{DefId, LOCAL_CRATE};
77
use rustc::session::Session;
88
use rustc::session::config::{Sanitizer, OptLevel};
9-
use rustc::ty::{self, TyCtxt, PolyFnSig};
9+
use rustc::ty::{TyCtxt, PolyFnSig};
1010
use rustc::ty::layout::HasTyCtxt;
1111
use rustc::ty::query::Providers;
1212
use rustc_data_structures::small_c_str::SmallCStr;
1313
use rustc_data_structures::fx::FxHashMap;
1414
use rustc_target::spec::PanicStrategy;
1515
use rustc_codegen_ssa::traits::*;
1616

17-
use crate::abi::Abi;
1817
use crate::attributes;
1918
use crate::llvm::{self, Attribute};
2019
use crate::llvm::AttributePlace::Function;
@@ -201,7 +200,7 @@ pub fn from_fn_attrs(
201200
cx: &CodegenCx<'ll, 'tcx>,
202201
llfn: &'ll Value,
203202
id: Option<DefId>,
204-
sig: PolyFnSig<'tcx>,
203+
_sig: PolyFnSig<'tcx>,
205204
) {
206205
let codegen_fn_attrs = id.map(|id| cx.tcx.codegen_fn_attrs(id))
207206
.unwrap_or_else(|| CodegenFnAttrs::new());
@@ -274,17 +273,6 @@ pub fn from_fn_attrs(
274273
} else if codegen_fn_attrs.flags.contains(CodegenFnAttrFlags::RUSTC_ALLOCATOR_NOUNWIND) {
275274
// Special attribute for allocator functions, which can't unwind
276275
false
277-
} else if let Some(id) = id {
278-
let sig = cx.tcx.normalize_erasing_late_bound_regions(ty::ParamEnv::reveal_all(), &sig);
279-
if cx.tcx.is_foreign_item(id) && sig.abi != Abi::Rust && sig.abi != Abi::RustCall {
280-
// Foreign non-Rust items like `extern "C" { fn foo(); }` are assumed not to
281-
// unwind
282-
false
283-
} else {
284-
// Anything else defined in Rust is assumed that it can possibly
285-
// unwind
286-
true
287-
}
288276
} else {
289277
// assume this can possibly unwind, avoiding the application of a
290278
// `nounwind` attribute below.

src/test/codegen/extern-functions.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
#![feature(unwind_attributes)]
55

66
extern {
7-
// CHECK: Function Attrs: nounwind
8-
// CHECK-NEXT: declare void @extern_fn
9-
fn extern_fn(); // assumed not to unwind
7+
// CHECK-NOT: nounwind
8+
// CHECK: declare void @extern_fn
9+
fn extern_fn();
1010
// CHECK-NOT: nounwind
1111
// CHECK: declare void @unwinding_extern_fn
1212
#[unwind(allowed)]

0 commit comments

Comments
 (0)