Skip to content

Commit bd7e5b9

Browse files
committed
Fix bitcast with different sizes
1 parent 237be9e commit bd7e5b9

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/type_of.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,6 +182,7 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
182182
/// of that field's type - this is useful for taking the address of
183183
/// that field and ensuring the struct has the right alignment.
184184
fn gcc_type<'gcc>(&self, cx: &CodegenCx<'gcc, 'tcx>) -> Type<'gcc> {
185+
use crate::rustc_middle::ty::layout::FnAbiOf;
185186
// This must produce the same result for `repr(transparent)` wrappers as for the inner type!
186187
// In other words, this should generally not look at the type at all, but only at the
187188
// layout.
@@ -191,7 +192,14 @@ impl<'tcx> LayoutGccExt<'tcx> for TyAndLayout<'tcx> {
191192
if let Some(&ty) = cx.scalar_types.borrow().get(&self.ty) {
192193
return ty;
193194
}
194-
let ty = self.scalar_gcc_type_at(cx, scalar, Size::ZERO);
195+
let ty =
196+
match *self.ty.kind() {
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.
200+
ty::FnPtr(sig) => cx.fn_ptr_backend_type(&cx.fn_abi_of_fn_ptr(sig, ty::List::empty())),
201+
_ => self.scalar_gcc_type_at(cx, scalar, Size::ZERO),
202+
};
195203
cx.scalar_types.borrow_mut().insert(self.ty, ty);
196204
return ty;
197205
}

0 commit comments

Comments
 (0)