Skip to content

Commit e82cc65

Browse files
Make dyn* have the same scalar pair ABI as corresponding fat pointer
1 parent 1f11d84 commit e82cc65

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/rustc_codegen_llvm/src/type_of.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,7 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
329329
) -> &'a Type {
330330
// HACK(eddyb) special-case fat pointers until LLVM removes
331331
// pointee types, to avoid bitcasting every `OperandRef::deref`.
332-
match self.ty.kind() {
332+
match *self.ty.kind() {
333333
ty::Ref(..) | ty::RawPtr(_) => {
334334
return self.field(cx, index).llvm_type(cx);
335335
}
@@ -339,6 +339,11 @@ impl<'tcx> LayoutLlvmExt<'tcx> for TyAndLayout<'tcx> {
339339
let ptr_ty = cx.tcx.mk_mut_ptr(self.ty.boxed_ty());
340340
return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate);
341341
}
342+
// `dyn* Trait` has the same ABI as `*mut dyn Trait`
343+
ty::Dynamic(bounds, region, ty::DynStar) => {
344+
let ptr_ty = cx.tcx.mk_mut_ptr(cx.tcx.mk_dynamic(bounds, region, ty::Dyn));
345+
return cx.layout_of(ptr_ty).scalar_pair_element_llvm_type(cx, index, immediate);
346+
}
342347
_ => {}
343348
}
344349

tests/codegen/function-arguments.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,9 @@ pub fn enum_id_2(x: Option<u8>) -> Option<u8> {
281281
x
282282
}
283283

284-
// CHECK: { {{i8\*|ptr}}, {{i.*\*|ptr}} } @dyn_star({{i8\*|ptr}} noundef %x.0, {{i.*\*|ptr}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %x.1)
284+
// CHECK: { {{\{\}\*|ptr}}, {{.+}} } @dyn_star({{\{\}\*|ptr}} noundef %x.0, {{.+}} noalias noundef readonly align {{.*}} dereferenceable({{.*}}) %x.1)
285+
// Expect an ABI something like `{ {}*, [3 x i64]* }`, but that's hard to match on generically,
286+
// so do like the `trait_box` test and just match on `{{.+}}` for the vtable.
285287
#[no_mangle]
286288
pub fn dyn_star(x: dyn* Drop) -> dyn* Drop {
287289
x

0 commit comments

Comments
 (0)