Centralise the handling of attributes on extern functions
This commit is contained in:
parent
fd230ff124
commit
90c48bed25
@ -677,11 +677,8 @@ pub fn trans_external_path<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
|||||||
ccx.sess().bug("unexpected intrinsic in trans_external_path")
|
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);
|
let attrs = csearch::get_item_attrs(&ccx.sess().cstore, did);
|
||||||
attributes::from_fn_attrs(ccx, &attrs, llfn);
|
foreign::register_foreign_item_fn(ccx, fn_ty.abi, t, &name, &attrs)
|
||||||
llfn
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -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 abi = ccx.tcx().map.get_foreign_abi(id);
|
||||||
let ty = ccx.tcx().node_id_to_type(ni.id);
|
let ty = ccx.tcx().node_id_to_type(ni.id);
|
||||||
let name = foreign::link_name(&*ni);
|
let name = foreign::link_name(&*ni);
|
||||||
let llfn = foreign::register_foreign_item_fn(ccx, abi, ty, &name);
|
foreign::register_foreign_item_fn(ccx, abi, ty, &name, &ni.attrs)
|
||||||
attributes::from_fn_attrs(ccx, &ni.attrs, llfn);
|
|
||||||
llfn
|
|
||||||
}
|
}
|
||||||
hir::ForeignItemStatic(..) => {
|
hir::ForeignItemStatic(..) => {
|
||||||
foreign::register_static(ccx, &*ni)
|
foreign::register_static(ccx, &*ni)
|
||||||
|
@ -187,7 +187,8 @@ pub fn get_extern_fn(ccx: &CrateContext,
|
|||||||
/// Registers a foreign function found in a library. Just adds a LLVM global.
|
/// 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>,
|
pub fn register_foreign_item_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
|
||||||
abi: Abi, fty: Ty<'tcx>,
|
abi: Abi, fty: Ty<'tcx>,
|
||||||
name: &str) -> ValueRef {
|
name: &str,
|
||||||
|
attrs: &[hir::Attribute])-> ValueRef {
|
||||||
debug!("register_foreign_item_fn(abi={:?}, \
|
debug!("register_foreign_item_fn(abi={:?}, \
|
||||||
ty={:?}, \
|
ty={:?}, \
|
||||||
name={})",
|
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);
|
let llfn = get_extern_fn(ccx, &mut *ccx.externs().borrow_mut(), name, cc, llfn_ty, fty);
|
||||||
add_argument_attributes(&tys, llfn);
|
add_argument_attributes(&tys, llfn);
|
||||||
|
attributes::from_fn_attrs(ccx, attrs, llfn);
|
||||||
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?")
|
"foreign fn's sty isn't a bare_fn_ty?")
|
||||||
}
|
}
|
||||||
|
|
||||||
let llfn = register_foreign_item_fn(ccx, abi, ty, &lname);
|
register_foreign_item_fn(ccx, abi, ty, &lname, &foreign_item.attrs);
|
||||||
attributes::from_fn_attrs(ccx, &foreign_item.attrs, llfn);
|
|
||||||
// Unlike for other items, we shouldn't call
|
// Unlike for other items, we shouldn't call
|
||||||
// `base::update_linkage` here. Foreign items have
|
// `base::update_linkage` here. Foreign items have
|
||||||
// special linkage requirements, which are handled
|
// special linkage requirements, which are handled
|
||||||
|
Loading…
Reference in New Issue
Block a user