authorgravatar for jacobly@ziglang.orgJacob Young <jacobly@ziglang.org> 2024-04-21 19:12:59-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-04-22 15:24:29-07:00
log5d745d94fbe30334ce0695cdf7118fb526313aed
tree315552d71d9eadb31d3de40c0910f590680f0267
parent6fd09f8d2d50525e3f58213e44f815ed577c2864

x86_64: fix C abi for unions

Closes #19721

9 files changed, 386 insertions(+), 385 deletions(-)

src/InternPool.zig+32-32
......@@ -1921,7 +1921,7 @@ pub const LoadedUnionType = struct {
19211921 return self.flagsPtr(ip).layout;
19221922 }
19231923
1924 pub fn fieldAlign(self: LoadedUnionType, ip: *const InternPool, field_index: u32) Alignment {
1924 pub fn fieldAlign(self: LoadedUnionType, ip: *const InternPool, field_index: usize) Alignment {
19251925 if (self.field_aligns.len == 0) return .none;
19261926 return self.field_aligns.get(ip)[field_index];
19271927 }
......@@ -2087,41 +2087,41 @@ pub const LoadedStructType = struct {
20872087
20882088 /// Returns the already-existing field with the same name, if any.
20892089 pub fn addFieldName(
2090 self: @This(),
2090 self: LoadedStructType,
20912091 ip: *InternPool,
20922092 name: NullTerminatedString,
20932093 ) ?u32 {
20942094 return ip.addFieldName(self.names_map.unwrap().?, self.field_names.start, name);
20952095 }
20962096
2097 pub fn fieldAlign(s: @This(), ip: *const InternPool, i: usize) Alignment {
2097 pub fn fieldAlign(s: LoadedStructType, ip: *const InternPool, i: usize) Alignment {
20982098 if (s.field_aligns.len == 0) return .none;
20992099 return s.field_aligns.get(ip)[i];
21002100 }
21012101
2102 pub fn fieldInit(s: @This(), ip: *const InternPool, i: usize) Index {
2102 pub fn fieldInit(s: LoadedStructType, ip: *const InternPool, i: usize) Index {
21032103 if (s.field_inits.len == 0) return .none;
21042104 assert(s.haveFieldInits(ip));
21052105 return s.field_inits.get(ip)[i];
21062106 }
21072107
21082108 /// Returns `none` in the case the struct is a tuple.
2109 pub fn fieldName(s: @This(), ip: *const InternPool, i: usize) OptionalNullTerminatedString {
2109 pub fn fieldName(s: LoadedStructType, ip: *const InternPool, i: usize) OptionalNullTerminatedString {
21102110 if (s.field_names.len == 0) return .none;
21112111 return s.field_names.get(ip)[i].toOptional();
21122112 }
21132113
2114 pub fn fieldIsComptime(s: @This(), ip: *const InternPool, i: usize) bool {
2114 pub fn fieldIsComptime(s: LoadedStructType, ip: *const InternPool, i: usize) bool {
21152115 return s.comptime_bits.getBit(ip, i);
21162116 }
21172117
2118 pub fn setFieldComptime(s: @This(), ip: *InternPool, i: usize) void {
2118 pub fn setFieldComptime(s: LoadedStructType, ip: *InternPool, i: usize) void {
21192119 s.comptime_bits.setBit(ip, i);
21202120 }
21212121
21222122 /// Reads the non-opv flag calculated during AstGen. Used to short-circuit more
21232123 /// complicated logic.
2124 pub fn knownNonOpv(s: @This(), ip: *InternPool) bool {
2124 pub fn knownNonOpv(s: LoadedStructType, ip: *InternPool) bool {
21252125 return switch (s.layout) {
21262126 .@"packed" => false,
21272127 .auto, .@"extern" => s.flagsPtr(ip).known_non_opv,
......@@ -2130,7 +2130,7 @@ pub const LoadedStructType = struct {
21302130
21312131 /// The returned pointer expires with any addition to the `InternPool`.
21322132 /// Asserts the struct is not packed.
2133 pub fn flagsPtr(self: @This(), ip: *const InternPool) *Tag.TypeStruct.Flags {
2133 pub fn flagsPtr(self: LoadedStructType, ip: *const InternPool) *Tag.TypeStruct.Flags {
21342134 assert(self.layout != .@"packed");
21352135 const flags_field_index = std.meta.fieldIndex(Tag.TypeStruct, "flags").?;
21362136 return @ptrCast(&ip.extra.items[self.extra_index + flags_field_index]);
......@@ -2138,13 +2138,13 @@ pub const LoadedStructType = struct {
21382138
21392139 /// The returned pointer expires with any addition to the `InternPool`.
21402140 /// Asserts that the struct is packed.
2141 pub fn packedFlagsPtr(self: @This(), ip: *const InternPool) *Tag.TypeStructPacked.Flags {
2141 pub fn packedFlagsPtr(self: LoadedStructType, ip: *const InternPool) *Tag.TypeStructPacked.Flags {
21422142 assert(self.layout == .@"packed");
21432143 const flags_field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "flags").?;
21442144 return @ptrCast(&ip.extra.items[self.extra_index + flags_field_index]);
21452145 }
21462146
2147 pub fn assumeRuntimeBitsIfFieldTypesWip(s: @This(), ip: *InternPool) bool {
2147 pub fn assumeRuntimeBitsIfFieldTypesWip(s: LoadedStructType, ip: *InternPool) bool {
21482148 if (s.layout == .@"packed") return false;
21492149 const flags_ptr = s.flagsPtr(ip);
21502150 if (flags_ptr.field_types_wip) {
......@@ -2154,7 +2154,7 @@ pub const LoadedStructType = struct {
21542154 return false;
21552155 }
21562156
2157 pub fn setTypesWip(s: @This(), ip: *InternPool) bool {
2157 pub fn setTypesWip(s: LoadedStructType, ip: *InternPool) bool {
21582158 if (s.layout == .@"packed") return false;
21592159 const flags_ptr = s.flagsPtr(ip);
21602160 if (flags_ptr.field_types_wip) return true;
......@@ -2162,12 +2162,12 @@ pub const LoadedStructType = struct {
21622162 return false;
21632163 }
21642164
2165 pub fn clearTypesWip(s: @This(), ip: *InternPool) void {
2165 pub fn clearTypesWip(s: LoadedStructType, ip: *InternPool) void {
21662166 if (s.layout == .@"packed") return;
21672167 s.flagsPtr(ip).field_types_wip = false;
21682168 }
21692169
2170 pub fn setLayoutWip(s: @This(), ip: *InternPool) bool {
2170 pub fn setLayoutWip(s: LoadedStructType, ip: *InternPool) bool {
21712171 if (s.layout == .@"packed") return false;
21722172 const flags_ptr = s.flagsPtr(ip);
21732173 if (flags_ptr.layout_wip) return true;
......@@ -2175,12 +2175,12 @@ pub const LoadedStructType = struct {
21752175 return false;
21762176 }
21772177
2178 pub fn clearLayoutWip(s: @This(), ip: *InternPool) void {
2178 pub fn clearLayoutWip(s: LoadedStructType, ip: *InternPool) void {
21792179 if (s.layout == .@"packed") return;
21802180 s.flagsPtr(ip).layout_wip = false;
21812181 }
21822182
2183 pub fn setAlignmentWip(s: @This(), ip: *InternPool) bool {
2183 pub fn setAlignmentWip(s: LoadedStructType, ip: *InternPool) bool {
21842184 if (s.layout == .@"packed") return false;
21852185 const flags_ptr = s.flagsPtr(ip);
21862186 if (flags_ptr.alignment_wip) return true;
......@@ -2188,12 +2188,12 @@ pub const LoadedStructType = struct {
21882188 return false;
21892189 }
21902190
2191 pub fn clearAlignmentWip(s: @This(), ip: *InternPool) void {
2191 pub fn clearAlignmentWip(s: LoadedStructType, ip: *InternPool) void {
21922192 if (s.layout == .@"packed") return;
21932193 s.flagsPtr(ip).alignment_wip = false;
21942194 }
21952195
2196 pub fn setInitsWip(s: @This(), ip: *InternPool) bool {
2196 pub fn setInitsWip(s: LoadedStructType, ip: *InternPool) bool {
21972197 switch (s.layout) {
21982198 .@"packed" => {
21992199 const flag = &s.packedFlagsPtr(ip).field_inits_wip;
......@@ -2210,14 +2210,14 @@ pub const LoadedStructType = struct {
22102210 }
22112211 }
22122212
2213 pub fn clearInitsWip(s: @This(), ip: *InternPool) void {
2213 pub fn clearInitsWip(s: LoadedStructType, ip: *InternPool) void {
22142214 switch (s.layout) {
22152215 .@"packed" => s.packedFlagsPtr(ip).field_inits_wip = false,
22162216 .auto, .@"extern" => s.flagsPtr(ip).field_inits_wip = false,
22172217 }
22182218 }
22192219
2220 pub fn setFullyResolved(s: @This(), ip: *InternPool) bool {
2220 pub fn setFullyResolved(s: LoadedStructType, ip: *InternPool) bool {
22212221 if (s.layout == .@"packed") return true;
22222222 const flags_ptr = s.flagsPtr(ip);
22232223 if (flags_ptr.fully_resolved) return true;
......@@ -2225,13 +2225,13 @@ pub const LoadedStructType = struct {
22252225 return false;
22262226 }
22272227
2228 pub fn clearFullyResolved(s: @This(), ip: *InternPool) void {
2228 pub fn clearFullyResolved(s: LoadedStructType, ip: *InternPool) void {
22292229 s.flagsPtr(ip).fully_resolved = false;
22302230 }
22312231
22322232 /// The returned pointer expires with any addition to the `InternPool`.
22332233 /// Asserts the struct is not packed.
2234 pub fn size(self: @This(), ip: *InternPool) *u32 {
2234 pub fn size(self: LoadedStructType, ip: *InternPool) *u32 {
22352235 assert(self.layout != .@"packed");
22362236 const size_field_index = std.meta.fieldIndex(Tag.TypeStruct, "size").?;
22372237 return @ptrCast(&ip.extra.items[self.extra_index + size_field_index]);
......@@ -2241,50 +2241,50 @@ pub const LoadedStructType = struct {
22412241 /// this type or the user specifies it, it is stored here. This will be
22422242 /// set to `none` until the layout is resolved.
22432243 /// Asserts the struct is packed.
2244 pub fn backingIntType(s: @This(), ip: *const InternPool) *Index {
2244 pub fn backingIntType(s: LoadedStructType, ip: *const InternPool) *Index {
22452245 assert(s.layout == .@"packed");
22462246 const field_index = std.meta.fieldIndex(Tag.TypeStructPacked, "backing_int_ty").?;
22472247 return @ptrCast(&ip.extra.items[s.extra_index + field_index]);
22482248 }
22492249
22502250 /// Asserts the struct is not packed.
2251 pub fn setZirIndex(s: @This(), ip: *InternPool, new_zir_index: TrackedInst.Index.Optional) void {
2251 pub fn setZirIndex(s: LoadedStructType, ip: *InternPool, new_zir_index: TrackedInst.Index.Optional) void {
22522252 assert(s.layout != .@"packed");
22532253 const field_index = std.meta.fieldIndex(Tag.TypeStruct, "zir_index").?;
22542254 ip.extra.items[s.extra_index + field_index] = @intFromEnum(new_zir_index);
22552255 }
22562256
2257 pub fn haveFieldTypes(s: @This(), ip: *const InternPool) bool {
2257 pub fn haveFieldTypes(s: LoadedStructType, ip: *const InternPool) bool {
22582258 const types = s.field_types.get(ip);
22592259 return types.len == 0 or types[0] != .none;
22602260 }
22612261
2262 pub fn haveFieldInits(s: @This(), ip: *const InternPool) bool {
2262 pub fn haveFieldInits(s: LoadedStructType, ip: *const InternPool) bool {
22632263 return switch (s.layout) {
22642264 .@"packed" => s.packedFlagsPtr(ip).inits_resolved,
22652265 .auto, .@"extern" => s.flagsPtr(ip).inits_resolved,
22662266 };
22672267 }
22682268
2269 pub fn setHaveFieldInits(s: @This(), ip: *InternPool) void {
2269 pub fn setHaveFieldInits(s: LoadedStructType, ip: *InternPool) void {
22702270 switch (s.layout) {
22712271 .@"packed" => s.packedFlagsPtr(ip).inits_resolved = true,
22722272 .auto, .@"extern" => s.flagsPtr(ip).inits_resolved = true,
22732273 }
22742274 }
22752275
2276 pub fn haveLayout(s: @This(), ip: *InternPool) bool {
2276 pub fn haveLayout(s: LoadedStructType, ip: *InternPool) bool {
22772277 return switch (s.layout) {
22782278 .@"packed" => s.backingIntType(ip).* != .none,
22792279 .auto, .@"extern" => s.flagsPtr(ip).layout_resolved,
22802280 };
22812281 }
22822282
2283 pub fn isTuple(s: @This(), ip: *InternPool) bool {
2283 pub fn isTuple(s: LoadedStructType, ip: *InternPool) bool {
22842284 return s.layout != .@"packed" and s.flagsPtr(ip).is_tuple;
22852285 }
22862286
2287 pub fn hasReorderedFields(s: @This()) bool {
2287 pub fn hasReorderedFields(s: LoadedStructType) bool {
22882288 return s.layout == .auto;
22892289 }
22902290
......@@ -2318,7 +2318,7 @@ pub const LoadedStructType = struct {
23182318 /// Iterates over non-comptime fields in the order they are laid out in memory at runtime.
23192319 /// May or may not include zero-bit fields.
23202320 /// Asserts the struct is not packed.
2321 pub fn iterateRuntimeOrder(s: @This(), ip: *InternPool) RuntimeOrderIterator {
2321 pub fn iterateRuntimeOrder(s: LoadedStructType, ip: *InternPool) RuntimeOrderIterator {
23222322 assert(s.layout != .@"packed");
23232323 return .{
23242324 .ip = ip,
......@@ -2358,7 +2358,7 @@ pub const LoadedStructType = struct {
23582358 }
23592359 };
23602360
2361 pub fn iterateRuntimeOrderReverse(s: @This(), ip: *InternPool) ReverseRuntimeOrderIterator {
2361 pub fn iterateRuntimeOrderReverse(s: LoadedStructType, ip: *InternPool) ReverseRuntimeOrderIterator {
23622362 assert(s.layout != .@"packed");
23632363 return .{
23642364 .ip = ip,
src/Module.zig+25-25
......@@ -6140,18 +6140,18 @@ pub const UnionLayout = struct {
61406140 padding: u32,
61416141};
61426142
6143pub fn getUnionLayout(mod: *Module, u: InternPool.LoadedUnionType) UnionLayout {
6143pub fn getUnionLayout(mod: *Module, loaded_union: InternPool.LoadedUnionType) UnionLayout {
61446144 const ip = &mod.intern_pool;
6145 assert(u.haveLayout(ip));
6145 assert(loaded_union.haveLayout(ip));
61466146 var most_aligned_field: u32 = undefined;
61476147 var most_aligned_field_size: u64 = undefined;
61486148 var biggest_field: u32 = undefined;
61496149 var payload_size: u64 = 0;
61506150 var payload_align: Alignment = .@"1";
6151 for (u.field_types.get(ip), 0..) |field_ty, i| {
6151 for (loaded_union.field_types.get(ip), 0..) |field_ty, field_index| {
61526152 if (!Type.fromInterned(field_ty).hasRuntimeBitsIgnoreComptime(mod)) continue;
61536153
6154 const explicit_align = u.fieldAlign(ip, @intCast(i));
6154 const explicit_align = loaded_union.fieldAlign(ip, field_index);
61556155 const field_align = if (explicit_align != .none)
61566156 explicit_align
61576157 else
......@@ -6159,16 +6159,16 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.LoadedUnionType) UnionLayout {
61596159 const field_size = Type.fromInterned(field_ty).abiSize(mod);
61606160 if (field_size > payload_size) {
61616161 payload_size = field_size;
6162 biggest_field = @intCast(i);
6162 biggest_field = @intCast(field_index);
61636163 }
61646164 if (field_align.compare(.gte, payload_align)) {
61656165 payload_align = field_align;
6166 most_aligned_field = @intCast(i);
6166 most_aligned_field = @intCast(field_index);
61676167 most_aligned_field_size = field_size;
61686168 }
61696169 }
6170 const have_tag = u.flagsPtr(ip).runtime_tag.hasTag();
6171 if (!have_tag or !Type.fromInterned(u.enum_tag_ty).hasRuntimeBits(mod)) {
6170 const have_tag = loaded_union.flagsPtr(ip).runtime_tag.hasTag();
6171 if (!have_tag or !Type.fromInterned(loaded_union.enum_tag_ty).hasRuntimeBits(mod)) {
61726172 return .{
61736173 .abi_size = payload_align.forward(payload_size),
61746174 .abi_align = payload_align,
......@@ -6183,10 +6183,10 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.LoadedUnionType) UnionLayout {
61836183 };
61846184 }
61856185
6186 const tag_size = Type.fromInterned(u.enum_tag_ty).abiSize(mod);
6187 const tag_align = Type.fromInterned(u.enum_tag_ty).abiAlignment(mod).max(.@"1");
6186 const tag_size = Type.fromInterned(loaded_union.enum_tag_ty).abiSize(mod);
6187 const tag_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(mod).max(.@"1");
61886188 return .{
6189 .abi_size = u.size(ip).*,
6189 .abi_size = loaded_union.size(ip).*,
61906190 .abi_align = tag_align.max(payload_align),
61916191 .most_aligned_field = most_aligned_field,
61926192 .most_aligned_field_size = most_aligned_field_size,
......@@ -6195,24 +6195,24 @@ pub fn getUnionLayout(mod: *Module, u: InternPool.LoadedUnionType) UnionLayout {
61956195 .payload_align = payload_align,
61966196 .tag_align = tag_align,
61976197 .tag_size = tag_size,
6198 .padding = u.padding(ip).*,
6198 .padding = loaded_union.padding(ip).*,
61996199 };
62006200}
62016201
6202pub fn unionAbiSize(mod: *Module, u: InternPool.LoadedUnionType) u64 {
6203 return mod.getUnionLayout(u).abi_size;
6202pub fn unionAbiSize(mod: *Module, loaded_union: InternPool.LoadedUnionType) u64 {
6203 return mod.getUnionLayout(loaded_union).abi_size;
62046204}
62056205
62066206/// Returns 0 if the union is represented with 0 bits at runtime.
6207pub fn unionAbiAlignment(mod: *Module, u: InternPool.LoadedUnionType) Alignment {
6207pub fn unionAbiAlignment(mod: *Module, loaded_union: InternPool.LoadedUnionType) Alignment {
62086208 const ip = &mod.intern_pool;
6209 const have_tag = u.flagsPtr(ip).runtime_tag.hasTag();
6209 const have_tag = loaded_union.flagsPtr(ip).runtime_tag.hasTag();
62106210 var max_align: Alignment = .none;
6211 if (have_tag) max_align = Type.fromInterned(u.enum_tag_ty).abiAlignment(mod);
6212 for (u.field_types.get(ip), 0..) |field_ty, field_index| {
6211 if (have_tag) max_align = Type.fromInterned(loaded_union.enum_tag_ty).abiAlignment(mod);
6212 for (loaded_union.field_types.get(ip), 0..) |field_ty, field_index| {
62136213 if (!Type.fromInterned(field_ty).hasRuntimeBits(mod)) continue;
62146214
6215 const field_align = mod.unionFieldNormalAlignment(u, @intCast(field_index));
6215 const field_align = mod.unionFieldNormalAlignment(loaded_union, @intCast(field_index));
62166216 max_align = max_align.max(field_align);
62176217 }
62186218 return max_align;
......@@ -6221,20 +6221,20 @@ pub fn unionAbiAlignment(mod: *Module, u: InternPool.LoadedUnionType) Alignment
62216221/// Returns the field alignment, assuming the union is not packed.
62226222/// Keep implementation in sync with `Sema.unionFieldAlignment`.
62236223/// Prefer to call that function instead of this one during Sema.
6224pub fn unionFieldNormalAlignment(mod: *Module, u: InternPool.LoadedUnionType, field_index: u32) Alignment {
6224pub fn unionFieldNormalAlignment(mod: *Module, loaded_union: InternPool.LoadedUnionType, field_index: u32) Alignment {
62256225 const ip = &mod.intern_pool;
6226 const field_align = u.fieldAlign(ip, field_index);
6226 const field_align = loaded_union.fieldAlign(ip, field_index);
62276227 if (field_align != .none) return field_align;
6228 const field_ty = Type.fromInterned(u.field_types.get(ip)[field_index]);
6228 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
62296229 return field_ty.abiAlignment(mod);
62306230}
62316231
62326232/// Returns the index of the active field, given the current tag value
6233pub fn unionTagFieldIndex(mod: *Module, u: InternPool.LoadedUnionType, enum_tag: Value) ?u32 {
6233pub fn unionTagFieldIndex(mod: *Module, loaded_union: InternPool.LoadedUnionType, enum_tag: Value) ?u32 {
62346234 const ip = &mod.intern_pool;
62356235 if (enum_tag.toIntern() == .none) return null;
6236 assert(ip.typeOf(enum_tag.toIntern()) == u.enum_tag_ty);
6237 return u.loadTagType(ip).tagValueIndex(ip, enum_tag.toIntern());
6236 assert(ip.typeOf(enum_tag.toIntern()) == loaded_union.enum_tag_ty);
6237 return loaded_union.loadTagType(ip).tagValueIndex(ip, enum_tag.toIntern());
62386238}
62396239
62406240/// Returns the field alignment of a non-packed struct in byte units.
src/Sema.zig+2-2
......@@ -35405,7 +35405,7 @@ pub fn resolveUnionAlignment(
3540535405 const field_ty = Type.fromInterned(union_type.field_types.get(ip)[field_index]);
3540635406 if (!(try sema.typeHasRuntimeBits(field_ty))) continue;
3540735407
35408 const explicit_align = union_type.fieldAlign(ip, @intCast(field_index));
35408 const explicit_align = union_type.fieldAlign(ip, field_index);
3540935409 const field_align = if (explicit_align != .none)
3541035410 explicit_align
3541135411 else
......@@ -35465,7 +35465,7 @@ fn resolveUnionLayout(sema: *Sema, ty: Type) CompileError!void {
3546535465 else => return err,
3546635466 });
3546735467
35468 const explicit_align = union_type.fieldAlign(ip, @intCast(field_index));
35468 const explicit_align = union_type.fieldAlign(ip, field_index);
3546935469 const field_align = if (explicit_align != .none)
3547035470 explicit_align
3547135471 else
src/arch/x86_64/CodeGen.zig+5-5
......@@ -14316,7 +14316,7 @@ fn moveStrategy(self: *Self, ty: Type, class: Register.Class, aligned: bool) !Mo
1431614316 .mmx => {},
1431714317 .sse => switch (ty.zigTypeTag(mod)) {
1431814318 else => {
14319 const classes = mem.sliceTo(&abi.classifySystemV(ty, mod, .other), .none);
14319 const classes = mem.sliceTo(&abi.classifySystemV(ty, mod, self.target.*, .other), .none);
1432014320 assert(std.mem.indexOfNone(abi.Class, classes, &.{
1432114321 .integer, .sse, .memory, .float, .float_combine,
1432214322 }) == null);
......@@ -18450,7 +18450,7 @@ fn airVaArg(self: *Self, inst: Air.Inst.Index) !void {
1845018450 const overflow_arg_area: MCValue = .{ .indirect = .{ .reg = ptr_arg_list_reg, .off = 8 } };
1845118451 const reg_save_area: MCValue = .{ .indirect = .{ .reg = ptr_arg_list_reg, .off = 16 } };
1845218452
18453 const classes = mem.sliceTo(&abi.classifySystemV(promote_ty, mod, .arg), .none);
18453 const classes = mem.sliceTo(&abi.classifySystemV(promote_ty, mod, self.target.*, .arg), .none);
1845418454 switch (classes[0]) {
1845518455 .integer => {
1845618456 assert(classes.len == 1);
......@@ -18800,7 +18800,7 @@ fn resolveCallingConventionValues(
1880018800 var ret_tracking_i: usize = 0;
1880118801
1880218802 const classes = switch (resolved_cc) {
18803 .SysV => mem.sliceTo(&abi.classifySystemV(ret_ty, mod, .ret), .none),
18803 .SysV => mem.sliceTo(&abi.classifySystemV(ret_ty, mod, self.target.*, .ret), .none),
1880418804 .Win64 => &.{abi.classifyWindows(ret_ty, mod)},
1880518805 else => unreachable,
1880618806 };
......@@ -18875,7 +18875,7 @@ fn resolveCallingConventionValues(
1887518875 var arg_mcv_i: usize = 0;
1887618876
1887718877 const classes = switch (resolved_cc) {
18878 .SysV => mem.sliceTo(&abi.classifySystemV(ty, mod, .arg), .none),
18878 .SysV => mem.sliceTo(&abi.classifySystemV(ty, mod, self.target.*, .arg), .none),
1887918879 .Win64 => &.{abi.classifyWindows(ty, mod)},
1888018880 else => unreachable,
1888118881 };
......@@ -19090,7 +19090,7 @@ fn memSize(self: *Self, ty: Type) Memory.Size {
1909019090
1909119091fn splitType(self: *Self, ty: Type) ![2]Type {
1909219092 const mod = self.bin_file.comp.module.?;
19093 const classes = mem.sliceTo(&abi.classifySystemV(ty, mod, .other), .none);
19093 const classes = mem.sliceTo(&abi.classifySystemV(ty, mod, self.target.*, .other), .none);
1909419094 var parts: [2]Type = undefined;
1909519095 if (classes.len == 2) for (&parts, classes, 0..) |*part, class, part_i| {
1909619096 part.* = switch (class) {
src/arch/x86_64/abi.zig+108-163
......@@ -11,6 +11,37 @@ pub const Class = enum {
1111 float,
1212 float_combine,
1313 integer_per_element,
14
15 fn isX87(class: Class) bool {
16 return switch (class) {
17 .x87, .x87up, .complex_x87 => true,
18 else => false,
19 };
20 }
21
22 /// Combine a field class with the prev one.
23 fn combineSystemV(prev_class: Class, next_class: Class) Class {
24 // "If both classes are equal, this is the resulting class."
25 if (prev_class == next_class)
26 return if (prev_class == .float) .float_combine else prev_class;
27
28 // "If one of the classes is NO_CLASS, the resulting class
29 // is the other class."
30 if (prev_class == .none) return next_class;
31
32 // "If one of the classes is MEMORY, the result is the MEMORY class."
33 if (prev_class == .memory or next_class == .memory) return .memory;
34
35 // "If one of the classes is INTEGER, the result is the INTEGER."
36 if (prev_class == .integer or next_class == .integer) return .integer;
37
38 // "If one of the classes is X87, X87UP, COMPLEX_X87 class,
39 // MEMORY is used as class."
40 if (prev_class.isX87() or next_class.isX87()) return .memory;
41
42 // "Otherwise class SSE is used."
43 return .sse;
44 }
1445};
1546
1647pub fn classifyWindows(ty: Type, zcu: *Zcu) Class {
......@@ -69,9 +100,7 @@ pub const Context = enum { ret, arg, field, other };
69100
70101/// There are a maximum of 8 possible return slots. Returned values are in
71102/// the beginning of the array; unused slots are filled with .none.
72pub fn classifySystemV(ty: Type, zcu: *Zcu, ctx: Context) [8]Class {
73 const ip = &zcu.intern_pool;
74 const target = zcu.getTarget();
103pub fn classifySystemV(ty: Type, zcu: *Zcu, target: std.Target, ctx: Context) [8]Class {
75104 const memory_class = [_]Class{
76105 .memory, .none, .none, .none,
77106 .none, .none, .none, .none,
......@@ -231,121 +260,30 @@ pub fn classifySystemV(ty: Type, zcu: *Zcu, ctx: Context) [8]Class {
231260 }
232261 return memory_class;
233262 },
234 .Struct => {
263 .Struct, .Union => {
235264 // "If the size of an object is larger than eight eightbytes, or
236265 // it contains unaligned fields, it has class MEMORY"
237266 // "If the size of the aggregate exceeds a single eightbyte, each is classified
238267 // separately.".
239 const loaded_struct = ip.loadStructType(ty.toIntern());
240268 const ty_size = ty.abiSize(zcu);
241 if (loaded_struct.layout == .@"packed") {
242 assert(ty_size <= 16);
243 result[0] = .integer;
244 if (ty_size > 8) result[1] = .integer;
245 return result;
246 }
247 if (ty_size > 64)
248 return memory_class;
249
250 var byte_offset: u64 = 0;
251 classifySystemVStruct(&result, &byte_offset, loaded_struct, zcu);
252
253 // Post-merger cleanup
254
255 // "If one of the classes is MEMORY, the whole argument is passed in memory"
256 // "If X87UP is not preceded by X87, the whole argument is passed in memory."
257 var found_sseup = false;
258 for (result, 0..) |item, i| switch (item) {
259 .memory => return memory_class,
260 .x87up => if (i == 0 or result[i - 1] != .x87) return memory_class,
261 .sseup => found_sseup = true,
262 else => continue,
263 };
264 // "If the size of the aggregate exceeds two eightbytes and the first eight-
265 // byte isn’t SSE or any other eightbyte isn’t SSEUP, the whole argument
266 // is passed in memory."
267 if (ty_size > 16 and (result[0] != .sse or !found_sseup)) return memory_class;
268
269 // "If SSEUP is not preceded by SSE or SSEUP, it is converted to SSE."
270 for (&result, 0..) |*item, i| {
271 if (item.* == .sseup) switch (result[i - 1]) {
272 .sse, .sseup => continue,
273 else => item.* = .sse,
274 };
275 }
276 return result;
277 },
278 .Union => {
279 // "If the size of an object is larger than eight eightbytes, or
280 // it contains unaligned fields, it has class MEMORY"
281 // "If the size of the aggregate exceeds a single eightbyte, each is classified
282 // separately.".
283 const union_obj = zcu.typeToUnion(ty).?;
284 const ty_size = zcu.unionAbiSize(union_obj);
285 if (union_obj.getLayout(ip) == .@"packed") {
286 assert(ty_size <= 16);
287 result[0] = .integer;
288 if (ty_size > 8) result[1] = .integer;
289 return result;
269 switch (ty.containerLayout(zcu)) {
270 .auto, .@"extern" => {},
271 .@"packed" => {
272 assert(ty_size <= 16);
273 result[0] = .integer;
274 if (ty_size > 8) result[1] = .integer;
275 return result;
276 },
290277 }
291278 if (ty_size > 64)
292279 return memory_class;
293280
294 for (union_obj.field_types.get(ip), 0..) |field_ty, field_index| {
295 const field_align = union_obj.fieldAlign(ip, @intCast(field_index));
296 if (field_align != .none and
297 field_align.compare(.lt, Type.fromInterned(field_ty).abiAlignment(zcu)))
298 {
299 return memory_class;
300 }
301 // Combine this field with the previous one.
302 const field_class = classifySystemV(Type.fromInterned(field_ty), zcu, .field);
303 for (&result, 0..) |*result_item, i| {
304 const field_item = field_class[i];
305 // "If both classes are equal, this is the resulting class."
306 if (result_item.* == field_item) {
307 continue;
308 }
309
310 // "If one of the classes is NO_CLASS, the resulting class
311 // is the other class."
312 if (result_item.* == .none) {
313 result_item.* = field_item;
314 continue;
315 }
316 if (field_item == .none) {
317 continue;
318 }
319
320 // "If one of the classes is MEMORY, the result is the MEMORY class."
321 if (result_item.* == .memory or field_item == .memory) {
322 result_item.* = .memory;
323 continue;
324 }
325
326 // "If one of the classes is INTEGER, the result is the INTEGER."
327 if (result_item.* == .integer or field_item == .integer) {
328 result_item.* = .integer;
329 continue;
330 }
331
332 // "If one of the classes is X87, X87UP, COMPLEX_X87 class,
333 // MEMORY is used as class."
334 if (result_item.* == .x87 or
335 result_item.* == .x87up or
336 result_item.* == .complex_x87 or
337 field_item == .x87 or
338 field_item == .x87up or
339 field_item == .complex_x87)
340 {
341 result_item.* = .memory;
342 continue;
343 }
344
345 // "Otherwise class SSE is used."
346 result_item.* = .sse;
347 }
348 }
281 _ = if (zcu.typeToStruct(ty)) |loaded_struct|
282 classifySystemVStruct(&result, 0, loaded_struct, zcu, target)
283 else if (zcu.typeToUnion(ty)) |loaded_union|
284 classifySystemVUnion(&result, 0, loaded_union, zcu, target)
285 else
286 unreachable;
349287
350288 // Post-merger cleanup
351289
......@@ -391,78 +329,85 @@ pub fn classifySystemV(ty: Type, zcu: *Zcu, ctx: Context) [8]Class {
391329
392330fn classifySystemVStruct(
393331 result: *[8]Class,
394 byte_offset: *u64,
332 starting_byte_offset: u64,
395333 loaded_struct: InternPool.LoadedStructType,
396334 zcu: *Zcu,
397) void {
335 target: std.Target,
336) u64 {
398337 const ip = &zcu.intern_pool;
338 var byte_offset = starting_byte_offset;
399339 var field_it = loaded_struct.iterateRuntimeOrder(ip);
400340 while (field_it.next()) |field_index| {
401341 const field_ty = Type.fromInterned(loaded_struct.field_types.get(ip)[field_index]);
402342 const field_align = loaded_struct.fieldAlign(ip, field_index);
403 byte_offset.* = std.mem.alignForward(
343 byte_offset = std.mem.alignForward(
404344 u64,
405 byte_offset.*,
345 byte_offset,
406346 field_align.toByteUnits() orelse field_ty.abiAlignment(zcu).toByteUnits().?,
407347 );
408348 if (zcu.typeToStruct(field_ty)) |field_loaded_struct| {
409 if (field_loaded_struct.layout != .@"packed") {
410 classifySystemVStruct(result, byte_offset, field_loaded_struct, zcu);
411 continue;
412 }
413 }
414 const field_class = std.mem.sliceTo(&classifySystemV(field_ty, zcu, .field), .none);
415 const field_size = field_ty.abiSize(zcu);
416 combine: {
417 // Combine this field with the previous one.
418 const result_class = &result[@intCast(byte_offset.* / 8)];
419 // "If both classes are equal, this is the resulting class."
420 if (result_class.* == field_class[0]) {
421 if (result_class.* == .float) {
422 result_class.* = .float_combine;
423 }
424 break :combine;
425 }
426
427 // "If one of the classes is NO_CLASS, the resulting class
428 // is the other class."
429 if (result_class.* == .none) {
430 result_class.* = field_class[0];
431 break :combine;
349 switch (field_loaded_struct.layout) {
350 .auto, .@"extern" => {
351 byte_offset = classifySystemVStruct(result, byte_offset, field_loaded_struct, zcu, target);
352 continue;
353 },
354 .@"packed" => {},
432355 }
433 assert(field_class[0] != .none);
434
435 // "If one of the classes is MEMORY, the result is the MEMORY class."
436 if (result_class.* == .memory or field_class[0] == .memory) {
437 result_class.* = .memory;
438 break :combine;
356 } else if (zcu.typeToUnion(field_ty)) |field_loaded_union| {
357 switch (field_loaded_union.getLayout(ip)) {
358 .auto, .@"extern" => {
359 byte_offset = classifySystemVUnion(result, byte_offset, field_loaded_union, zcu, target);
360 continue;
361 },
362 .@"packed" => {},
439363 }
364 }
365 const field_classes = std.mem.sliceTo(&classifySystemV(field_ty, zcu, target, .field), .none);
366 for (result[@intCast(byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|
367 result_class.* = result_class.combineSystemV(field_class);
368 byte_offset += field_ty.abiSize(zcu);
369 }
370 const final_byte_offset = starting_byte_offset + loaded_struct.size(ip).*;
371 std.debug.assert(final_byte_offset == std.mem.alignForward(
372 u64,
373 byte_offset,
374 loaded_struct.flagsPtr(ip).alignment.toByteUnits().?,
375 ));
376 return final_byte_offset;
377}
440378
441 // "If one of the classes is INTEGER, the result is the INTEGER."
442 if (result_class.* == .integer or field_class[0] == .integer) {
443 result_class.* = .integer;
444 break :combine;
379fn classifySystemVUnion(
380 result: *[8]Class,
381 starting_byte_offset: u64,
382 loaded_union: InternPool.LoadedUnionType,
383 zcu: *Zcu,
384 target: std.Target,
385) u64 {
386 const ip = &zcu.intern_pool;
387 for (0..loaded_union.field_types.len) |field_index| {
388 const field_ty = Type.fromInterned(loaded_union.field_types.get(ip)[field_index]);
389 if (zcu.typeToStruct(field_ty)) |field_loaded_struct| {
390 switch (field_loaded_struct.layout) {
391 .auto, .@"extern" => {
392 _ = classifySystemVStruct(result, starting_byte_offset, field_loaded_struct, zcu, target);
393 continue;
394 },
395 .@"packed" => {},
445396 }
446
447 // "If one of the classes is X87, X87UP, COMPLEX_X87 class,
448 // MEMORY is used as class."
449 if (result_class.* == .x87 or
450 result_class.* == .x87up or
451 result_class.* == .complex_x87 or
452 field_class[0] == .x87 or
453 field_class[0] == .x87up or
454 field_class[0] == .complex_x87)
455 {
456 result_class.* = .memory;
457 break :combine;
397 } else if (zcu.typeToUnion(field_ty)) |field_loaded_union| {
398 switch (field_loaded_union.getLayout(ip)) {
399 .auto, .@"extern" => {
400 _ = classifySystemVUnion(result, starting_byte_offset, field_loaded_union, zcu, target);
401 continue;
402 },
403 .@"packed" => {},
458404 }
459
460 // "Otherwise class SSE is used."
461 result_class.* = .sse;
462405 }
463 @memcpy(result[@intCast(byte_offset.* / 8 + 1)..][0 .. field_class.len - 1], field_class[1..]);
464 byte_offset.* += field_size;
406 const field_classes = std.mem.sliceTo(&classifySystemV(field_ty, zcu, target, .field), .none);
407 for (result[@intCast(starting_byte_offset / 8)..][0..field_classes.len], field_classes) |*result_class, field_class|
408 result_class.* = result_class.combineSystemV(field_class);
465409 }
410 return starting_byte_offset + loaded_union.size(ip).*;
466411}
467412
468413pub const SysV = struct {
src/codegen/c/Type.zig+1-1
......@@ -1858,7 +1858,7 @@ pub const Pool = struct {
18581858 loaded_tag.names.get(ip)[field_index].toSlice(ip),
18591859 );
18601860 const field_alignas = AlignAs.fromAlignment(.{
1861 .@"align" = loaded_union.fieldAlign(ip, @intCast(field_index)),
1861 .@"align" = loaded_union.fieldAlign(ip, field_index),
18621862 .abi = field_type.abiAlignment(zcu),
18631863 });
18641864 pool.addHashedExtraAssumeCapacityTo(scratch, &hasher, Field, .{
src/codegen/llvm.zig+128-127
......@@ -1384,7 +1384,7 @@ pub const Object = struct {
13841384 const namespace = zcu.namespacePtr(decl.src_namespace);
13851385 const owner_mod = namespace.file_scope.mod;
13861386 const fn_info = zcu.typeToFunc(decl.typeOf(zcu)).?;
1387 const target = zcu.getTarget();
1387 const target = owner_mod.resolved_target.result;
13881388 const ip = &zcu.intern_pool;
13891389
13901390 var dg: DeclGen = .{
......@@ -1456,7 +1456,7 @@ pub const Object = struct {
14561456 var llvm_arg_i: u32 = 0;
14571457
14581458 // This gets the LLVM values from the function and stores them in `dg.args`.
1459 const sret = firstParamSRet(fn_info, zcu);
1459 const sret = firstParamSRet(fn_info, zcu, target);
14601460 const ret_ptr: Builder.Value = if (sret) param: {
14611461 const param = wip.arg(llvm_arg_i);
14621462 llvm_arg_i += 1;
......@@ -2755,7 +2755,7 @@ pub const Object = struct {
27552755
27562756 // Return type goes first.
27572757 if (Type.fromInterned(fn_info.return_type).hasRuntimeBitsIgnoreComptime(mod)) {
2758 const sret = firstParamSRet(fn_info, mod);
2758 const sret = firstParamSRet(fn_info, mod, target);
27592759 const ret_ty = if (sret) Type.void else Type.fromInterned(fn_info.return_type);
27602760 debug_param_types.appendAssumeCapacity(try o.lowerDebugType(ret_ty));
27612761
......@@ -2881,7 +2881,7 @@ pub const Object = struct {
28812881 assert(decl.has_tv);
28822882 const fn_info = zcu.typeToFunc(zig_fn_type).?;
28832883 const target = owner_mod.resolved_target.result;
2884 const sret = firstParamSRet(fn_info, zcu);
2884 const sret = firstParamSRet(fn_info, zcu, target);
28852885
28862886 const is_extern = decl.isExtern(zcu);
28872887 const function_index = try o.builder.addFunction(
......@@ -3604,7 +3604,7 @@ pub const Object = struct {
36043604 var llvm_params = std.ArrayListUnmanaged(Builder.Type){};
36053605 defer llvm_params.deinit(o.gpa);
36063606
3607 if (firstParamSRet(fn_info, mod)) {
3607 if (firstParamSRet(fn_info, mod, target)) {
36083608 try llvm_params.append(o.gpa, .ptr);
36093609 }
36103610
......@@ -5130,7 +5130,7 @@ pub const FuncGen = struct {
51305130 const return_type = Type.fromInterned(fn_info.return_type);
51315131 const llvm_fn = try self.resolveInst(pl_op.operand);
51325132 const target = mod.getTarget();
5133 const sret = firstParamSRet(fn_info, mod);
5133 const sret = firstParamSRet(fn_info, mod, target);
51345134
51355135 var llvm_args = std.ArrayList(Builder.Value).init(self.gpa);
51365136 defer llvm_args.deinit();
......@@ -10865,38 +10865,38 @@ fn toLlvmGlobalAddressSpace(wanted_address_space: std.builtin.AddressSpace, targ
1086510865 };
1086610866}
1086710867
10868fn firstParamSRet(fn_info: InternPool.Key.FuncType, mod: *Module) bool {
10868fn firstParamSRet(fn_info: InternPool.Key.FuncType, zcu: *Zcu, target: std.Target) bool {
1086910869 const return_type = Type.fromInterned(fn_info.return_type);
10870 if (!return_type.hasRuntimeBitsIgnoreComptime(mod)) return false;
10870 if (!return_type.hasRuntimeBitsIgnoreComptime(zcu)) return false;
1087110871
10872 const target = mod.getTarget();
10873 switch (fn_info.cc) {
10874 .Unspecified, .Inline => return isByRef(return_type, mod),
10872 return switch (fn_info.cc) {
10873 .Unspecified, .Inline => isByRef(return_type, zcu),
1087510874 .C => switch (target.cpu.arch) {
10876 .mips, .mipsel => return false,
10875 .mips, .mipsel => false,
10876 .x86 => isByRef(return_type, zcu),
1087710877 .x86_64 => switch (target.os.tag) {
10878 .windows => return x86_64_abi.classifyWindows(return_type, mod) == .memory,
10879 else => return firstParamSRetSystemV(return_type, mod),
10878 .windows => x86_64_abi.classifyWindows(return_type, zcu) == .memory,
10879 else => firstParamSRetSystemV(return_type, zcu, target),
1088010880 },
10881 .wasm32 => return wasm_c_abi.classifyType(return_type, mod)[0] == .indirect,
10882 .aarch64, .aarch64_be => return aarch64_c_abi.classifyType(return_type, mod) == .memory,
10883 .arm, .armeb => switch (arm_c_abi.classifyType(return_type, mod, .ret)) {
10884 .memory, .i64_array => return true,
10885 .i32_array => |size| return size != 1,
10886 .byval => return false,
10881 .wasm32 => wasm_c_abi.classifyType(return_type, zcu)[0] == .indirect,
10882 .aarch64, .aarch64_be => aarch64_c_abi.classifyType(return_type, zcu) == .memory,
10883 .arm, .armeb => switch (arm_c_abi.classifyType(return_type, zcu, .ret)) {
10884 .memory, .i64_array => true,
10885 .i32_array => |size| size != 1,
10886 .byval => false,
1088710887 },
10888 .riscv32, .riscv64 => return riscv_c_abi.classifyType(return_type, mod) == .memory,
10889 else => return false, // TODO investigate C ABI for other architectures
10888 .riscv32, .riscv64 => riscv_c_abi.classifyType(return_type, zcu) == .memory,
10889 else => false, // TODO investigate C ABI for other architectures
1089010890 },
10891 .SysV => return firstParamSRetSystemV(return_type, mod),
10892 .Win64 => return x86_64_abi.classifyWindows(return_type, mod) == .memory,
10893 .Stdcall => return !isScalar(mod, return_type),
10894 else => return false,
10895 }
10891 .SysV => firstParamSRetSystemV(return_type, zcu, target),
10892 .Win64 => x86_64_abi.classifyWindows(return_type, zcu) == .memory,
10893 .Stdcall => !isScalar(zcu, return_type),
10894 else => false,
10895 };
1089610896}
1089710897
10898fn firstParamSRetSystemV(ty: Type, mod: *Module) bool {
10899 const class = x86_64_abi.classifySystemV(ty, mod, .ret);
10898fn firstParamSRetSystemV(ty: Type, zcu: *Zcu, target: std.Target) bool {
10899 const class = x86_64_abi.classifySystemV(ty, zcu, target, .ret);
1090010900 if (class[0] == .memory) return true;
1090110901 if (class[0] == .x87 and class[2] != .none) return true;
1090210902 return false;
......@@ -10922,6 +10922,7 @@ fn lowerFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.Error!Bu
1092210922 .C => {
1092310923 switch (target.cpu.arch) {
1092410924 .mips, .mipsel => return o.lowerType(return_type),
10925 .x86 => return if (isByRef(return_type, mod)) .void else o.lowerType(return_type),
1092510926 .x86_64 => switch (target.os.tag) {
1092610927 .windows => return lowerWin64FnRetTy(o, fn_info),
1092710928 else => return lowerSystemVFnRetTy(o, fn_info),
......@@ -11014,7 +11015,8 @@ fn lowerSystemVFnRetTy(o: *Object, fn_info: InternPool.Key.FuncType) Allocator.E
1101411015 if (isScalar(mod, return_type)) {
1101511016 return o.lowerType(return_type);
1101611017 }
11017 const classes = x86_64_abi.classifySystemV(return_type, mod, .ret);
11018 const target = mod.getTarget();
11019 const classes = x86_64_abi.classifySystemV(return_type, mod, target, .ret);
1101811020 if (classes[0] == .memory) return .void;
1101911021 var types_index: u32 = 0;
1102011022 var types_buffer: [8]Builder.Type = undefined;
......@@ -11098,8 +11100,8 @@ const ParamTypeIterator = struct {
1109811100
1109911101 pub fn next(it: *ParamTypeIterator) Allocator.Error!?Lowering {
1110011102 if (it.zig_index >= it.fn_info.param_types.len) return null;
11101 const mod = it.object.module;
11102 const ip = &mod.intern_pool;
11103 const zcu = it.object.module;
11104 const ip = &zcu.intern_pool;
1110311105 const ty = it.fn_info.param_types.get(ip)[it.zig_index];
1110411106 it.byval_attr = false;
1110511107 return nextInner(it, Type.fromInterned(ty));
......@@ -11107,8 +11109,8 @@ const ParamTypeIterator = struct {
1110711109
1110811110 /// `airCall` uses this instead of `next` so that it can take into account variadic functions.
1110911111 pub fn nextCall(it: *ParamTypeIterator, fg: *FuncGen, args: []const Air.Inst.Ref) Allocator.Error!?Lowering {
11110 const mod = it.object.module;
11111 const ip = &mod.intern_pool;
11112 const zcu = it.object.module;
11113 const ip = &zcu.intern_pool;
1111211114 if (it.zig_index >= it.fn_info.param_types.len) {
1111311115 if (it.zig_index >= args.len) {
1111411116 return null;
......@@ -11121,10 +11123,10 @@ const ParamTypeIterator = struct {
1112111123 }
1112211124
1112311125 fn nextInner(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
11124 const mod = it.object.module;
11125 const target = mod.getTarget();
11126 const zcu = it.object.module;
11127 const target = zcu.getTarget();
1112611128
11127 if (!ty.hasRuntimeBitsIgnoreComptime(mod)) {
11129 if (!ty.hasRuntimeBitsIgnoreComptime(zcu)) {
1112811130 it.zig_index += 1;
1112911131 return .no_bits;
1113011132 }
......@@ -11132,12 +11134,12 @@ const ParamTypeIterator = struct {
1113211134 .Unspecified, .Inline => {
1113311135 it.zig_index += 1;
1113411136 it.llvm_index += 1;
11135 if (ty.isSlice(mod) or
11136 (ty.zigTypeTag(mod) == .Optional and ty.optionalChild(mod).isSlice(mod) and !ty.ptrAllowsZero(mod)))
11137 if (ty.isSlice(zcu) or
11138 (ty.zigTypeTag(zcu) == .Optional and ty.optionalChild(zcu).isSlice(zcu) and !ty.ptrAllowsZero(zcu)))
1113711139 {
1113811140 it.llvm_index += 1;
1113911141 return .slice;
11140 } else if (isByRef(ty, mod)) {
11142 } else if (isByRef(ty, zcu)) {
1114111143 return .byref;
1114211144 } else {
1114311145 return .byval;
......@@ -11146,87 +11148,85 @@ const ParamTypeIterator = struct {
1114611148 .Async => {
1114711149 @panic("TODO implement async function lowering in the LLVM backend");
1114811150 },
11149 .C => {
11150 switch (target.cpu.arch) {
11151 .mips, .mipsel => {
11152 it.zig_index += 1;
11153 it.llvm_index += 1;
11151 .C => switch (target.cpu.arch) {
11152 .mips, .mipsel => {
11153 it.zig_index += 1;
11154 it.llvm_index += 1;
11155 return .byval;
11156 },
11157 .x86_64 => switch (target.os.tag) {
11158 .windows => return it.nextWin64(ty),
11159 else => return it.nextSystemV(ty),
11160 },
11161 .wasm32 => {
11162 it.zig_index += 1;
11163 it.llvm_index += 1;
11164 if (isScalar(zcu, ty)) {
1115411165 return .byval;
11155 },
11156 .x86_64 => switch (target.os.tag) {
11157 .windows => return it.nextWin64(ty),
11158 else => return it.nextSystemV(ty),
11159 },
11160 .wasm32 => {
11161 it.zig_index += 1;
11162 it.llvm_index += 1;
11163 if (isScalar(mod, ty)) {
11164 return .byval;
11165 }
11166 const classes = wasm_c_abi.classifyType(ty, mod);
11167 if (classes[0] == .indirect) {
11166 }
11167 const classes = wasm_c_abi.classifyType(ty, zcu);
11168 if (classes[0] == .indirect) {
11169 return .byref;
11170 }
11171 return .abi_sized_int;
11172 },
11173 .aarch64, .aarch64_be => {
11174 it.zig_index += 1;
11175 it.llvm_index += 1;
11176 switch (aarch64_c_abi.classifyType(ty, zcu)) {
11177 .memory => return .byref_mut,
11178 .float_array => |len| return Lowering{ .float_array = len },
11179 .byval => return .byval,
11180 .integer => {
11181 it.types_len = 1;
11182 it.types_buffer[0] = .i64;
11183 return .multiple_llvm_types;
11184 },
11185 .double_integer => return Lowering{ .i64_array = 2 },
11186 }
11187 },
11188 .arm, .armeb => {
11189 it.zig_index += 1;
11190 it.llvm_index += 1;
11191 switch (arm_c_abi.classifyType(ty, zcu, .arg)) {
11192 .memory => {
11193 it.byval_attr = true;
1116811194 return .byref;
11169 }
11170 return .abi_sized_int;
11171 },
11172 .aarch64, .aarch64_be => {
11173 it.zig_index += 1;
11174 it.llvm_index += 1;
11175 switch (aarch64_c_abi.classifyType(ty, mod)) {
11176 .memory => return .byref_mut,
11177 .float_array => |len| return Lowering{ .float_array = len },
11178 .byval => return .byval,
11179 .integer => {
11180 it.types_len = 1;
11181 it.types_buffer[0] = .i64;
11182 return .multiple_llvm_types;
11183 },
11184 .double_integer => return Lowering{ .i64_array = 2 },
11185 }
11186 },
11187 .arm, .armeb => {
11188 it.zig_index += 1;
11189 it.llvm_index += 1;
11190 switch (arm_c_abi.classifyType(ty, mod, .arg)) {
11191 .memory => {
11192 it.byval_attr = true;
11193 return .byref;
11194 },
11195 .byval => return .byval,
11196 .i32_array => |size| return Lowering{ .i32_array = size },
11197 .i64_array => |size| return Lowering{ .i64_array = size },
11198 }
11199 },
11200 .riscv32, .riscv64 => {
11201 it.zig_index += 1;
11202 it.llvm_index += 1;
11203 if (ty.toIntern() == .f16_type and
11204 !std.Target.riscv.featureSetHas(target.cpu.features, .d)) return .as_u16;
11205 switch (riscv_c_abi.classifyType(ty, mod)) {
11206 .memory => return .byref_mut,
11207 .byval => return .byval,
11208 .integer => return .abi_sized_int,
11209 .double_integer => return Lowering{ .i64_array = 2 },
11210 .fields => {
11211 it.types_len = 0;
11212 for (0..ty.structFieldCount(mod)) |field_index| {
11213 const field_ty = ty.structFieldType(field_index, mod);
11214 if (!field_ty.hasRuntimeBitsIgnoreComptime(mod)) continue;
11215 it.types_buffer[it.types_len] = try it.object.lowerType(field_ty);
11216 it.types_len += 1;
11217 }
11218 it.llvm_index += it.types_len - 1;
11219 return .multiple_llvm_types;
11220 },
11221 }
11222 },
11223 // TODO investigate C ABI for other architectures
11224 else => {
11225 it.zig_index += 1;
11226 it.llvm_index += 1;
11227 return .byval;
11228 },
11229 }
11195 },
11196 .byval => return .byval,
11197 .i32_array => |size| return Lowering{ .i32_array = size },
11198 .i64_array => |size| return Lowering{ .i64_array = size },
11199 }
11200 },
11201 .riscv32, .riscv64 => {
11202 it.zig_index += 1;
11203 it.llvm_index += 1;
11204 if (ty.toIntern() == .f16_type and
11205 !std.Target.riscv.featureSetHas(target.cpu.features, .d)) return .as_u16;
11206 switch (riscv_c_abi.classifyType(ty, zcu)) {
11207 .memory => return .byref_mut,
11208 .byval => return .byval,
11209 .integer => return .abi_sized_int,
11210 .double_integer => return Lowering{ .i64_array = 2 },
11211 .fields => {
11212 it.types_len = 0;
11213 for (0..ty.structFieldCount(zcu)) |field_index| {
11214 const field_ty = ty.structFieldType(field_index, zcu);
11215 if (!field_ty.hasRuntimeBitsIgnoreComptime(zcu)) continue;
11216 it.types_buffer[it.types_len] = try it.object.lowerType(field_ty);
11217 it.types_len += 1;
11218 }
11219 it.llvm_index += it.types_len - 1;
11220 return .multiple_llvm_types;
11221 },
11222 }
11223 },
11224 // TODO investigate C ABI for other architectures
11225 else => {
11226 it.zig_index += 1;
11227 it.llvm_index += 1;
11228 return .byval;
11229 },
1123011230 },
1123111231 .Win64 => return it.nextWin64(ty),
1123211232 .SysV => return it.nextSystemV(ty),
......@@ -11234,7 +11234,7 @@ const ParamTypeIterator = struct {
1123411234 it.zig_index += 1;
1123511235 it.llvm_index += 1;
1123611236
11237 if (isScalar(mod, ty)) {
11237 if (isScalar(zcu, ty)) {
1123811238 return .byval;
1123911239 } else {
1124011240 it.byval_attr = true;
......@@ -11250,10 +11250,10 @@ const ParamTypeIterator = struct {
1125011250 }
1125111251
1125211252 fn nextWin64(it: *ParamTypeIterator, ty: Type) ?Lowering {
11253 const mod = it.object.module;
11254 switch (x86_64_abi.classifyWindows(ty, mod)) {
11253 const zcu = it.object.module;
11254 switch (x86_64_abi.classifyWindows(ty, zcu)) {
1125511255 .integer => {
11256 if (isScalar(mod, ty)) {
11256 if (isScalar(zcu, ty)) {
1125711257 it.zig_index += 1;
1125811258 it.llvm_index += 1;
1125911259 return .byval;
......@@ -11283,16 +11283,17 @@ const ParamTypeIterator = struct {
1128311283 }
1128411284
1128511285 fn nextSystemV(it: *ParamTypeIterator, ty: Type) Allocator.Error!?Lowering {
11286 const mod = it.object.module;
11287 const ip = &mod.intern_pool;
11288 const classes = x86_64_abi.classifySystemV(ty, mod, .arg);
11286 const zcu = it.object.module;
11287 const ip = &zcu.intern_pool;
11288 const target = zcu.getTarget();
11289 const classes = x86_64_abi.classifySystemV(ty, zcu, target, .arg);
1128911290 if (classes[0] == .memory) {
1129011291 it.zig_index += 1;
1129111292 it.llvm_index += 1;
1129211293 it.byval_attr = true;
1129311294 return .byref;
1129411295 }
11295 if (isScalar(mod, ty)) {
11296 if (isScalar(zcu, ty)) {
1129611297 it.zig_index += 1;
1129711298 it.llvm_index += 1;
1129811299 return .byval;
test/c_abi/cfuncs.c+38-1
......@@ -269,6 +269,33 @@ void c_struct_f32_f32f32(struct Struct_f32_f32f32 s) {
269269 assert_or_panic(s.b.d == 3.0f);
270270}
271271
272struct Struct_u32_Union_u32_u32u32 {
273 uint32_t a;
274 union {
275 struct {
276 uint32_t d, e;
277 } c;
278 } b;
279};
280
281struct Struct_u32_Union_u32_u32u32 zig_ret_struct_u32_union_u32_u32u32(void);
282
283void zig_struct_u32_union_u32_u32u32(struct Struct_u32_Union_u32_u32u32);
284
285struct Struct_u32_Union_u32_u32u32 c_ret_struct_u32_union_u32_u32u32(void) {
286 struct Struct_u32_Union_u32_u32u32 s;
287 s.a = 1;
288 s.b.c.d = 2;
289 s.b.c.e = 3;
290 return s;
291}
292
293void c_struct_u32_union_u32_u32u32(struct Struct_u32_Union_u32_u32u32 s) {
294 assert_or_panic(s.a == 1);
295 assert_or_panic(s.b.c.d == 2);
296 assert_or_panic(s.b.c.e == 3);
297}
298
272299struct BigStruct {
273300 uint64_t a;
274301 uint64_t b;
......@@ -2664,6 +2691,16 @@ void run_c_tests(void) {
26642691 }
26652692#endif
26662693
2694#if !defined(__powerpc__)
2695 {
2696 struct Struct_u32_Union_u32_u32u32 s = zig_ret_struct_u32_union_u32_u32u32();
2697 assert_or_panic(s.a == 1);
2698 assert_or_panic(s.b.c.d == 2);
2699 assert_or_panic(s.b.c.e == 3);
2700 zig_struct_u32_union_u32_u32u32(s);
2701 }
2702#endif
2703
26672704 {
26682705 struct BigStruct s = {1, 2, 3, 4, 5};
26692706 zig_big_struct(s);
......@@ -2678,7 +2715,7 @@ void run_c_tests(void) {
26782715 }
26792716#endif
26802717
2681#if !defined __i386__ && !defined __arm__ && !defined __aarch64__ && \
2718#if !defined __arm__ && !defined __aarch64__ && \
26822719 !defined __mips__ && !defined __powerpc__ && !defined ZIG_RISCV64
26832720 {
26842721 struct MedStructInts s = {1, 2, 3};
test/c_abi/main.zig+47-29
......@@ -10,11 +10,11 @@ const builtin = @import("builtin");
1010const print = std.debug.print;
1111const expect = std.testing.expect;
1212const expectEqual = std.testing.expectEqual;
13const has_i128 = builtin.cpu.arch != .x86 and !builtin.cpu.arch.isARM() and
13const have_i128 = builtin.cpu.arch != .x86 and !builtin.cpu.arch.isARM() and
1414 !builtin.cpu.arch.isMIPS() and !builtin.cpu.arch.isPPC();
1515
16const has_f128 = builtin.cpu.arch.isX86() and !builtin.os.tag.isDarwin();
17const has_f80 = builtin.cpu.arch.isX86();
16const have_f128 = builtin.cpu.arch.isX86() and !builtin.os.tag.isDarwin();
17const have_f80 = builtin.cpu.arch.isX86();
1818
1919extern fn run_c_tests() void;
2020
......@@ -53,13 +53,13 @@ test "C ABI integers" {
5353 c_u16(0xfffe);
5454 c_u32(0xfffffffd);
5555 c_u64(0xfffffffffffffffc);
56 if (has_i128) c_struct_u128(.{ .value = 0xfffffffffffffffc });
56 if (have_i128) c_struct_u128(.{ .value = 0xfffffffffffffffc });
5757
5858 c_i8(-1);
5959 c_i16(-2);
6060 c_i32(-3);
6161 c_i64(-4);
62 if (has_i128) c_struct_i128(.{ .value = -6 });
62 if (have_i128) c_struct_i128(.{ .value = -6 });
6363 c_five_integers(12, 34, 56, 78, 90);
6464}
6565
......@@ -186,7 +186,6 @@ const complex_abi_compatible = builtin.cpu.arch != .x86 and !builtin.cpu.arch.is
186186
187187test "C ABI complex float" {
188188 if (!complex_abi_compatible) return error.SkipZigTest;
189 if (builtin.zig_backend == .stage2_llvm and builtin.cpu.arch == .x86_64) return error.SkipZigTest; // See https://github.com/ziglang/zig/issues/8465
190189
191190 const a = ComplexFloat{ .real = 1.25, .imag = 2.6 };
192191 const b = ComplexFloat{ .real = 11.3, .imag = -1.5 };
......@@ -401,6 +400,42 @@ test "C ABI struct f32 {f32,f32}" {
401400 c_struct_f32_f32f32(.{ .a = 1.0, .b = .{ .c = 2.0, .d = 3.0 } });
402401}
403402
403const Struct_u32_Union_u32_u32u32 = extern struct {
404 a: u32,
405 b: extern union {
406 c: extern struct {
407 d: u32,
408 e: u32,
409 },
410 },
411};
412
413export fn zig_ret_struct_u32_union_u32_u32u32() Struct_u32_Union_u32_u32u32 {
414 return .{ .a = 1, .b = .{ .c = .{ .d = 2, .e = 3 } } };
415}
416
417export fn zig_struct_u32_union_u32_u32u32(s: Struct_u32_Union_u32_u32u32) void {
418 expect(s.a == 1) catch @panic("test failure");
419 expect(s.b.c.d == 2) catch @panic("test failure");
420 expect(s.b.c.e == 3) catch @panic("test failure");
421}
422
423extern fn c_ret_struct_u32_union_u32_u32u32() Struct_u32_Union_u32_u32u32;
424
425extern fn c_struct_u32_union_u32_u32u32(Struct_u32_Union_u32_u32u32) void;
426
427test "C ABI struct{u32,union{u32,struct{u32,u32}}}" {
428 if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
429 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
430 if (builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
431
432 const s = c_ret_struct_u32_union_u32_u32u32();
433 try expect(s.a == 1);
434 try expect(s.b.c.d == 2);
435 try expect(s.b.c.e == 3);
436 c_struct_u32_union_u32_u32u32(.{ .a = 1, .b = .{ .c = .{ .d = 2, .e = 3 } } });
437}
438
404439const BigStruct = extern struct {
405440 a: u64,
406441 b: u64,
......@@ -470,7 +505,6 @@ extern fn c_med_struct_mixed(MedStructMixed) void;
470505extern fn c_ret_med_struct_mixed() MedStructMixed;
471506
472507test "C ABI medium struct of ints and floats" {
473 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
474508 if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
475509 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
476510 if (builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
......@@ -538,7 +572,6 @@ extern fn c_med_struct_ints(MedStructInts) void;
538572extern fn c_ret_med_struct_ints() MedStructInts;
539573
540574test "C ABI medium struct of ints" {
541 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
542575 if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
543576 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
544577 if (builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
......@@ -600,7 +633,7 @@ export fn zig_big_packed_struct(x: BigPackedStruct) void {
600633}
601634
602635test "C ABI big packed struct" {
603 if (!has_i128) return error.SkipZigTest;
636 if (!have_i128) return error.SkipZigTest;
604637
605638 const s = BigPackedStruct{ .a = 1, .b = 2 };
606639 c_big_packed_struct(s);
......@@ -943,7 +976,6 @@ extern fn c_float_array_struct(FloatArrayStruct) void;
943976extern fn c_ret_float_array_struct() FloatArrayStruct;
944977
945978test "Float array like struct" {
946 if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest;
947979 if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
948980 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
949981
......@@ -5318,7 +5350,6 @@ extern fn c_ptr_size_float_struct(Vector2) void;
53185350extern fn c_ret_ptr_size_float_struct() Vector2;
53195351
53205352test "C ABI pointer sized float struct" {
5321 if (builtin.cpu.arch == .x86) return error.SkipZigTest;
53225353 if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
53235354 if (builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
53245355 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -5348,7 +5379,6 @@ test "DC: Zig passes to C" {
53485379 try expectOk(c_assert_DC(.{ .v1 = -0.25, .v2 = 15 }));
53495380}
53505381test "DC: Zig returns to C" {
5351 if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest;
53525382 if (builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest;
53535383 if (builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
53545384 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -5363,7 +5393,6 @@ test "DC: C passes to Zig" {
53635393 try expectOk(c_send_DC());
53645394}
53655395test "DC: C returns to Zig" {
5366 if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest;
53675396 if (builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest;
53685397 if (builtin.cpu.arch.isRISCV()) return error.SkipZigTest;
53695398 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -5397,7 +5426,6 @@ test "CFF: Zig passes to C" {
53975426 try expectOk(c_assert_CFF(.{ .v1 = 39, .v2 = 0.875, .v3 = 1.0 }));
53985427}
53995428test "CFF: Zig returns to C" {
5400 if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest;
54015429 if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
54025430 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
54035431 if (builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
......@@ -5414,7 +5442,6 @@ test "CFF: C passes to Zig" {
54145442 try expectOk(c_send_CFF());
54155443}
54165444test "CFF: C returns to Zig" {
5417 if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest;
54185445 if (builtin.cpu.arch == .aarch64 and builtin.mode != .Debug) return error.SkipZigTest;
54195446 if (builtin.cpu.arch.isRISCV() and builtin.mode != .Debug) return error.SkipZigTest;
54205447 if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
......@@ -5442,28 +5469,24 @@ pub export fn zig_ret_CFF() CFF {
54425469const PD = extern struct { v1: ?*anyopaque, v2: f64 };
54435470
54445471test "PD: Zig passes to C" {
5445 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
54465472 if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
54475473 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
54485474 if (builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
54495475 try expectOk(c_assert_PD(.{ .v1 = null, .v2 = 0.5 }));
54505476}
54515477test "PD: Zig returns to C" {
5452 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
54535478 if (builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest;
54545479 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
54555480 if (builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
54565481 try expectOk(c_assert_ret_PD());
54575482}
54585483test "PD: C passes to Zig" {
5459 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
54605484 if (builtin.cpu.arch.isMIPS()) return error.SkipZigTest;
54615485 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
54625486 if (builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
54635487 try expectOk(c_send_PD());
54645488}
54655489test "PD: C returns to Zig" {
5466 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
54675490 if (builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest;
54685491 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
54695492 if (builtin.cpu.arch.isPPC64()) return error.SkipZigTest;
......@@ -5519,7 +5542,6 @@ const ByVal = extern struct {
55195542
55205543extern fn c_func_ptr_byval(*anyopaque, *anyopaque, ByVal, c_ulong, *anyopaque, c_ulong) void;
55215544test "C function that takes byval struct called via function pointer" {
5522 if (builtin.cpu.arch == .x86 and builtin.mode != .Debug) return error.SkipZigTest;
55235545 if (builtin.cpu.arch.isMIPS() and builtin.mode != .Debug) return error.SkipZigTest;
55245546 if (builtin.cpu.arch.isPPC()) return error.SkipZigTest;
55255547
......@@ -5551,7 +5573,6 @@ const f16_struct = extern struct {
55515573};
55525574extern fn c_f16_struct(f16_struct) f16_struct;
55535575test "f16 struct" {
5554 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
55555576 if (builtin.target.cpu.arch.isMIPS()) return error.SkipZigTest;
55565577 if (builtin.target.cpu.arch.isPPC()) return error.SkipZigTest;
55575578 if (builtin.target.cpu.arch.isPPC()) return error.SkipZigTest;
......@@ -5563,7 +5584,7 @@ test "f16 struct" {
55635584
55645585extern fn c_f80(f80) f80;
55655586test "f80 bare" {
5566 if (!has_f80) return error.SkipZigTest;
5587 if (!have_f80) return error.SkipZigTest;
55675588
55685589 const a = c_f80(12.34);
55695590 try expect(@as(f64, @floatCast(a)) == 56.78);
......@@ -5574,9 +5595,7 @@ const f80_struct = extern struct {
55745595};
55755596extern fn c_f80_struct(f80_struct) f80_struct;
55765597test "f80 struct" {
5577 if (!has_f80) return error.SkipZigTest;
5578 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
5579 if (builtin.zig_backend == .stage2_llvm and builtin.mode != .Debug) return error.SkipZigTest;
5598 if (!have_f80) return error.SkipZigTest;
55805599
55815600 const a = c_f80_struct(.{ .a = 12.34 });
55825601 try expect(@as(f64, @floatCast(a.a)) == 56.78);
......@@ -5588,8 +5607,7 @@ const f80_extra_struct = extern struct {
55885607};
55895608extern fn c_f80_extra_struct(f80_extra_struct) f80_extra_struct;
55905609test "f80 extra struct" {
5591 if (!has_f80) return error.SkipZigTest;
5592 if (builtin.target.cpu.arch == .x86) return error.SkipZigTest;
5610 if (!have_f80) return error.SkipZigTest;
55935611
55945612 const a = c_f80_extra_struct(.{ .a = 12.34, .b = 42 });
55955613 try expect(@as(f64, @floatCast(a.a)) == 56.78);
......@@ -5598,7 +5616,7 @@ test "f80 extra struct" {
55985616
55995617extern fn c_f128(f128) f128;
56005618test "f128 bare" {
5601 if (!has_f128) return error.SkipZigTest;
5619 if (!have_f128) return error.SkipZigTest;
56025620
56035621 const a = c_f128(12.34);
56045622 try expect(@as(f64, @floatCast(a)) == 56.78);
......@@ -5609,7 +5627,7 @@ const f128_struct = extern struct {
56095627};
56105628extern fn c_f128_struct(f128_struct) f128_struct;
56115629test "f128 struct" {
5612 if (!has_f128) return error.SkipZigTest;
5630 if (!have_f128) return error.SkipZigTest;
56135631
56145632 const a = c_f128_struct(.{ .a = 12.34 });
56155633 try expect(@as(f64, @floatCast(a.a)) == 56.78);