From 76220781279a2dc42572b7819a834aebb85eb354 Mon Sep 17 00:00:00 2001 From: Veikka Tuominen Date: Fri, 21 Oct 2022 17:51:54 +0300 Subject: [PATCH] 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. --- src/arch/aarch64/abi.zig | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/src/arch/aarch64/abi.zig b/src/arch/aarch64/abi.zig index 7c92d4e91c..57343ee4b1 100644 --- a/src/arch/aarch64/abi.zig +++ b/src/arch/aarch64/abi.zig @@ -9,23 +9,24 @@ pub const Class = enum(u8) { memory, integer, none, float_array, _ }; /// For `float_array` the second element will be the amount of floats. pub fn classifyType(ty: Type, target: std.Target) [2]Class { - var maybe_float_bits: ?u16 = null; - const float_count = countFloats(ty, target, &maybe_float_bits); - if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) }; - return classifyTypeInner(ty, target); -} - -fn classifyTypeInner(ty: Type, target: std.Target) [2]Class { if (!ty.hasRuntimeBitsIgnoreComptime()) return .{ .none, .none }; + var maybe_float_bits: ?u16 = null; switch (ty.zigTypeTag()) { .Struct => { if (ty.containerLayout() == .Packed) return .{ .integer, .none }; + const float_count = countFloats(ty, target, &maybe_float_bits); + if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) }; + const bit_size = ty.bitSize(target); if (bit_size > 128) return .{ .memory, .none }; if (bit_size > 64) return .{ .integer, .integer }; return .{ .integer, .none }; }, .Union => { + if (ty.containerLayout() == .Packed) return .{ .integer, .none }; + const float_count = countFloats(ty, target, &maybe_float_bits); + if (float_count <= sret_float_count) return .{ .float_array, @intToEnum(Class, float_count) }; + const bit_size = ty.bitSize(target); if (bit_size > 128) return .{ .memory, .none }; if (bit_size > 64) return .{ .integer, .integer };