Skip to content

Commit 4c2d4cd

Browse files
committed
Add noalias to safe shared reference parameters
This add the LLVM noalias attribute to parameters of a shared reference type (&) which have a safe interior.
1 parent a455345 commit 4c2d4cd

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/librustc/middle/trans/base.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -2140,7 +2140,10 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t)
21402140
attrs.push((idx, llvm::NonNullAttribute as u64));
21412141
}
21422142
// `&mut` pointer parameters never alias other parameters, or mutable global data
2143-
ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable => {
2143+
// `&` pointer parameters never alias either (for LLVM's purposes) as long as the
2144+
// interior is safe
2145+
ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable ||
2146+
!ty::type_contents(ccx.tcx(), mt.ty).interior_unsafe() => {
21442147
attrs.push((idx, llvm::NoAliasAttribute as u64));
21452148
attrs.push((idx, llvm::NonNullAttribute as u64));
21462149
match b {

0 commit comments

Comments
 (0)