@@ -177,57 +177,32 @@ impl<'a> Drop for StatRecorder<'a> {
177
177
}
178
178
179
179
// only use this for foreign function ABIs and glue, use `decl_rust_fn` for Rust functions
180
- fn decl_fn ( llmod : ModuleRef , name : & str , cc : lib:: llvm:: CallConv ,
181
- ty : Type , output : ty:: t ) -> ValueRef {
180
+ pub fn decl_fn ( llmod : ModuleRef , name : & str , cc : lib:: llvm:: CallConv , ty : Type ) -> ValueRef {
182
181
let llfn: ValueRef = name. with_c_str ( |buf| {
183
182
unsafe {
184
183
llvm:: LLVMGetOrInsertFunction ( llmod, buf, ty. to_ref ( ) )
185
184
}
186
185
} ) ;
187
186
188
- match ty:: get ( output) . sty {
189
- // functions returning bottom may unwind, but can never return normally
190
- ty:: ty_bot => {
191
- unsafe {
192
- llvm:: LLVMAddFunctionAttr ( llfn, lib:: llvm:: NoReturnAttribute as c_uint )
193
- }
194
- }
195
- // `~` pointer return values never alias because ownership is transferred
196
- // FIXME #6750 ~Trait cannot be directly marked as
197
- // noalias because the actual object pointer is nested.
198
- ty:: ty_uniq( ..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
199
- ty:: ty_vec( _, ty:: vstore_uniq) | ty:: ty_str( ty:: vstore_uniq) => {
200
- unsafe {
201
- llvm:: LLVMAddReturnAttribute ( llfn, lib:: llvm:: NoAliasAttribute as c_uint ) ;
202
- }
203
- }
204
- _ => { }
205
- }
206
-
207
187
lib:: llvm:: SetFunctionCallConv ( llfn, cc) ;
208
188
// Function addresses in Rust are never significant, allowing functions to be merged.
209
189
lib:: llvm:: SetUnnamedAddr ( llfn, true ) ;
210
-
211
- llfn
190
+ return llfn;
212
191
}
213
192
214
193
// only use this for foreign function ABIs and glue, use `decl_rust_fn` for Rust functions
215
- pub fn decl_cdecl_fn ( llmod : ModuleRef ,
216
- name : & str ,
217
- ty : Type ,
218
- output : ty:: t ) -> ValueRef {
219
- decl_fn ( llmod, name, lib:: llvm:: CCallConv , ty, output)
194
+ pub fn decl_cdecl_fn ( llmod : ModuleRef , name : & str , ty : Type ) -> ValueRef {
195
+ return decl_fn ( llmod, name, lib:: llvm:: CCallConv , ty) ;
220
196
}
221
197
222
198
// only use this for foreign function ABIs and glue, use `get_extern_rust_fn` for Rust functions
223
- pub fn get_extern_fn ( externs : & mut ExternMap , llmod : ModuleRef ,
224
- name : & str , cc : lib:: llvm:: CallConv ,
225
- ty : Type , output : ty:: t ) -> ValueRef {
199
+ pub fn get_extern_fn ( externs : & mut ExternMap , llmod : ModuleRef , name : & str ,
200
+ cc : lib:: llvm:: CallConv , ty : Type ) -> ValueRef {
226
201
match externs. find_equiv ( & name) {
227
202
Some ( n) => return * n,
228
- None => { }
203
+ None => ( )
229
204
}
230
- let f = decl_fn ( llmod, name, cc, ty, output ) ;
205
+ let f = decl_fn ( llmod, name, cc, ty) ;
231
206
externs. insert ( name. to_owned ( ) , f) ;
232
207
f
233
208
}
@@ -258,7 +233,24 @@ fn decl_rust_fn(ccx: &CrateContext,
258
233
output : ty:: t ,
259
234
name : & str ) -> ValueRef {
260
235
let llfty = type_of_rust_fn ( ccx, self_ty, inputs, output) ;
261
- let llfn = decl_cdecl_fn ( ccx. llmod , name, llfty, output) ;
236
+ let llfn = decl_cdecl_fn ( ccx. llmod , name, llfty) ;
237
+
238
+ match ty:: get ( output) . sty {
239
+ // functions returning bottom may unwind, but can never return normally
240
+ ty:: ty_bot => {
241
+ unsafe {
242
+ llvm:: LLVMAddFunctionAttr ( llfn, lib:: llvm:: NoReturnAttribute as c_uint )
243
+ }
244
+ }
245
+ // `~` pointer return values never alias because ownership is transferred
246
+ ty:: ty_uniq( ..) |
247
+ ty:: ty_vec( _, ty:: vstore_uniq) => {
248
+ unsafe {
249
+ llvm:: LLVMAddReturnAttribute ( llfn, lib:: llvm:: NoAliasAttribute as c_uint ) ;
250
+ }
251
+ }
252
+ _ => ( )
253
+ }
262
254
263
255
let uses_outptr = type_of:: return_uses_outptr ( ccx, output) ;
264
256
let offset = if uses_outptr { 2 } else { 1 } ;
@@ -267,10 +259,8 @@ fn decl_rust_fn(ccx: &CrateContext,
267
259
let llarg = unsafe { llvm:: LLVMGetParam ( llfn, ( offset + i) as c_uint ) } ;
268
260
match ty:: get ( arg_ty) . sty {
269
261
// `~` pointer parameters never alias because ownership is transferred
270
- // FIXME #6750 ~Trait cannot be directly marked as
271
- // noalias because the actual object pointer is nested.
272
- ty:: ty_uniq( ..) | // ty::ty_trait(_, _, ty::UniqTraitStore, _, _) |
273
- ty:: ty_vec( _, ty:: vstore_uniq) | ty:: ty_str( ty:: vstore_uniq) |
262
+ ty:: ty_uniq( ..) |
263
+ ty:: ty_vec( _, ty:: vstore_uniq) |
274
264
ty:: ty_closure( ty:: ClosureTy { sigil : ast:: OwnedSigil , ..} ) => {
275
265
unsafe {
276
266
llvm:: LLVMAddAttribute ( llarg, lib:: llvm:: NoAliasAttribute as c_uint ) ;
@@ -368,7 +358,7 @@ pub fn malloc_raw_dyn<'a>(
368
358
} else {
369
359
// we treat ~fn, @fn and @[] as @ here, which isn't ideal
370
360
let langcall = match heap {
371
- heap_managed | heap_managed_unique => {
361
+ heap_managed => {
372
362
require_alloc_fn ( bcx, t, MallocFnLangItem )
373
363
}
374
364
heap_exchange_closure => {
@@ -392,9 +382,7 @@ pub fn malloc_raw_dyn<'a>(
392
382
langcall,
393
383
[ tydesc, size] ,
394
384
None ) ;
395
- let r = rslt ( r. bcx , PointerCast ( r. bcx , r. val , llty) ) ;
396
- maybe_set_managed_unique_rc ( r. bcx , r. val , heap) ;
397
- r
385
+ rslt ( r. bcx , PointerCast ( r. bcx , r. val , llty) )
398
386
}
399
387
}
400
388
@@ -441,27 +429,6 @@ pub fn malloc_general<'a>(bcx: &'a Block, t: ty::t, heap: heap)
441
429
malloc_general_dyn ( bcx, t, heap, llsize_of ( bcx. ccx ( ) , ty) )
442
430
}
443
431
444
- pub fn heap_for_unique ( bcx : & Block , t : ty:: t ) -> heap {
445
- if ty:: type_contents ( bcx. tcx ( ) , t) . owns_managed ( ) {
446
- heap_managed_unique
447
- } else {
448
- heap_exchange
449
- }
450
- }
451
-
452
- pub fn maybe_set_managed_unique_rc ( bcx : & Block , bx : ValueRef , heap : heap ) {
453
- assert ! ( heap != heap_exchange) ;
454
- if heap == heap_managed_unique {
455
- // In cases where we are looking at a unique-typed allocation in the
456
- // managed heap (thus have refcount 1 from the managed allocator),
457
- // such as a ~(@foo) or such. These need to have their refcount forced
458
- // to -2 so the annihilator ignores them.
459
- let rc = GEPi ( bcx, bx, [ 0 u, abi:: box_field_refcnt] ) ;
460
- let rc_val = C_int ( bcx. ccx ( ) , -2 ) ;
461
- Store ( bcx, rc_val, rc) ;
462
- }
463
- }
464
-
465
432
// Type descriptor and type glue stuff
466
433
467
434
pub fn get_tydesc_simple ( ccx : & CrateContext , t : ty:: t ) -> ValueRef {
@@ -592,8 +559,11 @@ pub fn get_res_dtor(ccx: @CrateContext,
592
559
593
560
{
594
561
let mut externs = ccx. externs . borrow_mut ( ) ;
595
- get_extern_fn ( externs. get ( ) , ccx. llmod , name,
596
- lib:: llvm:: CCallConv , llty, ty:: mk_nil ( ) )
562
+ get_extern_fn ( externs. get ( ) ,
563
+ ccx. llmod ,
564
+ name,
565
+ lib:: llvm:: CCallConv ,
566
+ llty)
597
567
}
598
568
}
599
569
}
@@ -924,8 +894,7 @@ pub fn trans_external_path(ccx: &CrateContext, did: ast::DefId, t: ty::t) -> Val
924
894
let cconv = c.unwrap_or(lib::llvm::CCallConv);
925
895
let llty = type_of_fn_from_ty(ccx, None, t);
926
896
let mut externs = ccx.externs.borrow_mut();
927
- get_extern_fn(externs.get(), ccx.llmod, name,
928
- cconv, llty, fn_ty.sig.output)
897
+ get_extern_fn(externs.get(), ccx.llmod, name, cconv, llty)
929
898
}
930
899
}
931
900
}
@@ -2541,13 +2510,13 @@ pub fn register_fn_llvmty(ccx: @CrateContext,
2541
2510
sym : ~str ,
2542
2511
node_id : ast:: NodeId ,
2543
2512
cc : lib:: llvm:: CallConv ,
2544
- fn_ty : Type ,
2545
- output : ty :: t ) -> ValueRef {
2513
+ fn_ty : Type )
2514
+ -> ValueRef {
2546
2515
debug ! ( "register_fn_fuller creating fn for item {} with path {}" ,
2547
2516
node_id,
2548
2517
ast_map:: path_to_str( item_path( ccx, & node_id) , token:: get_ident_interner( ) ) ) ;
2549
2518
2550
- let llfn = decl_fn ( ccx. llmod , sym, cc, fn_ty, output ) ;
2519
+ let llfn = decl_fn ( ccx. llmod , sym, cc, fn_ty) ;
2551
2520
finish_register_fn ( ccx, sp, sym, node_id, llfn) ;
2552
2521
llfn
2553
2522
}
@@ -2579,7 +2548,7 @@ pub fn create_entry_wrapper(ccx: @CrateContext,
2579
2548
let llfty = Type :: func ( [ ccx. int_type , Type :: i8 ( ) . ptr_to ( ) . ptr_to ( ) ] ,
2580
2549
& ccx. int_type ) ;
2581
2550
2582
- let llfn = decl_cdecl_fn ( ccx. llmod , "main" , llfty, ty :: mk_nil ( ) ) ;
2551
+ let llfn = decl_cdecl_fn ( ccx. llmod , "main" , llfty) ;
2583
2552
let llbb = "top" . with_c_str ( |buf| {
2584
2553
unsafe {
2585
2554
llvm:: LLVMAppendBasicBlockInContext ( ccx. llcx , llfn, buf)
@@ -2983,8 +2952,7 @@ pub fn p2i(ccx: &CrateContext, v: ValueRef) -> ValueRef {
2983
2952
macro_rules! ifn (
2984
2953
( $intrinsics: ident, $name: expr, $args: expr, $ret: expr) => ( {
2985
2954
let name = $name;
2986
- // HACK(eddyb) dummy output type, shouln't affect anything.
2987
- let f = decl_cdecl_fn( llmod, name, Type :: func( $args, & $ret) , ty:: mk_nil( ) ) ;
2955
+ let f = decl_cdecl_fn( llmod, name, Type :: func( $args, & $ret) ) ;
2988
2956
$intrinsics. insert( name, f) ;
2989
2957
} )
2990
2958
)
0 commit comments