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