handle attributes for non-immediate types first

Slices are non-immediate and were not having these attributes applied.
This commit is contained in:
Daniel Micay 2014-05-26 03:20:31 -04:00
parent 0c51149ac9
commit 22ab5303ff
1 changed files with 10 additions and 15 deletions

View File

@ -1728,16 +1728,20 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
for (idx, &t) in fn_sig.inputs.iter().enumerate().map(|(i, v)| (i + first_arg_offset, v)) {
match ty::get(t).sty {
// this needs to be first to prevent fat pointers from falling through
_ if !type_is_immediate(ccx, t) => {
// For non-immediate arguments the callee gets its own copy of
// the value on the stack, so there are no aliases. It's also
// program-invisible so can't possibly capture
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
attrs.push((idx, lib::llvm::NoCaptureAttribute as u64));
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
}
// `~` pointer parameters never alias because ownership is transferred
ty::ty_uniq(_) => {
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
}
// These are not really pointers but pairs, (pointer, len)
ty::ty_rptr(_, ty::mt { ty: it, .. }) |
ty::ty_rptr(_, ty::mt { ty: it, .. }) if match ty::get(it).sty {
ty::ty_str | ty::ty_vec(..) => true, _ => false
} => {}
// `&mut` pointer parameters never alias other parameters, or mutable global data
ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable => {
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
@ -1759,16 +1763,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
ty::ty_rptr(_, _) => {
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
}
_ => {
// For non-immediate arguments the callee gets its own copy of
// the value on the stack, so there are no aliases. It's also
// program-invisible so can't possibly capture
if !type_is_immediate(ccx, t) {
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
attrs.push((idx, lib::llvm::NoCaptureAttribute as u64));
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
}
}
_ => ()
}
}