Correctly set return type attributes on foreign function declarations
The ArgType type gives us a generic way to specify an attribute for a type to ensure ABI conformance for foreign functions. But the code that actually sets the argument attributes in the function declaration only sets the attribute for the return type when the type is indirect. Since LLVMAddAttribute() doesn't allow to set attributes on the return type, we have to use LLVMAddFunctionAttribute() instead. This didn't cause problems yet, because currently only some indirect types require attributes to be set.
This commit is contained in:
parent
f556c8cbd8
commit
abdbaa2e19
@ -934,22 +934,17 @@ pub fn lltype_for_foreign_fn(ccx: &CrateContext, ty: ty::t) -> Type {
|
||||
|
||||
fn add_argument_attributes(tys: &ForeignTypes,
|
||||
llfn: ValueRef) {
|
||||
let mut i = 0;
|
||||
let mut i = if tys.fn_ty.ret_ty.is_indirect() { 1 } else { 0 };
|
||||
|
||||
if tys.fn_ty.ret_ty.is_indirect() {
|
||||
match tys.fn_ty.ret_ty.attr {
|
||||
Some(attr) => {
|
||||
let llarg = get_param(llfn, i);
|
||||
unsafe {
|
||||
llvm::LLVMAddAttribute(llarg, attr as c_uint);
|
||||
}
|
||||
}
|
||||
None => {}
|
||||
}
|
||||
|
||||
i += 1;
|
||||
match tys.fn_ty.ret_ty.attr {
|
||||
Some(attr) => unsafe {
|
||||
llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr as u64);
|
||||
},
|
||||
None => {}
|
||||
}
|
||||
|
||||
i += 1;
|
||||
|
||||
for &arg_ty in tys.fn_ty.arg_tys.iter() {
|
||||
if arg_ty.is_ignore() {
|
||||
continue;
|
||||
@ -958,12 +953,9 @@ fn add_argument_attributes(tys: &ForeignTypes,
|
||||
if arg_ty.pad.is_some() { i += 1; }
|
||||
|
||||
match arg_ty.attr {
|
||||
Some(attr) => {
|
||||
let llarg = get_param(llfn, i);
|
||||
unsafe {
|
||||
llvm::LLVMAddAttribute(llarg, attr as c_uint);
|
||||
}
|
||||
}
|
||||
Some(attr) => unsafe {
|
||||
llvm::LLVMAddFunctionAttribute(llfn, i as c_uint, attr as u64);
|
||||
},
|
||||
None => ()
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user