Skip to content

Commit 6fad19e

Browse files
committed
auto merge of #14439 : thestinger/rust/nonnull, r=luqmana
2 parents ba77c60 + 22ab530 commit 6fad19e

File tree

1 file changed

+10
-14
lines changed

1 file changed

+10
-14
lines changed

src/librustc/middle/trans/base.rs

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

17811781
for (idx, &t) in fn_sig.inputs.iter().enumerate().map(|(i, v)| (i + first_arg_offset, v)) {
17821782
match ty::get(t).sty {
1783+
// this needs to be first to prevent fat pointers from falling through
1784+
_ if !type_is_immediate(ccx, t) => {
1785+
// For non-immediate arguments the callee gets its own copy of
1786+
// the value on the stack, so there are no aliases. It's also
1787+
// program-invisible so can't possibly capture
1788+
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
1789+
attrs.push((idx, lib::llvm::NoCaptureAttribute as u64));
1790+
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
1791+
}
17831792
// `~` pointer parameters never alias because ownership is transferred
17841793
ty::ty_uniq(_) => {
17851794
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
17861795
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
17871796
}
1788-
// These are not really pointers but pairs, (pointer, len)
1789-
ty::ty_rptr(_, ty::mt { ty: it, .. }) |
1790-
ty::ty_rptr(_, ty::mt { ty: it, .. }) if match ty::get(it).sty {
1791-
ty::ty_str | ty::ty_vec(..) => true, _ => false
1792-
} => {}
17931797
// `&mut` pointer parameters never alias other parameters, or mutable global data
17941798
ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable => {
17951799
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
@@ -1811,15 +1815,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) -> Vec<(uint, u6
18111815
ty::ty_rptr(_, _) => {
18121816
attrs.push((idx, lib::llvm::NonNullAttribute as u64));
18131817
}
1814-
_ => {
1815-
// For non-immediate arguments the callee gets its own copy of
1816-
// the value on the stack, so there are no aliases. It's also
1817-
// program-invisible so can't possibly capture
1818-
if !type_is_immediate(ccx, t) {
1819-
attrs.push((idx, lib::llvm::NoAliasAttribute as u64));
1820-
attrs.push((idx, lib::llvm::NoCaptureAttribute as u64));
1821-
}
1822-
}
1818+
_ => ()
18231819
}
18241820
}
18251821

0 commit comments

Comments
 (0)