Skip to content

Commit 2c2346e

Browse files
author
James Miller
committed
Mark &mut parameters as noalias
1 parent e2f8b51 commit 2c2346e

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 14 additions & 1 deletion
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)