Skip to content

Commit 53407dd

Browse files
committed
Fix PassMode::Indirect with params
1 parent ab7d138 commit 53407dd

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/abi.rs

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use gccjit::{ToLValue, ToRValue, Type};
44
use rustc_codegen_ssa::traits::{AbiBuilderMethods, BaseTypeMethods};
55
use rustc_data_structures::fx::FxHashSet;
66
use rustc_middle::bug;
7+
use rustc_middle::ty::layout::LayoutOf;
78
use rustc_middle::ty::Ty;
89
#[cfg(feature = "master")]
910
use rustc_session::config;
@@ -184,9 +185,22 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
184185
}
185186
PassMode::Indirect { attrs, meta_attrs: Some(meta_attrs), on_stack } => {
186187
assert!(!on_stack);
187-
let ty =
188-
apply_attrs(cx.type_ptr_to(arg.memory_ty(cx)), &attrs, argument_tys.len());
189-
apply_attrs(ty, &meta_attrs, argument_tys.len())
188+
// Construct the type of a (wide) pointer to `ty`, and pass its two fields.
189+
// Any two ABI-compatible unsized types have the same metadata type and
190+
// moreover the same metadata value leads to the same dynamic size and
191+
// alignment, so this respects ABI compatibility.
192+
let ptr_ty = Ty::new_mut_ptr(cx.tcx, arg.layout.ty);
193+
let ptr_layout = cx.layout_of(ptr_ty);
194+
let typ1 = ptr_layout.scalar_pair_element_gcc_type(cx, 0);
195+
let typ2 = ptr_layout.scalar_pair_element_gcc_type(cx, 1);
196+
// TODO: should I apply the attributes on both?
197+
let typ1 = apply_attrs(typ1, &attrs, argument_tys.len());
198+
let typ1 = apply_attrs(typ1, &meta_attrs, argument_tys.len());
199+
let typ2 = apply_attrs(typ2, &attrs, argument_tys.len());
200+
let typ2 = apply_attrs(typ2, &meta_attrs, argument_tys.len());
201+
argument_tys.push(typ1);
202+
argument_tys.push(typ2);
203+
continue;
190204
}
191205
};
192206
argument_tys.push(arg_ty);

0 commit comments

Comments
 (0)