authorgravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-21 17:51:54+03:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2022-10-21 17:51:54+03:00
log76220781279a2dc42572b7819a834aebb85eb354
tree8d75386c37c0d09f33948d3c9fef0c2ee85d0759
parent972c39e2c00c487a483bad002ef33ca1a5c21d02

aarc64 C ABI: fix handling of packed structs and unions

* Packed unions were not handled at all previously. * Packed unions and structs are integers so their floats should not be counted.

1 files changed, 8 insertions(+), 7 deletions(-)

src/arch/aarch64/abi.zig+8-7
......@@ -9,23 +9,24 @@ pub const Class = enum(u8) { memory, integer, none, float_array, _ };
99
1010/// For `float_array` the second element will be the amount of floats.
1111pub fn classifyType(ty: Type, target: std.Target) [2]Class {
12 var maybe_float_bits: ?u16 = null;
13 const float_count = countFloats(ty, target, &maybe_float_bits);
14 if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) };
15 return classifyTypeInner(ty, target);
16}
17
18fn classifyTypeInner(ty: Type, target: std.Target) [2]Class {
1912 if (!ty.hasRuntimeBitsIgnoreComptime()) return .{ .none, .none };
13 var maybe_float_bits: ?u16 = null;
2014 switch (ty.zigTypeTag()) {
2115 .Struct => {
2216 if (ty.containerLayout() == .Packed) return .{ .integer, .none };
17 const float_count = countFloats(ty, target, &maybe_float_bits);
18 if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) };
19
2320 const bit_size = ty.bitSize(target);
2421 if (bit_size > 128) return .{ .memory, .none };
2522 if (bit_size > 64) return .{ .integer, .integer };
2623 return .{ .integer, .none };
2724 },
2825 .Union => {
26 if (ty.containerLayout() == .Packed) return .{ .integer, .none };
27 const float_count = countFloats(ty, target, &maybe_float_bits);
28 if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) };
29
2930 const bit_size = ty.bitSize(target);
3031 if (bit_size > 128) return .{ .memory, .none };
3132 if (bit_size > 64) return .{ .integer, .integer };