@@ -150,17 +150,18 @@ impl FnType {
150
150
abi : Abi ,
151
151
sig : & ty:: FnSig < ' tcx > ,
152
152
extra_args : & [ Ty < ' tcx > ] ) -> FnType {
153
+ let mut fn_ty = FnType :: unadjusted ( ccx, abi, sig, extra_args) ;
154
+ fn_ty. adjust_for_abi ( ccx, abi, sig) ;
155
+ fn_ty
156
+ }
157
+
158
+ pub fn unadjusted < ' a , ' tcx > ( ccx : & CrateContext < ' a , ' tcx > ,
159
+ abi : Abi ,
160
+ sig : & ty:: FnSig < ' tcx > ,
161
+ extra_args : & [ Ty < ' tcx > ] ) -> FnType {
153
162
use self :: Abi :: * ;
154
163
let cconv = match ccx. sess ( ) . target . target . adjust_abi ( abi) {
155
- RustIntrinsic => {
156
- // Intrinsics are emitted at the call site
157
- ccx. sess ( ) . bug ( "asked to compute FnType of intrinsic" ) ;
158
- }
159
- PlatformIntrinsic => {
160
- // Intrinsics are emitted at the call site
161
- ccx. sess ( ) . bug ( "asked to compute FnType of platform intrinsic" ) ;
162
- }
163
-
164
+ RustIntrinsic | PlatformIntrinsic |
164
165
Rust | RustCall => llvm:: CCallConv ,
165
166
166
167
// It's the ABI's job to select this, not us.
@@ -309,14 +310,20 @@ impl FnType {
309
310
}
310
311
}
311
312
312
- let mut fty = FnType {
313
+ FnType {
313
314
args : args,
314
315
ret : ret,
315
316
variadic : sig. variadic ,
316
317
cconv : cconv
317
- } ;
318
+ }
319
+ }
318
320
319
- if abi == Rust || abi == RustCall {
321
+ pub fn adjust_for_abi < ' a , ' tcx > ( & mut self ,
322
+ ccx : & CrateContext < ' a , ' tcx > ,
323
+ abi : Abi ,
324
+ sig : & ty:: FnSig < ' tcx > ) {
325
+ if abi == Abi :: Rust || abi == Abi :: RustCall ||
326
+ abi == Abi :: RustIntrinsic || abi == Abi :: PlatformIntrinsic {
320
327
let fixup = |arg : & mut ArgType | {
321
328
if !arg. ty . is_aggregate ( ) {
322
329
// Scalars and vectors, always immediate.
@@ -332,49 +339,48 @@ impl FnType {
332
339
arg. cast = Some ( Type :: ix ( ccx, size * 8 ) ) ;
333
340
}
334
341
} ;
335
- if fty . ret . ty != Type :: void ( ccx ) {
336
- // Fat pointers are returned by-value.
342
+ // Fat pointers are returned by-value.
343
+ if ! self . ret . is_ignore ( ) {
337
344
if !type_is_fat_ptr ( ccx. tcx ( ) , sig. output . unwrap ( ) ) {
338
- fixup ( & mut fty . ret ) ;
345
+ fixup ( & mut self . ret ) ;
339
346
}
340
347
}
341
- for arg in & mut fty. args {
348
+ for arg in & mut self . args {
349
+ if arg. is_ignore ( ) { continue ; }
342
350
fixup ( arg) ;
343
351
}
344
- if fty . ret . is_indirect ( ) {
345
- fty . ret . attrs . set ( llvm:: Attribute :: StructRet ) ;
352
+ if self . ret . is_indirect ( ) {
353
+ self . ret . attrs . set ( llvm:: Attribute :: StructRet ) ;
346
354
}
347
- return fty ;
355
+ return ;
348
356
}
349
357
350
358
match & ccx. sess ( ) . target . target . arch [ ..] {
351
- "x86" => cabi_x86:: compute_abi_info ( ccx, & mut fty ) ,
359
+ "x86" => cabi_x86:: compute_abi_info ( ccx, self ) ,
352
360
"x86_64" => if ccx. sess ( ) . target . target . options . is_like_windows {
353
- cabi_x86_win64:: compute_abi_info ( ccx, & mut fty ) ;
361
+ cabi_x86_win64:: compute_abi_info ( ccx, self ) ;
354
362
} else {
355
- cabi_x86_64:: compute_abi_info ( ccx, & mut fty ) ;
363
+ cabi_x86_64:: compute_abi_info ( ccx, self ) ;
356
364
} ,
357
- "aarch64" => cabi_aarch64:: compute_abi_info ( ccx, & mut fty ) ,
365
+ "aarch64" => cabi_aarch64:: compute_abi_info ( ccx, self ) ,
358
366
"arm" => {
359
367
let flavor = if ccx. sess ( ) . target . target . target_os == "ios" {
360
368
cabi_arm:: Flavor :: Ios
361
369
} else {
362
370
cabi_arm:: Flavor :: General
363
371
} ;
364
- cabi_arm:: compute_abi_info ( ccx, & mut fty , flavor) ;
372
+ cabi_arm:: compute_abi_info ( ccx, self , flavor) ;
365
373
} ,
366
- "mips" => cabi_mips:: compute_abi_info ( ccx, & mut fty ) ,
367
- "powerpc" => cabi_powerpc:: compute_abi_info ( ccx, & mut fty ) ,
368
- "powerpc64" => cabi_powerpc64:: compute_abi_info ( ccx, & mut fty ) ,
369
- "asmjs" => cabi_asmjs:: compute_abi_info ( ccx, & mut fty ) ,
374
+ "mips" => cabi_mips:: compute_abi_info ( ccx, self ) ,
375
+ "powerpc" => cabi_powerpc:: compute_abi_info ( ccx, self ) ,
376
+ "powerpc64" => cabi_powerpc64:: compute_abi_info ( ccx, self ) ,
377
+ "asmjs" => cabi_asmjs:: compute_abi_info ( ccx, self ) ,
370
378
a => ccx. sess ( ) . fatal ( & format ! ( "unrecognized arch \" {}\" in target specification" , a) )
371
379
}
372
380
373
- if fty . ret . is_indirect ( ) {
374
- fty . ret . attrs . set ( llvm:: Attribute :: StructRet ) ;
381
+ if self . ret . is_indirect ( ) {
382
+ self . ret . attrs . set ( llvm:: Attribute :: StructRet ) ;
375
383
}
376
-
377
- fty
378
384
}
379
385
380
386
pub fn llvm_type ( & self , ccx : & CrateContext ) -> Type {
0 commit comments