@@ -10,12 +10,12 @@ use rustc_data_structures::base_n::ToBaseN;
1010use rustc_data_structures:: base_n:: ALPHANUMERIC_ONLY ;
1111use rustc_data_structures:: fx:: { FxHashMap , FxHashSet } ;
1212use rustc_middle:: mir:: mono:: CodegenUnit ;
13- use rustc_middle:: span_bug;
1413use rustc_middle:: ty:: layout:: {
1514 FnAbiError , FnAbiOf , FnAbiOfHelpers , FnAbiRequest , HasParamEnv , HasTyCtxt , LayoutError ,
1615 LayoutOfHelpers , TyAndLayout ,
1716} ;
1817use rustc_middle:: ty:: { self , Instance , ParamEnv , PolyExistentialTraitRef , Ty , TyCtxt } ;
18+ use rustc_middle:: { bug, span_bug} ;
1919use rustc_session:: Session ;
2020use rustc_span:: { source_map:: respan, Span } ;
2121use rustc_target:: abi:: {
@@ -360,6 +360,31 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
360360 function
361361 }
362362
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+
363388 pub fn is_native_int_type ( & self , typ : Type < ' gcc > ) -> bool {
364389 let types = [
365390 self . u8_type ,
0 commit comments