Skip to content

Commit

Permalink
auto merge of rust-lang#6742 : Aatch/rust/mut-noalias, r=thestinger
Browse files Browse the repository at this point in the history
This marks `&mut` function arguments with the `noalias` attribute. Since the borrow checker enforces this property, this is worth doing.

I'm not sure if the place I'm doing it in is ideal, but it generates the correct code.

Closes rust-lang#6350
  • Loading branch information
bors committed May 26, 2013
2 parents 510d0f2 + 2c2346e commit f254d11
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/librustc/middle/trans/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1694,7 +1694,20 @@ pub fn create_llargs_for_fn_args(cx: fn_ctxt,
vec::from_fn(args.len(), |i| {
unsafe {
let arg_n = first_real_arg + i;
llvm::LLVMGetParam(cx.llfn, arg_n as c_uint)
let arg = &args[i];
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);

// Mark `&mut T` as no-alias, as the borrowck pass ensures it's true
match arg.ty.node {
ast::ty_rptr(_, mt) => {
if mt.mutbl == ast::m_mutbl {
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
}
}
_ => {}
}

llarg
}
})
}
Expand Down

0 comments on commit f254d11

Please sign in to comment.