@@ -203,28 +203,28 @@ pub fn decl_internal_cdecl_fn(llmod: ModuleRef, name: &str, ty: Type) -> ValueRe
203
203
return llfn;
204
204
}
205
205
206
- pub fn get_extern_fn ( externs : & mut ExternMap , llmod : ModuleRef , name : @ str ,
206
+ pub fn get_extern_fn ( externs : & mut ExternMap , llmod : ModuleRef , name : & str ,
207
207
cc : lib:: llvm:: CallConv , ty : Type ) -> ValueRef {
208
- match externs. find_copy ( & name) {
209
- Some ( n) => return n,
208
+ match externs. find_equiv ( & name) {
209
+ Some ( n) => return * n,
210
210
None => ( )
211
211
}
212
212
let f = decl_fn ( llmod, name, cc, ty) ;
213
- externs. insert ( name, f) ;
213
+ externs. insert ( name. to_owned ( ) , f) ;
214
214
return f;
215
215
}
216
216
217
217
pub fn get_extern_const ( externs : & mut ExternMap , llmod : ModuleRef ,
218
- name : @ str , ty : Type ) -> ValueRef {
219
- match externs. find_copy ( & name) {
220
- Some ( n) => return n,
218
+ name : & str , ty : Type ) -> ValueRef {
219
+ match externs. find_equiv ( & name) {
220
+ Some ( n) => return * n,
221
221
None => ( )
222
222
}
223
223
unsafe {
224
224
let c = do name. with_c_str |buf| {
225
225
llvm:: LLVMAddGlobal ( llmod, ty. to_ref ( ) , buf)
226
226
} ;
227
- externs. insert ( name, c) ;
227
+ externs. insert ( name. to_owned ( ) , c) ;
228
228
return c;
229
229
}
230
230
}
@@ -511,7 +511,6 @@ pub fn get_res_dtor(ccx: @mut CrateContext,
511
511
None ,
512
512
ty:: lookup_item_type ( tcx, parent_id) . ty ) ;
513
513
let llty = type_of_dtor ( ccx, class_ty) ;
514
- let name = name. to_managed ( ) ; // :-(
515
514
get_extern_fn ( & mut ccx. externs ,
516
515
ccx. llmod ,
517
516
name,
@@ -798,13 +797,13 @@ pub fn fail_if_zero(cx: @mut Block, span: span, divrem: ast::binop,
798
797
}
799
798
}
800
799
801
- pub fn null_env_ptr(bcx: @mut Block ) -> ValueRef {
802
- C_null(Type::opaque_box(bcx. ccx() ).ptr_to())
800
+ pub fn null_env_ptr(ccx: &CrateContext ) -> ValueRef {
801
+ C_null(Type::opaque_box(ccx).ptr_to())
803
802
}
804
803
805
804
pub fn trans_external_path(ccx: &mut CrateContext, did: ast::def_id, t: ty::t)
806
805
-> ValueRef {
807
- let name = csearch::get_symbol(ccx.sess.cstore, did).to_managed(); // Sad
806
+ let name = csearch::get_symbol(ccx.sess.cstore, did);
808
807
match ty::get(t).sty {
809
808
ty::ty_bare_fn(_) | ty::ty_closure(_) => {
810
809
let llty = type_of_fn_from_ty(ccx, t);
@@ -1572,7 +1571,7 @@ pub fn mk_return_basic_block(llfn: ValueRef) -> BasicBlockRef {
1572
1571
// slot where the return value of the function must go.
1573
1572
pub fn make_return_pointer(fcx: @mut FunctionContext, output_type: ty::t) -> ValueRef {
1574
1573
unsafe {
1575
- if !ty::type_is_immediate (fcx.ccx.tcx, output_type) {
1574
+ if type_of::return_uses_outptr (fcx.ccx.tcx, output_type) {
1576
1575
llvm::LLVMGetParam(fcx.llfn, 0)
1577
1576
} else {
1578
1577
let lloutputtype = type_of::type_of(fcx.ccx, output_type);
@@ -1612,7 +1611,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
1612
1611
ty:: subst_tps ( ccx. tcx , substs. tys , substs. self_ty , output_type)
1613
1612
}
1614
1613
} ;
1615
- let is_immediate = ty :: type_is_immediate ( ccx. tcx , substd_output_type) ;
1614
+ let uses_outptr = type_of :: return_uses_outptr ( ccx. tcx , substd_output_type) ;
1616
1615
let fcx = @mut FunctionContext {
1617
1616
llfn : llfndecl,
1618
1617
llenv : unsafe {
@@ -1624,7 +1623,7 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
1624
1623
llreturn : None ,
1625
1624
llself : None ,
1626
1625
personality : None ,
1627
- has_immediate_return_value : is_immediate ,
1626
+ caller_expects_out_pointer : uses_outptr ,
1628
1627
llargs : @mut HashMap :: new ( ) ,
1629
1628
lllocals : @mut HashMap :: new ( ) ,
1630
1629
llupvars : @mut HashMap :: new ( ) ,
@@ -1647,8 +1646,15 @@ pub fn new_fn_ctxt_w_id(ccx: @mut CrateContext,
1647
1646
fcx. alloca_insert_pt = Some ( llvm:: LLVMGetFirstInstruction ( entry_bcx. llbb ) ) ;
1648
1647
}
1649
1648
1650
- if !ty:: type_is_nil ( substd_output_type) && !( is_immediate && skip_retptr) {
1651
- fcx. llretptr = Some ( make_return_pointer ( fcx, substd_output_type) ) ;
1649
+ if !ty:: type_is_voidish ( substd_output_type) {
1650
+ // If the function returns nil/bot, there is no real return
1651
+ // value, so do not set `llretptr`.
1652
+ if !skip_retptr || uses_outptr {
1653
+ // Otherwise, we normally allocate the llretptr, unless we
1654
+ // have been instructed to skip it for immediate return
1655
+ // values.
1656
+ fcx. llretptr = Some ( make_return_pointer ( fcx, substd_output_type) ) ;
1657
+ }
1652
1658
}
1653
1659
fcx
1654
1660
}
@@ -1796,7 +1802,7 @@ pub fn finish_fn(fcx: @mut FunctionContext, last_bcx: @mut Block) {
1796
1802
// Builds the return block for a function.
1797
1803
pub fn build_return_block ( fcx : & FunctionContext , ret_cx : @mut Block ) {
1798
1804
// Return the value if this function immediate; otherwise, return void.
1799
- if fcx. llretptr . is_none ( ) || ! fcx. has_immediate_return_value {
1805
+ if fcx. llretptr . is_none ( ) || fcx. caller_expects_out_pointer {
1800
1806
return RetVoid ( ret_cx) ;
1801
1807
}
1802
1808
@@ -1882,9 +1888,7 @@ pub fn trans_closure(ccx: @mut CrateContext,
1882
1888
// translation calls that don't have a return value (trans_crate,
1883
1889
// trans_mod, trans_item, et cetera) and those that do
1884
1890
// (trans_block, trans_expr, et cetera).
1885
- if body. expr . is_none ( ) || ty:: type_is_bot ( block_ty) ||
1886
- ty:: type_is_nil ( block_ty)
1887
- {
1891
+ if body. expr . is_none ( ) || ty:: type_is_voidish ( block_ty) {
1888
1892
bcx = controlflow:: trans_block ( bcx, body, expr:: Ignore ) ;
1889
1893
} else {
1890
1894
let dest = expr:: SaveIn ( fcx. llretptr . unwrap ( ) ) ;
@@ -2129,13 +2133,14 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
2129
2133
ast:: item_fn( ref decl, purity, _abis, ref generics, ref body) => {
2130
2134
if purity == ast:: extern_fn {
2131
2135
let llfndecl = get_item_val ( ccx, item. id ) ;
2132
- foreign:: trans_foreign_fn ( ccx,
2133
- vec:: append ( ( * path) . clone ( ) ,
2134
- [ path_name ( item. ident ) ] ) ,
2135
- decl,
2136
- body,
2137
- llfndecl,
2138
- item. id ) ;
2136
+ foreign:: trans_rust_fn_with_foreign_abi (
2137
+ ccx,
2138
+ & vec:: append ( ( * path) . clone ( ) ,
2139
+ [ path_name ( item. ident ) ] ) ,
2140
+ decl,
2141
+ body,
2142
+ llfndecl,
2143
+ item. id ) ;
2139
2144
} else if !generics. is_type_parameterized ( ) {
2140
2145
let llfndecl = get_item_val ( ccx, item. id ) ;
2141
2146
trans_fn ( ccx,
@@ -2196,7 +2201,7 @@ pub fn trans_item(ccx: @mut CrateContext, item: &ast::item) {
2196
2201
}
2197
2202
} ,
2198
2203
ast:: item_foreign_mod( ref foreign_mod) => {
2199
- foreign:: trans_foreign_mod ( ccx, path , foreign_mod) ;
2204
+ foreign:: trans_foreign_mod ( ccx, foreign_mod) ;
2200
2205
}
2201
2206
ast:: item_struct( struct_def, ref generics) => {
2202
2207
if !generics. is_type_parameterized ( ) {
@@ -2291,16 +2296,15 @@ pub fn create_entry_wrapper(ccx: @mut CrateContext,
2291
2296
2292
2297
fn create_main ( ccx : @mut CrateContext , main_llfn : ValueRef ) -> ValueRef {
2293
2298
let nt = ty:: mk_nil ( ) ;
2294
-
2295
- let llfty = type_of_fn ( ccx, [ ] , nt) ;
2299
+ let llfty = type_of_rust_fn ( ccx, [ ] , nt) ;
2296
2300
let llfdecl = decl_fn ( ccx. llmod , "_rust_main" ,
2297
2301
lib:: llvm:: CCallConv , llfty) ;
2298
2302
2299
2303
let fcx = new_fn_ctxt ( ccx, ~[ ] , llfdecl, nt, None ) ;
2300
2304
2301
2305
// the args vector built in create_entry_fn will need
2302
2306
// be updated if this assertion starts to fail.
2303
- assert ! ( fcx. has_immediate_return_value ) ;
2307
+ assert ! ( ! fcx. caller_expects_out_pointer ) ;
2304
2308
2305
2309
let bcx = fcx. entry_bcx . unwrap ( ) ;
2306
2310
// Call main.
@@ -2463,7 +2467,10 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
2463
2467
let llfn = if purity != ast:: extern_fn {
2464
2468
register_fn ( ccx, i. span , sym, i. id , ty)
2465
2469
} else {
2466
- foreign:: register_foreign_fn ( ccx, i. span , sym, i. id )
2470
+ foreign:: register_rust_fn_with_foreign_abi ( ccx,
2471
+ i. span ,
2472
+ sym,
2473
+ i. id )
2467
2474
} ;
2468
2475
set_inline_hint_if_appr ( i. attrs , llfn) ;
2469
2476
llfn
@@ -2509,9 +2516,7 @@ pub fn get_item_val(ccx: @mut CrateContext, id: ast::NodeId) -> ValueRef {
2509
2516
match ni. node {
2510
2517
ast:: foreign_item_fn( * ) => {
2511
2518
let path = vec:: append ( ( * pth) . clone ( ) , [ path_name ( ni. ident ) ] ) ;
2512
- let sym = exported_name ( ccx, path, ty, ni. attrs ) ;
2513
-
2514
- register_fn ( ccx, ni. span , sym, ni. id , ty)
2519
+ foreign:: register_foreign_item_fn ( ccx, abis, & path, ni) ;
2515
2520
}
2516
2521
ast:: foreign_item_static( * ) => {
2517
2522
let ident = token:: ident_to_str ( & ni. ident ) ;
0 commit comments