@@ -75,6 +75,7 @@ state type crate_ctxt = rec(session.session sess,
75
75
state type fn_ctxt = rec ( ValueRef llfn,
76
76
ValueRef lltaskptr ,
77
77
mutable option. t[ ValueRef ] llself ,
78
+ mutable option. t[ ValueRef ] llretptr ,
78
79
hashmap[ ast. def_id, ValueRef ] llargs ,
79
80
hashmap[ ast. def_id, ValueRef ] lllocals ,
80
81
hashmap[ ast. def_id, ValueRef ] lltydescs ,
@@ -306,6 +307,10 @@ fn type_of_fn_full(@crate_ctxt cx,
306
307
case ( _) { }
307
308
}
308
309
310
+ if ( ty. type_has_dynamic_size ( output) ) {
311
+ atys += T_ptr ( type_of ( cx, output) ) ;
312
+ }
313
+
309
314
for ( ty. arg arg in inputs) {
310
315
let TypeRef t = type_of ( cx, arg. ty ) ;
311
316
alt ( arg. mode ) {
@@ -318,7 +323,7 @@ fn type_of_fn_full(@crate_ctxt cx,
318
323
}
319
324
320
325
auto ret_ty;
321
- if ( ty. type_is_nil ( output) ) {
326
+ if ( ty. type_is_nil ( output) || ty . type_has_dynamic_size ( output ) ) {
322
327
ret_ty = llvm. LLVMVoidType ( ) ;
323
328
} else {
324
329
ret_ty = type_of ( cx, output) ;
@@ -2183,8 +2188,17 @@ impure fn trans_ret(@block_ctxt cx, &option.t[@ast.expr] e) -> result {
2183
2188
if ( ty. type_is_nil( ty. expr_ty( ex) ) ) {
2184
2189
r. bcx. build. RetVoid ( ) ;
2185
2190
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
+ }
2188
2202
}
2189
2203
ret r;
2190
2204
}
@@ -2375,6 +2389,7 @@ fn new_fn_ctxt(@crate_ctxt cx,
2375
2389
ret @rec( llfn=llfndecl,
2376
2390
lltaskptr=lltaskptr,
2377
2391
mutable llself=none[ ValueRef ] ,
2392
+ mutable llretptr=none[ ValueRef ] ,
2378
2393
llargs=llargs,
2379
2394
lllocals=lllocals,
2380
2395
lltydescs=lltydescs,
@@ -2384,6 +2399,7 @@ fn new_fn_ctxt(@crate_ctxt cx,
2384
2399
2385
2400
fn create_llargs_for_fn_args ( & @fn_ctxt cx ,
2386
2401
option. t[ TypeRef ] ty_self ,
2402
+ @ty. t ret_ty ,
2387
2403
& vec[ ast. arg] args ,
2388
2404
& vec[ ast. ty_param] ty_params ) {
2389
2405
let uint arg_n = 1 u;
@@ -2405,6 +2421,11 @@ fn create_llargs_for_fn_args(&@fn_ctxt cx,
2405
2421
case ( _) { }
2406
2422
}
2407
2423
2424
+ if ( ty. type_has_dynamic_size( ret_ty) ) {
2425
+ cx. llretptr = some[ ValueRef ] ( llvm. LLVMGetParam ( cx. llfn, arg_n) ) ;
2426
+ arg_n += 1 u;
2427
+ }
2428
+
2408
2429
for ( ast. arg arg in args) {
2409
2430
auto llarg = llvm. LLVMGetParam ( cx. llfn, arg_n) ;
2410
2431
check ( llarg as int != 0 ) ;
@@ -2467,7 +2488,8 @@ impure fn trans_fn(@crate_ctxt cx, &ast._fn f, ast.def_id fid,
2467
2488
cx. item_names. insert( cx. path, llfndecl) ;
2468
2489
2469
2490
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) ;
2471
2493
2472
2494
auto bcx = new_top_block_ctxt( fcx) ;
2473
2495
@@ -2528,7 +2550,7 @@ impure fn trans_obj(@crate_ctxt cx, &ast._obj ob, ast.def_id oid,
2528
2550
}
2529
2551
2530
2552
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 ) ,
2532
2554
fn_args, ty_params) ;
2533
2555
2534
2556
auto bcx = new_top_block_ctxt( fcx) ;
@@ -2636,7 +2658,8 @@ fn trans_tag_variant(@crate_ctxt cx, ast.def_id tag_id,
2636
2658
cx. item_names. insert( cx. path, llfndecl) ;
2637
2659
2638
2660
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) ;
2640
2663
2641
2664
auto bcx = new_top_block_ctxt( fcx) ;
2642
2665
@@ -2902,6 +2925,7 @@ fn trans_exit_task_glue(@crate_ctxt cx) {
2902
2925
auto fcx = @rec ( llfn=llfn,
2903
2926
lltaskptr=lltaskptr,
2904
2927
mutable llself=none[ ValueRef ] ,
2928
+ mutable llretptr=none[ ValueRef ] ,
2905
2929
llargs=new_def_hash[ ValueRef ] ( ) ,
2906
2930
lllocals=new_def_hash[ ValueRef ] ( ) ,
2907
2931
lltydescs=new_def_hash[ ValueRef ] ( ) ,
0 commit comments