Skip to content

Commit 8900341

Browse files
committed
Move ArgAbi::pad_i32 into PassMode::Cast.
Because it's only needed for that variant. This shrinks the types and clarifies the logic.
1 parent d83636d commit 8900341

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/abi.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -117,19 +117,14 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
117117
match self.ret.mode {
118118
PassMode::Ignore => cx.type_void(),
119119
PassMode::Direct(_) | PassMode::Pair(..) => self.ret.layout.immediate_gcc_type(cx),
120-
PassMode::Cast(ref cast) => cast.gcc_type(cx),
120+
PassMode::Cast(ref cast, _) => cast.gcc_type(cx),
121121
PassMode::Indirect { .. } => {
122122
argument_tys.push(cx.type_ptr_to(self.ret.memory_ty(cx)));
123123
cx.type_void()
124124
}
125125
};
126126

127127
for arg in self.args.iter() {
128-
// add padding
129-
if arg.pad_i32 {
130-
argument_tys.push(Reg::i32().gcc_type(cx));
131-
}
132-
133128
let arg_ty = match arg.mode {
134129
PassMode::Ignore => continue,
135130
PassMode::Direct(_) => arg.layout.immediate_gcc_type(cx),
@@ -141,7 +136,13 @@ impl<'gcc, 'tcx> FnAbiGccExt<'gcc, 'tcx> for FnAbi<'tcx, Ty<'tcx>> {
141136
PassMode::Indirect { extra_attrs: Some(_), .. } => {
142137
unimplemented!();
143138
}
144-
PassMode::Cast(ref cast) => cast.gcc_type(cx),
139+
PassMode::Cast(ref cast, pad_i32) => {
140+
// add padding
141+
if pad_i32 {
142+
argument_tys.push(Reg::i32().gcc_type(cx));
143+
}
144+
cast.gcc_type(cx)
145+
}
145146
PassMode::Indirect { extra_attrs: None, on_stack: true, .. } => {
146147
on_stack_param_indices.insert(argument_tys.len());
147148
arg.memory_ty(cx)

src/intrinsic/mod.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
130130
sym::volatile_load | sym::unaligned_volatile_load => {
131131
let tp_ty = substs.type_at(0);
132132
let mut ptr = args[0].immediate();
133-
if let PassMode::Cast(ty) = &fn_abi.ret.mode {
133+
if let PassMode::Cast(ty, _) = &fn_abi.ret.mode {
134134
ptr = self.pointercast(ptr, self.type_ptr_to(ty.gcc_type(self)));
135135
}
136136
let load = self.volatile_load(ptr.get_type(), ptr);
@@ -320,7 +320,7 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallMethods<'tcx> for Builder<'a, 'gcc, 'tcx> {
320320
};
321321

322322
if !fn_abi.ret.is_ignore() {
323-
if let PassMode::Cast(ty) = &fn_abi.ret.mode {
323+
if let PassMode::Cast(ty, _) = &fn_abi.ret.mode {
324324
let ptr_llty = self.type_ptr_to(ty.gcc_type(self));
325325
let ptr = self.pointercast(result.llval, ptr_llty);
326326
self.store(llval, ptr, result.align);
@@ -416,7 +416,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
416416
else if self.is_unsized_indirect() {
417417
bug!("unsized `ArgAbi` must be handled through `store_fn_arg`");
418418
}
419-
else if let PassMode::Cast(ref cast) = self.mode {
419+
else if let PassMode::Cast(ref cast, _) = self.mode {
420420
// FIXME(eddyb): Figure out when the simpler Store is safe, clang
421421
// uses it for i16 -> {i8, i8}, but not for i24 -> {i8, i8, i8}.
422422
let can_store_through_cast_ptr = false;
@@ -481,7 +481,7 @@ impl<'gcc, 'tcx> ArgAbiExt<'gcc, 'tcx> for ArgAbi<'tcx, Ty<'tcx>> {
481481
PassMode::Indirect { extra_attrs: Some(_), .. } => {
482482
OperandValue::Ref(next(), Some(next()), self.layout.align.abi).store(bx, dst);
483483
},
484-
PassMode::Direct(_) | PassMode::Indirect { extra_attrs: None, .. } | PassMode::Cast(_) => {
484+
PassMode::Direct(_) | PassMode::Indirect { extra_attrs: None, .. } | PassMode::Cast(..) => {
485485
let next_arg = next();
486486
self.store(bx, next_arg, dst);
487487
},

0 commit comments

Comments
 (0)