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.
This commit is contained in:
Veikka Tuominen 2022-10-21 17:51:54 +03:00
parent 972c39e2c0
commit 7622078127

View File

@ -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 };