Skip to content

Commit 22ab530

Browse files
committed
handle attributes for non-immediate types first
Slices are non-immediate and were not having these attributes applied.
1 parent 0c51149 commit 22ab530

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

src/librustc/middle/trans/base.rs

+10-15
Original file line numberDiff line numberDiff line change
@@ -1728,16 +1728,20 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
17281728

17291729
for (idx, &t) in fn_sig.inputs.iter().enumerate().map(|(i, v)| (i + first_arg_offset, v)) {
17301730
match ty::get(t).sty {
1731+
// this needs to be first to prevent fat pointers from falling through
1732+
_ if !type_is_immediate(ccx, t) => {
1733+
// For non-immediate arguments the callee gets its own copy of
1734+
// the value on the stack, so there are no aliases. It's also
1735+
// program-invisible so can't possibly capture
1736+
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
1737+
attrs.push((idx, lib::llvm::NoCaptureAttribute as u64));
1738+
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
1739+
}
17311740
// `~` pointer parameters never alias because ownership is transferred
17321741
ty::ty_uniq(_) => {
17331742
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
17341743
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
17351744
}
1736-
// These are not really pointers but pairs, (pointer, len)
1737-
ty::ty_rptr(_, ty::mt { ty: it, .. }) |
1738-
ty::ty_rptr(_, ty::mt { ty: it, .. }) if match ty::get(it).sty {
1739-
ty::ty_str | ty::ty_vec(..) => true, _ => false
1740-
} => {}
17411745
// `&mut` pointer parameters never alias other parameters, or mutable global data
17421746
ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable => {
17431747
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
17591763
ty::ty_rptr(_, _) => {
17601764
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
17611765
}
1762-
_ => {
1763-
// For non-immediate arguments the callee gets its own copy of
1764-
// the value on the stack, so there are no aliases. It's also
1765-
// program-invisible so can't possibly capture
1766-
if !type_is_immediate(ccx, t) {
1767-
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
1768-
attrs.push((idx, lib::llvm::NoCaptureAttribute as u64));
1769-
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
1770-
}
1771-
}
1766+
_ => ()
17721767
}
17731768
}
17741769

0 commit comments

Comments
 (0)