|
34 | 34 | } |
35 | 35 | } |
36 | 36 |
|
37 | | -fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>) |
| 37 | +fn classify_ret<'a, Ty, C>(cx: &C, ret: &mut ArgAbi<'a, Ty>, offset: &mut Size) |
38 | 38 | where |
39 | 39 | Ty: TyAbiInterface<'a, C> + Copy, |
40 | 40 | C: HasDataLayout, |
@@ -70,10 +70,11 @@ where |
70 | 70 | ret.cast_to(Uniform::new(Reg::i64(), size)); |
71 | 71 | } else { |
72 | 72 | ret.make_indirect(); |
| 73 | + *offset += cx.data_layout().pointer_size(); |
73 | 74 | } |
74 | 75 | } |
75 | 76 |
|
76 | | -fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) |
| 77 | +fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>, offset: &mut Size) |
77 | 78 | where |
78 | 79 | Ty: TyAbiInterface<'a, C> + Copy, |
79 | 80 | C: HasDataLayout, |
@@ -134,24 +135,36 @@ where |
134 | 135 | } |
135 | 136 | }; |
136 | 137 |
|
| 138 | + // Detect need for padding |
| 139 | + let align = arg.layout.align.abi.max(dl.i64_align).min(dl.i128_align); |
| 140 | + let pad_i32 = !offset.is_aligned(align); |
137 | 141 | // Extract first 8 chunks as the prefix |
138 | 142 | let rest_size = size - Size::from_bytes(8) * prefix_index as u64; |
139 | | - arg.cast_to(CastTarget::prefixed(prefix, Uniform::new(Reg::i64(), rest_size))); |
| 143 | + // FIXME: an i32 padding is generated while clang uses i64 |
| 144 | + arg.cast_to_and_pad_i32( |
| 145 | + CastTarget::prefixed(prefix, Uniform::new(Reg::i64(), rest_size)), |
| 146 | + pad_i32, |
| 147 | + ); |
| 148 | + *offset = offset.align_to(align) + size.align_to(align); |
140 | 149 | } |
141 | 150 |
|
142 | 151 | pub(crate) fn compute_abi_info<'a, Ty, C>(cx: &C, fn_abi: &mut FnAbi<'a, Ty>) |
143 | 152 | where |
144 | 153 | Ty: TyAbiInterface<'a, C> + Copy, |
145 | 154 | C: HasDataLayout, |
146 | 155 | { |
| 156 | + // mips64 argument passing is also affected by the alignment of aggregates. |
| 157 | + // see mips.rs for how the offset is used |
| 158 | + let mut offset = Size::ZERO; |
| 159 | + |
147 | 160 | if !fn_abi.ret.is_ignore() { |
148 | | - classify_ret(cx, &mut fn_abi.ret); |
| 161 | + classify_ret(cx, &mut fn_abi.ret, &mut offset); |
149 | 162 | } |
150 | 163 |
|
151 | 164 | for arg in fn_abi.args.iter_mut() { |
152 | 165 | if arg.is_ignore() { |
153 | 166 | continue; |
154 | 167 | } |
155 | | - classify_arg(cx, arg); |
| 168 | + classify_arg(cx, arg, &mut offset); |
156 | 169 | } |
157 | 170 | } |
0 commit comments