@@ -129,19 +129,39 @@ impl<'gcc, 'tcx> CodegenCx<'gcc, 'tcx> {
129
129
pub fn new ( context : & ' gcc Context < ' gcc > , codegen_unit : & ' tcx CodegenUnit < ' tcx > , tcx : TyCtxt < ' tcx > , supports_128bit_integers : bool ) -> Self {
130
130
let check_overflow = tcx. sess . overflow_checks ( ) ;
131
131
132
- let i8_type = context. new_c_type ( CType :: Int8t ) ;
133
- let i16_type = context. new_c_type ( CType :: Int16t ) ;
134
- let i32_type = context. new_c_type ( CType :: Int32t ) ;
135
- let i64_type = context. new_c_type ( CType :: Int64t ) ;
136
- let u8_type = context. new_c_type ( CType :: UInt8t ) ;
137
- let u16_type = context. new_c_type ( CType :: UInt16t ) ;
138
- let u32_type = context. new_c_type ( CType :: UInt32t ) ;
139
- let u64_type = context. new_c_type ( CType :: UInt64t ) ;
132
+ let create_type = |ctype, rust_type| {
133
+ let layout = tcx. layout_of ( ParamEnv :: reveal_all ( ) . and ( rust_type) ) . unwrap ( ) ;
134
+ let align = layout. align . abi . bytes ( ) ;
135
+ #[ cfg( feature="master" ) ]
136
+ {
137
+ context. new_c_type ( ctype) . get_aligned ( align)
138
+ }
139
+ #[ cfg( not( feature="master" ) ) ]
140
+ {
141
+ // Since libgccjit 12 doesn't contain the fix to compare aligned integer types,
142
+ // only align u128 and i128.
143
+ if layout. ty . int_size_and_signed ( tcx) . 0 . bytes ( ) == 16 {
144
+ context. new_c_type ( ctype) . get_aligned ( align)
145
+ }
146
+ else {
147
+ context. new_c_type ( ctype)
148
+ }
149
+ }
150
+ } ;
151
+
152
+ let i8_type = create_type ( CType :: Int8t , tcx. types . i8 ) ;
153
+ let i16_type = create_type ( CType :: Int16t , tcx. types . i16 ) ;
154
+ let i32_type = create_type ( CType :: Int32t , tcx. types . i32 ) ;
155
+ let i64_type = create_type ( CType :: Int64t , tcx. types . i64 ) ;
156
+ let u8_type = create_type ( CType :: UInt8t , tcx. types . u8 ) ;
157
+ let u16_type = create_type ( CType :: UInt16t , tcx. types . u16 ) ;
158
+ let u32_type = create_type ( CType :: UInt32t , tcx. types . u32 ) ;
159
+ let u64_type = create_type ( CType :: UInt64t , tcx. types . u64 ) ;
140
160
141
161
let ( i128_type, u128_type) =
142
162
if supports_128bit_integers {
143
- let i128_type = context . new_c_type ( CType :: Int128t ) . get_aligned ( 8 ) ; // TODO(antoyo): should the alignment be hard-coded? ;
144
- let u128_type = context . new_c_type ( CType :: UInt128t ) . get_aligned ( 8 ) ; // TODO(antoyo): should the alignment be hard-coded? ;
163
+ let i128_type = create_type ( CType :: Int128t , tcx . types . i128 ) ;
164
+ let u128_type = create_type ( CType :: UInt128t , tcx . types . u128 ) ;
145
165
( i128_type, u128_type)
146
166
}
147
167
else {
0 commit comments