@@ -1612,10 +1612,11 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
1612
1612
}
1613
1613
} ;
1614
1614
let is_immediate = ty:: type_is_immediate ( substd_output_type) ;
1615
-
1616
1615
let fcx = @mut fn_ctxt_ {
1617
1616
llfn : llfndecl,
1618
- llenv : unsafe { llvm:: LLVMGetParam ( llfndecl, 1 u as c_uint ) } ,
1617
+ llenv : unsafe {
1618
+ llvm:: LLVMGetUndef ( T_ptr ( T_i8 ( ) ) )
1619
+ } ,
1619
1620
llretptr : None ,
1620
1621
llstaticallocas : llbbs. sa ,
1621
1622
llloadenv : None ,
@@ -1634,7 +1635,9 @@ pub fn new_fn_ctxt_w_id(ccx: @CrateContext,
1634
1635
path : path,
1635
1636
ccx : @ccx
1636
1637
} ;
1637
-
1638
+ fcx. llenv = unsafe {
1639
+ llvm:: LLVMGetParam ( llfndecl, fcx. env_arg_pos ( ) as c_uint )
1640
+ } ;
1638
1641
fcx. llretptr = Some ( make_return_pointer ( fcx, substd_output_type) ) ;
1639
1642
fcx
1640
1643
}
@@ -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 = cx . arg_pos ( i ) ;
1694
1697
let arg = & args[ i] ;
1695
1698
let llarg = llvm:: LLVMGetParam ( cx. llfn , arg_n as c_uint ) ;
1696
1699
@@ -2293,19 +2296,26 @@ 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
2304
let fcx = new_fn_ctxt(ccx, ~[], llfdecl, nt, None);
2301
2305
2306
+ // the args vector built in create_entry_fn will need
2307
+ // be updated if this assertion starts to fail.
2308
+ assert!(fcx.has_immediate_return_value);
2309
+
2302
2310
let bcx = top_scope_block(fcx, None);
2303
2311
let lltop = bcx.llbb;
2304
2312
2305
2313
// 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];
2314
+ let llenvarg = unsafe {
2315
+ let env_arg = fcx.env_arg_pos();
2316
+ llvm::LLVMGetParam(llfdecl, env_arg as c_uint)
2317
+ };
2318
+ let args = ~[llenvarg];
2309
2319
let llresult = Call(bcx, main_llfn, args);
2310
2320
Store(bcx, llresult, fcx.llretptr.get());
2311
2321
@@ -2345,8 +2355,6 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
2345
2355
trans_external_path(ccx, start_def_id, start_fn_type);
2346
2356
}
2347
2357
2348
- let retptr = llvm::LLVMBuildAlloca(bld, T_i8(), noname());
2349
-
2350
2358
let crate_map = ccx.crate_map;
2351
2359
let opaque_crate_map = llvm::LLVMBuildPointerCast(bld,
2352
2360
crate_map,
@@ -2368,7 +2376,6 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
2368
2376
bld, rust_main, T_ptr(T_i8()), noname());
2369
2377
2370
2378
~[
2371
- retptr,
2372
2379
C_null(T_opaque_box_ptr(ccx)),
2373
2380
opaque_rust_main,
2374
2381
llvm::LLVMGetParam(llfn, 0),
@@ -2381,7 +2388,6 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
2381
2388
debug!(" using user-defined start fn ");
2382
2389
let args = {
2383
2390
~[
2384
- retptr,
2385
2391
C_null(T_opaque_box_ptr(ccx)),
2386
2392
llvm::LLVMGetParam(llfn, 0 as c_uint),
2387
2393
llvm::LLVMGetParam(llfn, 1 as c_uint),
0 commit comments