Skip to content

Commit 2be738a

Browse files
committed
auto merge of #13935 : thestinger/rust/noalias, r=pcwalton
This was removed because these could alias with `&const T` or `@mut T` and those are now gone from the language. There are still aliasing issues within local scopes, but this is correct for function parameters. This also removes the no-op `noalias` marker on proc (not a pointer) and leaves out the mention of #6750 because real type-based alias analysis is not within the scope of best effort usage of the `noalias` attribute. Test case: pub fn foo(x: &mut &mut u32) { **x = 5; **x = 5; } Before: define void @_ZN3foo20h0ce94c9671b0150bdaa4v0.0E(i32** nocapture readonly) unnamed_addr #0 { entry-block: %1 = load i32** %0, align 8 store i32 5, i32* %1, align 4 %2 = load i32** %0, align 8 store i32 5, i32* %2, align 4 ret void } After: define void @_ZN3foo20h0ce94c9671b0150bdaa4v0.0E(i32** noalias nocapture readonly) unnamed_addr #0 { entry-block: %1 = load i32** %0, align 8 store i32 5, i32* %1, align 4 ret void } Closes #12436
2 parents ecc18f3 + f62c753 commit 2be738a

File tree

1 file changed

+11
-11
lines changed

1 file changed

+11
-11
lines changed

src/librustc/middle/trans/base.rs

+11-11
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,6 @@ fn decl_fn(llmod: ModuleRef, name: &str, cc: lib::llvm::CallConv,
186186
}
187187
}
188188
// `~` pointer return values never alias because ownership is transferred
189-
// FIXME #6750 ~Trait cannot be directly marked as
190-
// noalias because the actual object pointer is nested.
191189
ty::ty_uniq(..) // | ty::ty_trait(_, _, ty::UniqTraitStore, _, _)
192190
=> {
193191
unsafe {
@@ -258,23 +256,25 @@ pub fn decl_rust_fn(ccx: &CrateContext, has_env: bool,
258256
let llarg = unsafe { llvm::LLVMGetParam(llfn, (offset + i) as c_uint) };
259257
match ty::get(arg_ty).sty {
260258
// `~` pointer parameters never alias because ownership is transferred
261-
// FIXME #6750 ~Trait cannot be directly marked as
262-
// noalias because the actual object pointer is nested.
263-
ty::ty_uniq(..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
264-
ty::ty_closure(~ty::ClosureTy {store: ty::UniqTraitStore, ..}) => {
259+
ty::ty_uniq(..) => {
265260
unsafe {
266261
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
267262
}
268-
},
269-
// When a reference in an argument has no named lifetime, it's
270-
// impossible for that reference to escape this function(ie, be
271-
// returned).
263+
}
264+
// `&mut` pointer parameters never alias other parameters, or mutable global data
265+
ty::ty_rptr(_, mt) if mt.mutbl == ast::MutMutable => {
266+
unsafe {
267+
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
268+
}
269+
}
270+
// When a reference in an argument has no named lifetime, it's impossible for that
271+
// reference to escape this function (returned or stored beyond the call by a closure).
272272
ty::ty_rptr(ReLateBound(_, BrAnon(_)), _) => {
273273
debug!("marking argument of {} as nocapture because of anonymous lifetime", name);
274274
unsafe {
275275
llvm::LLVMAddAttribute(llarg, lib::llvm::NoCaptureAttribute as c_uint);
276276
}
277-
},
277+
}
278278
_ => {
279279
// For non-immediate arguments the callee gets its own copy of
280280
// the value on the stack, so there are no aliases

0 commit comments

Comments
 (0)