Skip to content

Commit 90c48be

Browse files
committed
Centralise the handling of attributes on extern functions
1 parent fd230ff commit 90c48be

File tree

2 files changed

+6
-10
lines changed

2 files changed

+6
-10
lines changed

src/librustc_trans/trans/base.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -677,11 +677,8 @@ pub fn trans_external_path<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
677677
ccx.sess().bug("unexpected intrinsic in trans_external_path")
678678
}
679679
_ => {
680-
let llfn = foreign::register_foreign_item_fn(ccx, fn_ty.abi,
681-
t, &name);
682680
let attrs = csearch::get_item_attrs(&ccx.sess().cstore, did);
683-
attributes::from_fn_attrs(ccx, &attrs, llfn);
684-
llfn
681+
foreign::register_foreign_item_fn(ccx, fn_ty.abi, t, &name, &attrs)
685682
}
686683
}
687684
}
@@ -2418,9 +2415,7 @@ pub fn get_item_val(ccx: &CrateContext, id: ast::NodeId) -> ValueRef {
24182415
let abi = ccx.tcx().map.get_foreign_abi(id);
24192416
let ty = ccx.tcx().node_id_to_type(ni.id);
24202417
let name = foreign::link_name(&*ni);
2421-
let llfn = foreign::register_foreign_item_fn(ccx, abi, ty, &name);
2422-
attributes::from_fn_attrs(ccx, &ni.attrs, llfn);
2423-
llfn
2418+
foreign::register_foreign_item_fn(ccx, abi, ty, &name, &ni.attrs)
24242419
}
24252420
hir::ForeignItemStatic(..) => {
24262421
foreign::register_static(ccx, &*ni)

src/librustc_trans/trans/foreign.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,8 @@ pub fn get_extern_fn(ccx: &CrateContext,
187187
/// Registers a foreign function found in a library. Just adds a LLVM global.
188188
pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
189189
abi: Abi, fty: Ty<'tcx>,
190-
name: &str) -> ValueRef {
190+
name: &str,
191+
attrs: &[hir::Attribute])-> ValueRef {
191192
debug!("register_foreign_item_fn(abi={:?}, \
192193
ty={:?}, \
193194
name={})",
@@ -211,6 +212,7 @@ pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
211212

212213
let llfn = get_extern_fn(ccx, &mut *ccx.externs().borrow_mut(), name, cc, llfn_ty, fty);
213214
add_argument_attributes(&tys, llfn);
215+
attributes::from_fn_attrs(ccx, attrs, llfn);
214216
llfn
215217
}
216218

@@ -489,8 +491,7 @@ pub fn trans_foreign_mod(ccx: &CrateContext, foreign_mod: &hir::ForeignMod) {
489491
"foreign fn's sty isn't a bare_fn_ty?")
490492
}
491493

492-
let llfn = register_foreign_item_fn(ccx, abi, ty, &lname);
493-
attributes::from_fn_attrs(ccx, &foreign_item.attrs, llfn);
494+
register_foreign_item_fn(ccx, abi, ty, &lname, &foreign_item.attrs);
494495
// Unlike for other items, we shouldn't call
495496
// `base::update_linkage` here. Foreign items have
496497
// special linkage requirements, which are handled

0 commit comments

Comments
 (0)