@@ -10,12 +10,12 @@ use rustc_data_structures::base_n::ToBaseN;
10
10
use rustc_data_structures:: base_n:: ALPHANUMERIC_ONLY ;
11
11
use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
12
12
use rustc_middle:: mir:: mono:: CodegenUnit ;
13
- use rustc_middle:: span_bug;
14
13
use rustc_middle:: ty:: layout:: {
15
14
FnAbiError , FnAbiOf , FnAbiOfHelpers , FnAbiRequest , HasParamEnv , HasTyCtxt , LayoutError ,
16
15
LayoutOfHelpers , TyAndLayout ,
17
16
} ;
18
17
use rustc_middle:: ty:: { self , Instance , ParamEnv , PolyExistentialTraitRef , Ty , TyCtxt } ;
18
+ use rustc_middle:: { bug, span_bug} ;
19
19
use rustc_session:: Session ;
20
20
use rustc_span:: { source_map:: respan, Span } ;
21
21
use rustc_target:: abi:: {
@@ -360,6 +360,31 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
360
360
function
361
361
}
362
362
363
+ pub fn get_matching_int_type ( & self , typ : Type < ' gcc > , signed : bool ) -> Type < ' gcc > {
364
+ let size = if typ. is_compatible_with ( self . bool_type ) {
365
+ // For booleans, return an 8-bit integer instead.
366
+ 1
367
+ } else {
368
+ typ. get_size ( )
369
+ } ;
370
+
371
+ match ( size, signed) {
372
+ ( 1 , false ) => self . u8_type ,
373
+ ( 2 , false ) => self . u16_type ,
374
+ ( 4 , false ) => self . u32_type ,
375
+ ( 8 , false ) => self . u64_type ,
376
+ ( 16 , false ) => self . u128_type ,
377
+ ( 1 , true ) => self . i8_type ,
378
+ ( 2 , true ) => self . i16_type ,
379
+ ( 4 , true ) => self . i32_type ,
380
+ ( 8 , true ) => self . i64_type ,
381
+ ( 16 , true ) => self . i128_type ,
382
+ _ => {
383
+ bug ! ( "attempt to get bad int type {}{}" , if signed { 'i' } else { 'u' } , size * 8 ) ;
384
+ }
385
+ }
386
+ }
387
+
363
388
pub fn is_native_int_type ( & self , typ : Type < ' gcc > ) -> bool {
364
389
let types = [
365
390
self . u8_type ,
0 commit comments