about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2014-07-25 12:11:08 +0000
committerbors <bors@rust-lang.org>2014-07-25 12:11:08 +0000
commit44019c79e0c7bd08d6136cd609eef619c97f45eb (patch)
tree43738aed804df0d602ae3cadaeca30e36619ad1f
parent470dbef29a3df65b6b7a7c7c46a28696eda1d031 (diff)
parent4c2d4cd3dea344e81e4df24382ac3f23e2f86f40 (diff)
downloadrust-44019c79e0c7bd08d6136cd609eef619c97f45eb.tar.gz
rust-44019c79e0c7bd08d6136cd609eef619c97f45eb.zip
auto merge of #15970 : Zoxc/rust/noalias-ref, r=cmr
This add the LLVM noalias attribute to parameters of a
shared reference type (&) which have a safe interior.
-rw-r--r--src/librustc/middle/trans/base.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs
index 68d8ab3f04c..fcdcb7847cb 100644
--- a/src/librustc/middle/trans/base.rs
+++ b/src/librustc/middle/trans/base.rs
@@ -2140,7 +2140,10 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t)
                 attrs.push((idx, llvm::NonNullAttribute as u64));
             }
             // `&mut` pointer parameters never alias other parameters, or mutable global data
-            ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable => {
+            // `&` pointer parameters never alias either (for LLVM's purposes) as long as the
+            // interior is safe
+            ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable ||
+                                  !ty::type_contents(ccx.tcx(), mt.ty).interior_unsafe() => {
                 attrs.push((idx, llvm::NoAliasAttribute as u64));
                 attrs.push((idx, llvm::NonNullAttribute as u64));
                 match b {