diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2014-08-15 12:34:28 -0400 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2014-08-15 14:23:00 -0400 |
| commit | 48edb32a3fc8ba6cc3db9a9d11f5201a919391f5 (patch) | |
| tree | 9b908cdf08fbee11a917c66c770e7f216750e305 | |
| parent | cafa47506db7f0ac8407d5771ec81f560c5a481f (diff) | |
| download | rust-48edb32a3fc8ba6cc3db9a9d11f5201a919391f5.tar.gz rust-48edb32a3fc8ba6cc3db9a9d11f5201a919391f5.zip | |
mark &T params without UnsafeCell<U> as readonly
These are already marked as `noalias` due to the immutability guarantee (see 4c2d4cd3dea344e81e4df24382ac3f23e2f86f40), but more information can be bubbled up to the caller via `readonly`.
| -rw-r--r-- | src/librustc/middle/trans/base.rs | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/src/librustc/middle/trans/base.rs b/src/librustc/middle/trans/base.rs index 9aa4355632c..351ccd9bf4d 100644 --- a/src/librustc/middle/trans/base.rs +++ b/src/librustc/middle/trans/base.rs @@ -2280,7 +2280,7 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) match ty::get(ret_ty).sty { // `~` pointer return values never alias because ownership // is transferred - ty::ty_uniq(it) if match ty::get(it).sty { + ty::ty_uniq(it) if match ty::get(it).sty { ty::ty_str | ty::ty_vec(..) | ty::ty_trait(..) => true, _ => false } => {} ty::ty_uniq(_) => { @@ -2356,8 +2356,10 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) } // `&mut` pointer parameters never alias other parameters, or mutable global data - // `&` pointer parameters never alias either (for LLVM's purposes) as long as the - // interior is safe + // + // `&T` where `T` contains no `UnsafeCell<U>` is immutable, and can be marked as both + // `readonly` and `noalias`, as LLVM's definition of `noalias` is based solely on + // memory dependencies rather than pointer equality ty::ty_rptr(b, mt) if mt.mutbl == ast::MutMutable || !ty::type_contents(ccx.tcx(), mt.ty).interior_unsafe() => { @@ -2365,6 +2367,10 @@ pub fn get_fn_llvm_attributes(ccx: &CrateContext, fn_ty: ty::t) attrs.arg(idx, llvm::NoAliasAttribute) .arg(idx, llvm::DereferenceableAttribute(llsz)); + if mt.mutbl == ast::MutImmutable { + attrs.arg(idx, llvm::ReadOnlyAttribute); + } + match b { ReLateBound(_, BrAnon(_)) => { attrs.arg(idx, llvm::NoCaptureAttribute); |
