From 90c48bed25751f4c171b1555f8114234ca0a81c4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Steinbrink?= Date: Fri, 11 Sep 2015 20:07:12 +0200 Subject: [PATCH] Centralise the handling of attributes on extern functions --- src/librustc_trans/trans/base.rs | 9 ++------- src/librustc_trans/trans/foreign.rs | 7 ++++--- 2 files changed, 6 insertions(+), 10 deletions(-) diff --git a/src/librustc_trans/trans/base.rs b/src/librustc_trans/trans/base.rs index f8b60ebdea5..1359252e035 100644 --- a/src/librustc_trans/trans/base.rs +++ b/src/librustc_trans/trans/base.rs @@ -677,11 +677,8 @@ pub fn trans_external_path<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ccx.sess().bug("unexpected intrinsic in trans_external_path") } _ => { - let llfn = foreign::register_foreign_item_fn(ccx, fn_ty.abi, - t, &name); let attrs = csearch::get_item_attrs(&ccx.sess().cstore, did); - attributes::from_fn_attrs(ccx, &attrs, llfn); - llfn + foreign::register_foreign_item_fn(ccx, fn_ty.abi, t, &name, &attrs) } } } @@ -2418,9 +2415,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef { let abi = ccx.tcx().map.get_foreign_abi(id); let ty = ccx.tcx().node_id_to_type(ni.id); let name = foreign::link_name(&*ni); - let llfn = foreign::register_foreign_item_fn(ccx, abi, ty, &name); - attributes::from_fn_attrs(ccx, &ni.attrs, llfn); - llfn + foreign::register_foreign_item_fn(ccx, abi, ty, &name, &ni.attrs) } hir::ForeignItemStatic(..) => { foreign::register_static(ccx, &*ni) diff --git a/src/librustc_trans/trans/foreign.rs b/src/librustc_trans/trans/foreign.rs index 9781fd037d7..9a561249594 100644 --- a/src/librustc_trans/trans/foreign.rs +++ b/src/librustc_trans/trans/foreign.rs @@ -187,7 +187,8 @@ pub fn get_extern_fn(ccx: &CrateContext, /// Registers a foreign function found in a library. Just adds a LLVM global. pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, abi: Abi, fty: Ty<'tcx>, - name: &str) -> ValueRef { + name: &str, + attrs: &[hir::Attribute])-> ValueRef { debug!("register_foreign_item_fn(abi={:?}, \ ty={:?}, \ name={})", @@ -211,6 +212,7 @@ pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, let llfn = get_extern_fn(ccx, &mut *ccx.externs().borrow_mut(), name, cc, llfn_ty, fty); add_argument_attributes(&tys, llfn); + attributes::from_fn_attrs(ccx, attrs, llfn); llfn } @@ -489,8 +491,7 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) { "foreign fn's sty isn't a bare_fn_ty?") } - let llfn = register_foreign_item_fn(ccx, abi, ty, &lname); - attributes::from_fn_attrs(ccx, &foreign_item.attrs, llfn); + register_foreign_item_fn(ccx, abi, ty, &lname, &foreign_item.attrs); // Unlike for other items, we shouldn't call // `base::update_linkage` here. Foreign items have // special linkage requirements, which are handled