Skip to content

Commit f254d11

Browse files
committed
auto merge of #6742 : Aatch/rust/mut-noalias, r=thestinger
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 #6350
2 parents 510d0f2 + 2c2346e commit f254d11

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/librustc/middle/trans/base.rs

+14-1
Original file line numberDiff line numberDiff line change
@@ -1694,7 +1694,20 @@ pub fn create_llargs_for_fn_args(cx: fn_ctxt,
16941694
vec::from_fn(args.len(), |i| {
16951695
unsafe {
16961696
let arg_n = first_real_arg + i;
1697-
llvm::LLVMGetParam(cx.llfn, arg_n as c_uint)
1697+
let arg = &args[i];
1698+
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
1699+
1700+
// Mark `&mut T` as no-alias, as the borrowck pass ensures it's true
1701+
match arg.ty.node {
1702+
ast::ty_rptr(_, mt) => {
1703+
if mt.mutbl == ast::m_mutbl {
1704+
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
1705+
}
1706+
}
1707+
_ => {}
1708+
}
1709+
1710+
llarg
16981711
}
16991712
})
17001713
}

0 commit comments

Comments
 (0)