@@ -1593,7 +1593,7 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
1593
1593
impl_id : Option < ast:: def_id > ,
1594
1594
param_substs : Option < @param_substs > ,
1595
1595
sp : Option < span > )
1596
- -> ( fn_ctxt , bool ) {
1596
+ -> fn_ctxt {
1597
1597
for param_substs. each |p| { p. validate ( ) ; }
1598
1598
1599
1599
debug ! ( "new_fn_ctxt_w_id(path=%s, id=%?, impl_id=%?, \
@@ -1611,21 +1611,19 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
1611
1611
ty:: subst_tps ( ccx. tcx , substs. tys , substs. self_ty , output_type)
1612
1612
}
1613
1613
} ;
1614
- let imm = ty:: type_is_immediate ( substd_output_type) ;
1614
+ let is_immediate = ty:: type_is_immediate ( substd_output_type) ;
1615
1615
1616
1616
let fcx = @mut fn_ctxt_ {
1617
1617
llfn : llfndecl,
1618
- llenv : unsafe {
1619
- llvm:: LLVMGetParam ( llfndecl, arg_env ( imm) as c_uint )
1620
- } ,
1618
+ llenv : unsafe { llvm:: LLVMGetParam ( llfndecl, 1 u as c_uint ) } ,
1621
1619
llretptr : None ,
1622
1620
llstaticallocas : llbbs. sa ,
1623
1621
llloadenv : None ,
1624
1622
llreturn : llbbs. rt ,
1625
1623
llself : None ,
1626
1624
personality : None ,
1627
1625
loop_ret : None ,
1628
- has_immediate_return_value : imm ,
1626
+ has_immediate_return_value : is_immediate ,
1629
1627
llargs : @mut HashMap :: new ( ) ,
1630
1628
lllocals : @mut HashMap :: new ( ) ,
1631
1629
llupvars : @mut HashMap :: new ( ) ,
@@ -1638,15 +1636,15 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
1638
1636
} ;
1639
1637
1640
1638
fcx. llretptr = Some ( make_return_pointer ( fcx, substd_output_type) ) ;
1641
- ( fcx, imm )
1639
+ fcx
1642
1640
}
1643
1641
1644
1642
pub fn new_fn_ctxt ( ccx : @CrateContext ,
1645
1643
path : path ,
1646
1644
llfndecl : ValueRef ,
1647
1645
output_type : ty:: t ,
1648
1646
sp : Option < span > )
1649
- -> ( fn_ctxt , bool ) {
1647
+ -> fn_ctxt {
1650
1648
new_fn_ctxt_w_id ( ccx, path, llfndecl, -1 , output_type, None , None , sp)
1651
1649
}
1652
1650
@@ -1666,8 +1664,7 @@ pub fn new_fn_ctxt(ccx: @CrateContext,
1666
1664
// field of the fn_ctxt with
1667
1665
pub fn create_llargs_for_fn_args ( cx : fn_ctxt ,
1668
1666
self_arg : self_arg ,
1669
- args : & [ ast:: arg ] ,
1670
- ret_imm : bool )
1667
+ args : & [ ast:: arg ] )
1671
1668
-> ~[ ValueRef ] {
1672
1669
let _icx = cx. insn_ctxt ( "create_llargs_for_fn_args" ) ;
1673
1670
@@ -1693,7 +1690,7 @@ pub fn create_llargs_for_fn_args(cx: fn_ctxt,
1693
1690
// llvm::LLVMGetParam for each argument.
1694
1691
vec:: from_fn ( args. len ( ) , |i| {
1695
1692
unsafe {
1696
- let arg_n = arg_pos ( ret_imm , i ) ;
1693
+ let arg_n = first_real_arg + i ;
1697
1694
let arg = & args[ i] ;
1698
1695
let llarg = llvm:: LLVMGetParam ( cx. llfn , arg_n as c_uint ) ;
1699
1696
@@ -1832,15 +1829,15 @@ pub fn trans_closure(ccx: @CrateContext,
1832
1829
param_substs. repr( ccx. tcx) ) ;
1833
1830
1834
1831
// Set up arguments to the function.
1835
- let ( fcx, imm ) = new_fn_ctxt_w_id ( ccx,
1836
- path,
1837
- llfndecl,
1838
- id,
1839
- output_type,
1840
- impl_id,
1841
- param_substs,
1842
- Some ( body. span ) ) ;
1843
- let raw_llargs = create_llargs_for_fn_args ( fcx, self_arg, decl. inputs , imm ) ;
1832
+ let fcx = new_fn_ctxt_w_id ( ccx,
1833
+ path,
1834
+ llfndecl,
1835
+ id,
1836
+ output_type,
1837
+ impl_id,
1838
+ param_substs,
1839
+ Some ( body. span ) ) ;
1840
+ let raw_llargs = create_llargs_for_fn_args ( fcx, self_arg, decl. inputs ) ;
1844
1841
1845
1842
// Set the fixed stack segment flag if necessary.
1846
1843
if attr:: attrs_contains_name ( attributes, "fixed_stack_segment" ) {
@@ -1965,16 +1962,16 @@ pub fn trans_enum_variant(ccx: @CrateContext,
1965
1962
ty_param_substs,
1966
1963
None ,
1967
1964
ty:: node_id_to_type ( ccx. tcx , enum_id) ) ;
1968
- let ( fcx, imm ) = new_fn_ctxt_w_id ( ccx,
1969
- ~[ ] ,
1970
- llfndecl,
1971
- variant. node . id ,
1972
- enum_ty,
1973
- None ,
1974
- param_substs,
1975
- None ) ;
1976
-
1977
- let raw_llargs = create_llargs_for_fn_args ( fcx, no_self, fn_args, imm ) ;
1965
+ let fcx = new_fn_ctxt_w_id ( ccx,
1966
+ ~[ ] ,
1967
+ llfndecl,
1968
+ variant. node . id ,
1969
+ enum_ty,
1970
+ None ,
1971
+ param_substs,
1972
+ None ) ;
1973
+
1974
+ let raw_llargs = create_llargs_for_fn_args ( fcx, no_self, fn_args) ;
1978
1975
let bcx = top_scope_block ( fcx, None ) , lltop = bcx. llbb ;
1979
1976
let arg_tys = ty:: ty_fn_args ( node_id_type ( bcx, variant. node . id ) ) ;
1980
1977
let bcx = copy_args_to_allocas ( fcx, bcx, fn_args, raw_llargs, arg_tys) ;
@@ -2044,16 +2041,16 @@ pub fn trans_tuple_struct(ccx: @CrateContext,
2044
2041
ty_to_str(ccx.tcx, ctor_ty)))
2045
2042
};
2046
2043
2047
- let ( fcx, imm) = new_fn_ctxt_w_id(ccx,
2048
- ~[],
2049
- llfndecl,
2050
- ctor_id,
2051
- tup_ty,
2052
- None,
2053
- param_substs,
2054
- None);
2044
+ let fcx = new_fn_ctxt_w_id(ccx,
2045
+ ~[],
2046
+ llfndecl,
2047
+ ctor_id,
2048
+ tup_ty,
2049
+ None,
2050
+ param_substs,
2051
+ None);
2055
2052
2056
- let raw_llargs = create_llargs_for_fn_args(fcx, no_self, fn_args, imm );
2053
+ let raw_llargs = create_llargs_for_fn_args(fcx, no_self, fn_args);
2057
2054
2058
2055
let bcx = top_scope_block(fcx, None);
2059
2056
let lltop = bcx.llbb;
@@ -2296,21 +2293,19 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
2296
2293
2297
2294
fn create_main(ccx: @CrateContext, main_llfn: ValueRef) -> ValueRef {
2298
2295
let nt = ty::mk_nil();
2299
-
2300
2296
let llfty = type_of_fn(ccx, [], nt);
2301
2297
let llfdecl = decl_fn(ccx.llmod, " _rust_main",
2302
2298
lib::llvm::CCallConv, llfty);
2303
2299
2304
- let ( fcx, _) = new_fn_ctxt(ccx, ~[], llfdecl, nt, None);
2300
+ let fcx = new_fn_ctxt(ccx, ~[], llfdecl, nt, None);
2305
2301
2306
2302
let bcx = top_scope_block(fcx, None);
2307
2303
let lltop = bcx.llbb;
2308
2304
2309
2305
// Call main.
2310
- let llenvarg = unsafe {
2311
- llvm::LLVMGetParam(llfdecl, arg_env(true) as c_uint)
2312
- };
2313
- let args = ~[llenvarg];
2306
+ let lloutputarg = C_null(T_ptr(T_i8()));
2307
+ let llenvarg = unsafe { llvm::LLVMGetParam(llfdecl, 1 as c_uint) };
2308
+ let args = ~[lloutputarg, llenvarg];
2314
2309
let llresult = Call(bcx, main_llfn, args);
2315
2310
Store(bcx, llresult, fcx.llretptr.get());
2316
2311
@@ -2352,6 +2347,8 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
2352
2347
trans_external_path(ccx, start_def_id, start_fn_type);
2353
2348
}
2354
2349
2350
+ let retptr = llvm::LLVMBuildAlloca(bld, T_i8(), noname());
2351
+
2355
2352
let crate_map = ccx.crate_map;
2356
2353
let opaque_crate_map = llvm::LLVMBuildPointerCast(bld,
2357
2354
crate_map,
@@ -2374,6 +2371,7 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
2374
2371
bld, rust_main, T_ptr(T_i8()), noname());
2375
2372
2376
2373
~[
2374
+ retptr,
2377
2375
C_null(T_opaque_box_ptr(ccx)),
2378
2376
opaque_rust_main,
2379
2377
llvm::LLVMGetParam(llfn, 0),
@@ -2386,6 +2384,7 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
2386
2384
debug!(" using user-defined start fn ");
2387
2385
let args = {
2388
2386
~[
2387
+ retptr,
2389
2388
C_null(T_opaque_box_ptr(ccx)),
2390
2389
llvm::LLVMGetParam(llfn, 0 as c_uint),
2391
2390
llvm::LLVMGetParam(llfn, 1 as c_uint),
0 commit comments