@@ -51,8 +51,8 @@ use syntax::codemap::Span;
51
51
52
52
use std:: cmp:: Ordering ;
53
53
54
- pub fn get_simple_intrinsic ( ccx : & CrateContext , item : & hir :: ForeignItem ) -> Option < ValueRef > {
55
- let name = match & * item . name . as_str ( ) {
54
+ fn get_simple_intrinsic ( ccx : & CrateContext , name : & str ) -> Option < ValueRef > {
55
+ let llvm_name = match name {
56
56
"sqrtf32" => "llvm.sqrt.f32" ,
57
57
"sqrtf64" => "llvm.sqrt.f64" ,
58
58
"powif32" => "llvm.powi.f32" ,
@@ -94,7 +94,7 @@ pub fn get_simple_intrinsic(ccx: &CrateContext, item: &hir::ForeignItem) -> Opti
94
94
"assume" => "llvm.assume" ,
95
95
_ => return None
96
96
} ;
97
- Some ( ccx. get_intrinsic ( & name ) )
97
+ Some ( ccx. get_intrinsic ( & llvm_name ) )
98
98
}
99
99
100
100
pub fn span_transmute_size_error ( a : & Session , b : Span , msg : & str ) {
@@ -171,12 +171,10 @@ pub fn check_intrinsics(ccx: &CrateContext) {
171
171
/// and in libcore/intrinsics.rs; if you need access to any llvm intrinsics,
172
172
/// add them to librustc_trans/trans/context.rs
173
173
pub fn trans_intrinsic_call < ' a , ' blk , ' tcx > ( mut bcx : Block < ' blk , ' tcx > ,
174
- node : ast:: NodeId ,
175
174
callee_ty : Ty < ' tcx > ,
176
175
cleanup_scope : cleanup:: CustomScopeIndex ,
177
176
args : callee:: CallArgs < ' a , ' tcx > ,
178
177
dest : expr:: Dest ,
179
- substs : & ' tcx subst:: Substs < ' tcx > ,
180
178
call_info : NodeIdAndSpan )
181
179
-> Result < ' blk , ' tcx > {
182
180
let fcx = bcx. fcx ;
@@ -185,12 +183,16 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
185
183
186
184
let _icx = push_ctxt ( "trans_intrinsic_call" ) ;
187
185
188
- let sig = ccx. tcx ( ) . erase_late_bound_regions ( callee_ty. fn_sig ( ) ) ;
189
- let sig = infer:: normalize_associated_type ( ccx. tcx ( ) , & sig) ;
186
+ let ( def_id, substs, sig) = match callee_ty. sty {
187
+ ty:: TyFnDef ( def_id, substs, fty) => {
188
+ let sig = tcx. erase_late_bound_regions ( & fty. sig ) ;
189
+ ( def_id, substs, infer:: normalize_associated_type ( tcx, & sig) )
190
+ }
191
+ _ => unreachable ! ( "expected fn item type, found {}" , callee_ty)
192
+ } ;
190
193
let arg_tys = sig. inputs ;
191
194
let ret_ty = sig. output ;
192
- let foreign_item = tcx. map . expect_foreign_item ( node) ;
193
- let name = foreign_item. name . as_str ( ) ;
195
+ let name = tcx. item_name ( def_id) . as_str ( ) ;
194
196
195
197
let call_debug_location = DebugLoc :: At ( call_info. id , call_info. span ) ;
196
198
@@ -437,8 +439,8 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
437
439
}
438
440
} ;
439
441
440
- let simple = get_simple_intrinsic ( ccx, & foreign_item ) ;
441
- let llval = match ( simple, & * name) {
442
+ let simple = get_simple_intrinsic ( ccx, & name ) ;
443
+ let llval = match ( simple, & name[ .. ] ) {
442
444
( Some ( llfn) , _) => {
443
445
Call ( bcx, llfn, & llargs, None , call_debug_location)
444
446
}
@@ -815,8 +817,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
815
817
( _, _) => {
816
818
let intr = match Intrinsic :: find ( tcx, & name) {
817
819
Some ( intr) => intr,
818
- None => ccx. sess ( ) . span_bug ( foreign_item. span ,
819
- & format ! ( "unknown intrinsic '{}'" , name) ) ,
820
+ None => unreachable ! ( "unknown intrinsic '{}'" , name) ,
820
821
} ;
821
822
fn one < T > ( x : Vec < T > ) -> T {
822
823
assert_eq ! ( x. len( ) , 1 ) ;
0 commit comments