Skip to content

Commit 004c93d

Browse files
committed
---
yaml --- r: 1146 b: refs/heads/master c: a634b21 h: refs/heads/master v: v3
1 parent c5142d2 commit 004c93d

File tree

2 files changed

+31
-7
lines changed

2 files changed

+31
-7
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: 2c6dd18224a926ed0da365511e05fcb8e5e817a5
2+
refs/heads/master: a634b21563fde802e2424bbef086ce541bb6ad8c

trunk/src/comp/middle/trans.rs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ state type crate_ctxt = rec(session.session sess,
7575
state type fn_ctxt = rec(ValueRef llfn,
7676
ValueRef lltaskptr,
7777
mutable option.t[ValueRef] llself,
78+
mutable option.t[ValueRef] llretptr,
7879
hashmap[ast.def_id, ValueRef] llargs,
7980
hashmap[ast.def_id, ValueRef] lllocals,
8081
hashmap[ast.def_id, ValueRef] lltydescs,
@@ -306,6 +307,10 @@ fn type_of_fn_full(@crate_ctxt cx,
306307
case (_) { }
307308
}
308309

310+
if (ty.type_has_dynamic_size(output)) {
311+
atys += T_ptr(type_of(cx, output));
312+
}
313+
309314
for (ty.arg arg in inputs) {
310315
let TypeRef t = type_of(cx, arg.ty);
311316
alt (arg.mode) {
@@ -318,7 +323,7 @@ fn type_of_fn_full(@crate_ctxt cx,
318323
}
319324

320325
auto ret_ty;
321-
if (ty.type_is_nil(output)) {
326+
if (ty.type_is_nil(output) || ty.type_has_dynamic_size(output)) {
322327
ret_ty = llvm.LLVMVoidType();
323328
} else {
324329
ret_ty = type_of(cx, output);
@@ -2183,8 +2188,17 @@ impure fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
21832188
if (ty.type_is_nil(ty.expr_ty(ex))) {
21842189
r.bcx.build.RetVoid();
21852190
r.val = C_nil();
2186-
} else {
2187-
r.val = r.bcx.build.Ret(r.val);
2191+
ret r; // FIXME: early return needed due to typestate bug
2192+
}
2193+
2194+
alt (cx.fcx.llretptr) {
2195+
case (some[ValueRef](?llptr)) {
2196+
r.bcx.build.Store(r.val, llptr);
2197+
r.bcx.build.RetVoid();
2198+
}
2199+
case (none[ValueRef]) {
2200+
r.val = r.bcx.build.Ret(r.val);
2201+
}
21882202
}
21892203
ret r;
21902204
}
@@ -2375,6 +2389,7 @@ fn new_fn_ctxt(@crate_ctxt cx,
23752389
ret @rec(llfn=llfndecl,
23762390
lltaskptr=lltaskptr,
23772391
mutable llself=none[ValueRef],
2392+
mutable llretptr=none[ValueRef],
23782393
llargs=llargs,
23792394
lllocals=lllocals,
23802395
lltydescs=lltydescs,
@@ -2384,6 +2399,7 @@ fn new_fn_ctxt(@crate_ctxt cx,
23842399

23852400
fn create_llargs_for_fn_args(&@fn_ctxt cx,
23862401
option.t[TypeRef] ty_self,
2402+
@ty.t ret_ty,
23872403
&vec[ast.arg] args,
23882404
&vec[ast.ty_param] ty_params) {
23892405
let uint arg_n = 1u;
@@ -2405,6 +2421,11 @@ fn create_llargs_for_fn_args(&@fn_ctxt cx,
24052421
case (_) { }
24062422
}
24072423

2424+
if (ty.type_has_dynamic_size(ret_ty)) {
2425+
cx.llretptr = some[ValueRef](llvm.LLVMGetParam(cx.llfn, arg_n));
2426+
arg_n += 1u;
2427+
}
2428+
24082429
for (ast.arg arg in args) {
24092430
auto llarg = llvm.LLVMGetParam(cx.llfn, arg_n);
24102431
check (llarg as int != 0);
@@ -2467,7 +2488,8 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
24672488
cx.item_names.insert(cx.path, llfndecl);
24682489

24692490
auto fcx = new_fn_ctxt(cx, cx.path, llfndecl);
2470-
create_llargs_for_fn_args(fcx, none[TypeRef], f.inputs, ty_params);
2491+
create_llargs_for_fn_args(fcx, none[TypeRef], ret_ty_of_fn(ann),
2492+
f.inputs, ty_params);
24712493

24722494
auto bcx = new_top_block_ctxt(fcx);
24732495

@@ -2528,7 +2550,7 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
25282550
}
25292551

25302552
auto fcx = new_fn_ctxt(cx, cx.path, llctor_decl);
2531-
create_llargs_for_fn_args(fcx, none[TypeRef],
2553+
create_llargs_for_fn_args(fcx, none[TypeRef], ret_ty_of_fn(ann),
25322554
fn_args, ty_params);
25332555

25342556
auto bcx = new_top_block_ctxt(fcx);
@@ -2636,7 +2658,8 @@ fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
26362658
cx.item_names.insert(cx.path, llfndecl);
26372659

26382660
auto fcx = new_fn_ctxt(cx, cx.path, llfndecl);
2639-
create_llargs_for_fn_args(fcx, none[TypeRef], fn_args, ty_params);
2661+
create_llargs_for_fn_args(fcx, none[TypeRef], ret_ty_of_fn(variant.ann),
2662+
fn_args, ty_params);
26402663

26412664
auto bcx = new_top_block_ctxt(fcx);
26422665

@@ -2902,6 +2925,7 @@ fn trans_exit_task_glue(@crate_ctxt cx) {
29022925
auto fcx = @rec(llfn=llfn,
29032926
lltaskptr=lltaskptr,
29042927
mutable llself=none[ValueRef],
2928+
mutable llretptr=none[ValueRef],
29052929
llargs=new_def_hash[ValueRef](),
29062930
lllocals=new_def_hash[ValueRef](),
29072931
lltydescs=new_def_hash[ValueRef](),

0 commit comments

Comments
 (0)