Skip to content

Commit 9f14915

Browse files
committed
---
yaml --- r: 4873 b: refs/heads/master c: 35c962e h: refs/heads/master i: 4871: d51cf58 v: v3
1 parent 55e0c55 commit 9f14915

File tree

4 files changed

+39
-46
lines changed

4 files changed

+39
-46
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
---
2-
refs/heads/master: 6ad5b71ad91ae23648945733efd162935c392a41
2+
refs/heads/master: 35c962e9a18e1fc73939990865bfc799e485c23b

trunk/src/comp/middle/trans.rs

Lines changed: 35 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -92,12 +92,14 @@ fn type_of_explicit_args(cx: &@crate_ctxt, sp: &span, inputs: &[ty::arg]) ->
9292
let atys: [TypeRef] = [];
9393
for arg: ty::arg in inputs {
9494
let t: TypeRef = type_of_inner(cx, sp, arg.ty);
95-
t =
96-
alt arg.mode {
97-
ty::mo_alias(_) { T_ptr(t) }
98-
ty::mo_move. { T_ptr(t) }
99-
_ { t }
100-
};
95+
t = alt arg.mode {
96+
ty::mo_alias(_) { T_ptr(t) }
97+
ty::mo_move. { T_ptr(t) }
98+
_ {
99+
if ty::type_is_structural(cx.tcx, arg.ty) { T_ptr(t) }
100+
else { t }
101+
}
102+
};
101103
atys += [t];
102104
}
103105
ret atys;
@@ -4327,7 +4329,9 @@ fn trans_bind_thunk(cx: &@local_ctxt, sp: &span, incoming_fty: &ty::t,
43274329
bcx = copy_ty(bcx, val, e_ty).bcx;
43284330
} else {
43294331
bcx = copy_ty(bcx, val, e_ty).bcx;
4330-
val = bcx.build.Load(val);
4332+
if !ty::type_is_structural(cx.ccx.tcx, e_ty) {
4333+
val = bcx.build.Load(val);
4334+
}
43314335
}
43324336
}
43334337
llargs += [val];
@@ -4494,16 +4498,8 @@ fn trans_arg_expr(cx: &@block_ctxt, arg: &ty::arg, lldestty0: TypeRef,
44944498

44954499
if !is_bot && ty::type_contains_params(ccx.tcx, arg.ty) {
44964500
let lldestty = lldestty0;
4497-
if arg.mode == ty::mo_val && ty::type_is_structural(ccx.tcx, e_ty) {
4498-
lldestty = T_ptr(lldestty);
4499-
}
45004501
val = bcx.build.PointerCast(val, lldestty);
45014502
}
4502-
if arg.mode == ty::mo_val && ty::type_is_structural(ccx.tcx, e_ty) {
4503-
// Until here we've been treating structures by pointer;
4504-
// we are now passing it as an arg, so need to load it.
4505-
val = bcx.build.Load(val);
4506-
}
45074503

45084504
// Collect arg for later if it happens to be one we've moving out.
45094505
if arg.mode == ty::mo_move {
@@ -5821,12 +5817,13 @@ fn create_llargs_for_fn_args(cx: &@fn_ctxt, proto: ast::proto,
58215817
}
58225818
}
58235819

5824-
fn copy_args_to_allocas(fcx: @fn_ctxt, args: &[ast::arg]) {
5820+
fn copy_args_to_allocas(fcx: @fn_ctxt, args: &[ast::arg],
5821+
arg_tys: &[ty::arg]) {
58255822
let bcx = new_raw_block_ctxt(fcx, fcx.llcopyargs);
58265823
let arg_n: uint = 0u;
58275824
for aarg: ast::arg in args {
58285825
if aarg.mode == ast::val {
5829-
let argval;
5826+
let argval, arg_ty = arg_tys.(arg_n).ty;
58305827
alt bcx.fcx.llargs.find(aarg.id) {
58315828
some(x) { argval = x; }
58325829
_ {
@@ -5835,13 +5832,20 @@ fn copy_args_to_allocas(fcx: @fn_ctxt, args: &[ast::arg]) {
58355832
"unbound arg ID in copy_args_to_allocas");
58365833
}
58375834
}
5838-
let a = do_spill(bcx, argval);
5835+
let a;
5836+
if ty::type_is_structural(fcx_tcx(fcx), arg_ty) {
5837+
a = alloca(bcx, llvm::LLVMGetElementType(val_ty(argval)));
5838+
bcx = memmove_ty(bcx, a, argval, arg_ty).bcx;
5839+
} else {
5840+
a = do_spill(bcx, argval);
5841+
}
58395842

58405843
// Overwrite the llargs entry for this arg with its alloca.
58415844
bcx.fcx.llargs.insert(aarg.id, a);
58425845
}
58435846
arg_n += 1u;
58445847
}
5848+
fcx.llcopyargs = bcx.llbb;
58455849
}
58465850

58475851
fn add_cleanups_for_args(bcx: &@block_ctxt, args: &[ast::arg],
@@ -5961,7 +5965,7 @@ fn trans_closure(bcx_maybe: &option::t<@block_ctxt>,
59615965
_ { }
59625966
}
59635967
let arg_tys = arg_tys_of_fn(fcx.lcx.ccx, id);
5964-
copy_args_to_allocas(fcx, f.decl.inputs);
5968+
copy_args_to_allocas(fcx, f.decl.inputs, arg_tys);
59655969

59665970
// Figure out if we need to build a closure and act accordingly
59675971
let res =
@@ -6115,7 +6119,7 @@ fn trans_tag_variant(cx: @local_ctxt, tag_id: ast::node_id,
61156119
i += 1u;
61166120
}
61176121
let arg_tys = arg_tys_of_fn(cx.ccx, variant.node.id);
6118-
copy_args_to_allocas(fcx, fn_args);
6122+
copy_args_to_allocas(fcx, fn_args, arg_tys);
61196123
let bcx = new_top_block_ctxt(fcx);
61206124
let lltop = bcx.llbb;
61216125

@@ -6325,30 +6329,20 @@ fn create_main_wrapper(ccx: &@crate_ctxt, sp: &span, main_llfn: ValueRef,
63256329
let bcx = new_top_block_ctxt(fcx);
63266330
let lltop = bcx.llbb;
63276331

6328-
if takes_ivec {
6329-
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u);
6330-
let lltaskarg = llvm::LLVMGetParam(llfdecl, 1u);
6331-
let llenvarg = llvm::LLVMGetParam(llfdecl, 2u);
6332-
let llargvarg = llvm::LLVMGetParam(llfdecl, 3u);
6333-
let args = [lloutputarg, lltaskarg, llenvarg, llargvarg];
6334-
bcx.build.FastCall(main_llfn, args);
6332+
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u);
6333+
let lltaskarg = llvm::LLVMGetParam(llfdecl, 1u);
6334+
let llenvarg = llvm::LLVMGetParam(llfdecl, 2u);
6335+
let llargvarg = llvm::LLVMGetParam(llfdecl, 3u);
6336+
let args = if takes_ivec {
6337+
~[lloutputarg, lltaskarg, llenvarg, llargvarg]
63356338
} else {
6336-
let lloutputarg = llvm::LLVMGetParam(llfdecl, 0u);
6337-
let lltaskarg = llvm::LLVMGetParam(llfdecl, 1u);
6338-
let llenvarg = llvm::LLVMGetParam(llfdecl, 2u);
6339-
let llargvarg = llvm::LLVMGetParam(llfdecl, 3u);
6340-
63416339
// If the crate's main function doesn't take the args vector then
63426340
// we're responsible for freeing it
6343-
let llivecptr = alloca(bcx, val_ty(llargvarg));
6344-
bcx.build.Store(llargvarg, llivecptr);
6345-
bcx =
6346-
maybe_free_ivec_heap_part(bcx, llivecptr,
6347-
ty::mk_str(ccx.tcx)).bcx;
6348-
6349-
let args = [lloutputarg, lltaskarg, llenvarg];
6350-
bcx.build.FastCall(main_llfn, args);
6351-
}
6341+
bcx = maybe_free_ivec_heap_part(bcx, llargvarg,
6342+
ty::mk_str(ccx.tcx)).bcx;
6343+
~[lloutputarg, lltaskarg, llenvarg]
6344+
};
6345+
bcx.build.FastCall(main_llfn, args);
63526346
build_return(bcx);
63536347

63546348
finish_fn(fcx, lltop);

trunk/src/comp/middle/trans_objects.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ fn trans_obj(cx: @local_ctxt, sp: &span, ob: &ast::_obj,
5555
ty::ret_ty_of_fn(ccx.tcx, ctor_id), fn_args,
5656
ty_params);
5757
let arg_tys: [ty::arg] = arg_tys_of_fn(ccx, ctor_id);
58-
copy_args_to_allocas(fcx, fn_args);
58+
copy_args_to_allocas(fcx, fn_args, arg_tys);
5959

6060
// Create the first block context in the function and keep a handle on it
6161
// to pass to finish_fn later.

trunk/src/rt/main.ll.in

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,11 @@
1616

1717
declare i32 @rust_start(i32, i32, i32, i32)
1818

19-
declare external fastcc void @_rust_main(i1* nocapture, %task*, %2* nocapture, %ivec)
19+
declare external fastcc void @_rust_main(i1* nocapture, %task*, %2* nocapture, %ivec*)
2020

2121
define void @_rust_main_wrap(i1* nocapture, %task *, %2* nocapture, %ivec *)
2222
{
23-
%ivec = load %ivec *%3
24-
tail call fastcc void @_rust_main(i1* %0, %task *%1, %2* nocapture %2, %ivec %ivec)
23+
tail call fastcc void @_rust_main(i1* %0, %task *%1, %2* nocapture %2, %ivec* %3)
2524
ret void
2625
}
2726

0 commit comments

Comments
 (0)