Skip to content

Commit 8bf65a1

Browse files
committed
auto merge of #8719 : msullivan/rust/cleanup, r=catamorphism
r?
2 parents c96b1d8 + 7bee050 commit 8bf65a1

File tree

1 file changed

+37
-29
lines changed

1 file changed

+37
-29
lines changed

src/librustc/middle/trans/base.rs

Lines changed: 37 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1710,7 +1710,8 @@ pub fn new_fn_ctxt(ccx: @mut CrateContext,
17101710
// field of the fn_ctxt with
17111711
pub fn create_llargs_for_fn_args(cx: @mut FunctionContext,
17121712
self_arg: self_arg,
1713-
args: &[ast::arg])
1713+
args: &[ast::arg],
1714+
arg_tys: &[ty::t])
17141715
-> ~[ValueRef] {
17151716
let _icx = push_ctxt("create_llargs_for_fn_args");
17161717

@@ -1727,26 +1728,31 @@ pub fn create_llargs_for_fn_args(cx: @mut FunctionContext,
17271728

17281729
// Return an array containing the ValueRefs that we get from
17291730
// llvm::LLVMGetParam for each argument.
1730-
vec::from_fn(args.len(), |i| {
1731-
unsafe {
1732-
let arg_n = cx.arg_pos(i);
1733-
let arg = &args[i];
1734-
let llarg = llvm::LLVMGetParam(cx.llfn, arg_n as c_uint);
1735-
1736-
// FIXME #7260: aliasing should be determined by monomorphized ty::t
1737-
match arg.ty.node {
1738-
// `~` pointers never alias other parameters, because ownership was transferred
1739-
ast::ty_uniq(_) => {
1740-
llvm::LLVMAddAttribute(llarg, lib::llvm::NoAliasAttribute as c_uint);
1731+
do vec::from_fn(args.len()) |i| {
1732+
let arg_n = cx.arg_pos(i);
1733+
let arg_ty = arg_tys[i];
1734+
let llarg = unsafe {llvm::LLVMGetParam(cx.llfn, arg_n as c_uint) };
1735+
1736+
match ty::get(arg_ty).sty {
1737+
// `~` pointers never alias other parameters, because
1738+
// ownership was transferred
1739+
ty::ty_uniq(*) |
1740+
ty::ty_evec(_, ty::vstore_uniq) |
1741+
ty::ty_closure(ty::ClosureTy {sigil: ast::OwnedSigil, _}) => {
1742+
unsafe {
1743+
llvm::LLVMAddAttribute(
1744+
llarg, lib::llvm::NoAliasAttribute as c_uint);
17411745
}
1742-
// FIXME: #6785: `&mut` can only alias `&const` and `@mut`, we should check for
1743-
// those in the other parameters and then mark it as `noalias` if there aren't any
1744-
_ => {}
17451746
}
1746-
1747-
llarg
1747+
// FIXME: #6785: `&mut` can only alias `&const` and
1748+
// `@mut`, we should check for those in the other
1749+
// parameters and then mark it as `noalias` if there
1750+
// aren't any
1751+
_ => {}
17481752
}
1749-
})
1753+
1754+
llarg
1755+
}
17501756
}
17511757

17521758
pub fn copy_args_to_allocas(fcx: @mut FunctionContext,
@@ -1881,7 +1887,6 @@ pub fn trans_closure(ccx: @mut CrateContext,
18811887
debug!("trans_closure(..., param_substs=%s)",
18821888
param_substs.repr(ccx.tcx));
18831889

1884-
// Set up arguments to the function.
18851890
let fcx = new_fn_ctxt_w_id(ccx,
18861891
path,
18871892
llfndecl,
@@ -1892,21 +1897,23 @@ pub fn trans_closure(ccx: @mut CrateContext,
18921897
body.info(),
18931898
Some(body.span));
18941899

1895-
let raw_llargs = create_llargs_for_fn_args(fcx, self_arg, decl.inputs);
1896-
1897-
// Set the fixed stack segment flag if necessary.
1898-
if attr::contains_name(attributes, "fixed_stack_segment") {
1899-
set_no_inline(fcx.llfn);
1900-
set_fixed_stack_segment(fcx.llfn);
1901-
}
1902-
19031900
// Create the first basic block in the function and keep a handle on it to
19041901
// pass to finish_fn later.
19051902
let bcx_top = fcx.entry_bcx.unwrap();
19061903
let mut bcx = bcx_top;
19071904
let block_ty = node_id_type(bcx, body.id);
19081905

1906+
// Set up arguments to the function.
19091907
let arg_tys = ty::ty_fn_args(node_id_type(bcx, id));
1908+
let raw_llargs = create_llargs_for_fn_args(fcx, self_arg,
1909+
decl.inputs, arg_tys);
1910+
1911+
// Set the fixed stack segment flag if necessary.
1912+
if attr::contains_name(attributes, "fixed_stack_segment") {
1913+
set_no_inline(fcx.llfn);
1914+
set_fixed_stack_segment(fcx.llfn);
1915+
}
1916+
19101917
bcx = copy_args_to_allocas(fcx, bcx, decl.inputs, raw_llargs, arg_tys);
19111918

19121919
maybe_load_env(fcx);
@@ -2108,10 +2115,11 @@ pub fn trans_enum_variant_or_tuple_like_struct<A:IdAndTy>(
21082115
None,
21092116
None);
21102117

2111-
let raw_llargs = create_llargs_for_fn_args(fcx, no_self, fn_args);
2118+
let arg_tys = ty::ty_fn_args(ctor_ty);
2119+
2120+
let raw_llargs = create_llargs_for_fn_args(fcx, no_self, fn_args, arg_tys);
21122121

21132122
let bcx = fcx.entry_bcx.unwrap();
2114-
let arg_tys = ty::ty_fn_args(ctor_ty);
21152123

21162124
insert_synthetic_type_entries(bcx, fn_args, arg_tys);
21172125
let bcx = copy_args_to_allocas(fcx, bcx, fn_args, raw_llargs, arg_tys);

0 commit comments

Comments
 (0)