Skip to content

Commit 2479a9c

Browse files
Snehal-ReddyLegNeato
authored andcommitted
fix(nvvm): use PassMode::Cast for align(16) ADTs
1 parent 96e16c3 commit 2479a9c

File tree

1 file changed

+26
-2
lines changed
  • crates/rustc_codegen_nvvm/src

1 file changed

+26
-2
lines changed

crates/rustc_codegen_nvvm/src/abi.rs

Lines changed: 26 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,32 @@ pub(crate) fn readjust_fn_abi<'tcx>(
5959

6060
// pass all adts directly as values, ptx wants them to be passed all by value, but rustc's
6161
// ptx-kernel abi seems to be wrong, and it's unstable.
62-
if arg.layout.ty.is_adt() && !matches!(arg.mode, PassMode::Direct { .. }) {
63-
arg.mode = PassMode::Direct(ArgAttributes::new());
62+
if arg.layout.ty.is_adt() {
63+
let align = arg.layout.align.abi.bytes();
64+
if align >= 16 && align.is_power_of_two() {
65+
let unit = Reg {
66+
kind: RegKind::Integer,
67+
size: Size::from_bytes(16),
68+
};
69+
let cast = CastTarget {
70+
prefix: Default::default(),
71+
rest: rustc_target::callconv::Uniform {
72+
unit,
73+
total: arg.layout.size,
74+
is_consecutive: false,
75+
},
76+
rest_offset: Some(Size::ZERO),
77+
attrs: ArgAttributes::new(),
78+
};
79+
arg.mode = PassMode::Cast {
80+
cast: Box::new(cast),
81+
pad_i32: false,
82+
};
83+
} else if !matches!(arg.mode, PassMode::Direct { .. }) {
84+
let mut attrs = ArgAttributes::new();
85+
attrs.pointee_align = Some(arg.layout.align.abi);
86+
arg.mode = PassMode::Direct(attrs);
87+
}
6488
}
6589
arg
6690
};

0 commit comments

Comments
 (0)