@@ -4,7 +4,7 @@ use gccjit::{Struct, Type};
4
4
use crate :: rustc_codegen_ssa:: traits:: { BaseTypeMethods , DerivedTypeMethods , LayoutTypeMethods } ;
5
5
use rustc_middle:: bug;
6
6
use rustc_middle:: ty:: { self , Ty , TypeVisitableExt } ;
7
- use rustc_middle:: ty:: layout:: { FnAbiOf , LayoutOf , TyAndLayout } ;
7
+ use rustc_middle:: ty:: layout:: { LayoutOf , TyAndLayout } ;
8
8
use rustc_middle:: ty:: print:: with_no_trimmed_paths;
9
9
use rustc_target:: abi:: { self , Abi , Align , F32 , F64 , FieldsShape , Int , Integer , Pointer , PointeeInfo , Size , TyAbiInterface , Variants } ;
10
10
use rustc_target:: abi:: call:: { CastTarget , FnAbi , Reg } ;
@@ -74,8 +74,8 @@ fn uncached_gcc_type<'gcc, 'tcx>(cx: &CodegenCx<'gcc, 'tcx>, layout: TyAndLayout
74
74
Abi :: ScalarPair ( ..) => {
75
75
return cx. type_struct (
76
76
& [
77
- layout. scalar_pair_element_gcc_type ( cx, 0 , false ) ,
78
- layout. scalar_pair_element_gcc_type ( cx, 1 , false ) ,
77
+ layout. scalar_pair_element_gcc_type ( cx, 0 ) ,
78
+ layout. scalar_pair_element_gcc_type ( cx, 1 ) ,
79
79
] ,
80
80
false ,
81
81
) ;
@@ -150,7 +150,7 @@ pub trait LayoutGccExt<'tcx> {
150
150
fn gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Type < ' gcc > ;
151
151
fn immediate_gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Type < ' gcc > ;
152
152
fn scalar_gcc_type_at < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' tcx > , scalar : & abi:: Scalar , offset : Size ) -> Type < ' gcc > ;
153
- fn scalar_pair_element_gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' tcx > , index : usize , immediate : bool ) -> Type < ' gcc > ;
153
+ fn scalar_pair_element_gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' tcx > , index : usize ) -> Type < ' gcc > ;
154
154
fn gcc_field_index ( & self , index : usize ) -> u64 ;
155
155
fn pointee_info_at < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' tcx > , offset : Size ) -> Option < PointeeInfo > ;
156
156
}
@@ -182,6 +182,10 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
182
182
/// of that field's type - this is useful for taking the address of
183
183
/// that field and ensuring the struct has the right alignment.
184
184
fn gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' tcx > ) -> Type < ' gcc > {
185
+ use crate :: rustc_middle:: ty:: layout:: FnAbiOf ;
186
+ // This must produce the same result for `repr(transparent)` wrappers as for the inner type!
187
+ // In other words, this should generally not look at the type at all, but only at the
188
+ // layout.
185
189
if let Abi :: Scalar ( ref scalar) = self . abi {
186
190
// Use a different cache for scalars because pointers to DSTs
187
191
// can be either fat or thin (data pointers of fat pointers).
@@ -190,12 +194,9 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
190
194
}
191
195
let ty =
192
196
match * self . ty . kind ( ) {
193
- ty:: Ref ( _, ty, _) | ty:: RawPtr ( ty:: TypeAndMut { ty, .. } ) => {
194
- cx. type_ptr_to ( cx. layout_of ( ty) . gcc_type ( cx) )
195
- }
196
- ty:: Adt ( def, _) if def. is_box ( ) => {
197
- cx. type_ptr_to ( cx. layout_of ( self . ty . boxed_ty ( ) ) . gcc_type ( cx) )
198
- }
197
+ // NOTE: we cannot remove this match like in the LLVM codegen because the call
198
+ // to fn_ptr_backend_type handle the on-stack attribute.
199
+ // TODO(antoyo): find a less hackish way to hande the on-stack attribute.
199
200
ty:: FnPtr ( sig) => cx. fn_ptr_backend_type ( & cx. fn_abi_of_fn_ptr ( sig, ty:: List :: empty ( ) ) ) ,
200
201
_ => self . scalar_gcc_type_at ( cx, scalar, Size :: ZERO ) ,
201
202
} ;
@@ -272,23 +273,10 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
272
273
}
273
274
}
274
275
275
- fn scalar_pair_element_gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' tcx > , index : usize , immediate : bool ) -> Type < ' gcc > {
276
- // TODO(antoyo): remove llvm hack:
277
- // HACK(eddyb) special-case fat pointers until LLVM removes
278
- // pointee types, to avoid bitcasting every `OperandRef::deref`.
279
- match self . ty . kind ( ) {
280
- ty:: Ref ( ..) | ty:: RawPtr ( _) => {
281
- return self . field ( cx, index) . gcc_type ( cx) ;
282
- }
283
- // only wide pointer boxes are handled as pointers
284
- // thin pointer boxes with scalar allocators are handled by the general logic below
285
- ty:: Adt ( def, args) if def. is_box ( ) && cx. layout_of ( args. type_at ( 1 ) ) . is_zst ( ) => {
286
- let ptr_ty = Ty :: new_mut_ptr ( cx. tcx , self . ty . boxed_ty ( ) ) ;
287
- return cx. layout_of ( ptr_ty) . scalar_pair_element_gcc_type ( cx, index, immediate) ;
288
- }
289
- _ => { }
290
- }
291
-
276
+ fn scalar_pair_element_gcc_type < ' gcc > ( & self , cx : & CodegenCx < ' gcc , ' tcx > , index : usize ) -> Type < ' gcc > {
277
+ // This must produce the same result for `repr(transparent)` wrappers as for the inner type!
278
+ // In other words, this should generally not look at the type at all, but only at the
279
+ // layout.
292
280
let ( a, b) = match self . abi {
293
281
Abi :: ScalarPair ( ref a, ref b) => ( a, b) ,
294
282
_ => bug ! ( "TyAndLayout::scalar_pair_element_llty({:?}): not applicable" , self ) ,
@@ -367,8 +355,8 @@ impl<'gcc, 'tcx> LayoutTypeMethods<'tcx> for CodegenCx<'gcc, 'tcx> {
367
355
layout. gcc_field_index ( index)
368
356
}
369
357
370
- fn scalar_pair_element_backend_type ( & self , layout : TyAndLayout < ' tcx > , index : usize , immediate : bool ) -> Type < ' gcc > {
371
- layout. scalar_pair_element_gcc_type ( self , index, immediate )
358
+ fn scalar_pair_element_backend_type ( & self , layout : TyAndLayout < ' tcx > , index : usize , _immediate : bool ) -> Type < ' gcc > {
359
+ layout. scalar_pair_element_gcc_type ( self , index)
372
360
}
373
361
374
362
fn cast_backend_type ( & self , ty : & CastTarget ) -> Type < ' gcc > {
0 commit comments