Skip to content

Commit 0fde82f

Browse files
committed
codegen_llvm/llvm_type: avoid matching on the Rust type
1 parent b60f7b5 commit 0fde82f

File tree

1 file changed

+5
-9
lines changed

1 file changed

+5
-9
lines changed

compiler/rustc_codegen_llvm/src/type_of.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use crate::context::TypeLowering;
33
use crate::type_::Type;
44
use rustc_codegen_ssa::traits::*;
55
use rustc_middle::bug;
6-
use rustc_middle::ty::layout::{FnAbiOf, LayoutOf, TyAndLayout};
6+
use rustc_middle::ty::layout::{LayoutOf, TyAndLayout};
77
use rustc_middle::ty::print::{with_no_trimmed_paths, with_no_visible_paths};
88
use rustc_middle::ty::{self, Ty, TypeVisitableExt};
99
use rustc_target::abi::HasDataLayout;
@@ -215,20 +215,16 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
215215
/// of that field's type - this is useful for taking the address of
216216
/// that field and ensuring the struct has the right alignment.
217217
fn llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type {
218+
// This must produce the same result for `repr(transparent)` wrappers as for the inner type!
219+
// In other words, this should generally not look at the type at all, but only at the
220+
// layout.
218221
if let Abi::Scalar(scalar) = self.abi {
219222
// Use a different cache for scalars because pointers to DSTs
220223
// can be either fat or thin (data pointers of fat pointers).
221224
if let Some(&llty) = cx.scalar_lltypes.borrow().get(&self.ty) {
222225
return llty;
223226
}
224-
let llty = match *self.ty.kind() {
225-
ty::Ref(..) | ty::RawPtr(_) => cx.type_ptr(),
226-
ty::Adt(def, _) if def.is_box() => cx.type_ptr(),
227-
ty::FnPtr(sig) => {
228-
cx.fn_ptr_backend_type(cx.fn_abi_of_fn_ptr(sig, ty::List::empty()))
229-
}
230-
_ => self.scalar_llvm_type_at(cx, scalar),
231-
};
227+
let llty = self.scalar_llvm_type_at(cx, scalar);
232228
cx.scalar_lltypes.borrow_mut().insert(self.ty, llty);
233229
return llty;
234230
}

0 commit comments

Comments
 (0)