| ... | ... | @@ -5356,11 +5356,6 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5356 | 5356 | // Ensure complete type definition is visible before accessing fields. |
| 5357 | 5357 | _ = try f.typeToIndex(struct_ty, .complete); |
| 5358 | 5358 | |
| 5359 | | const extra_name: CValue = switch (struct_ty.tag()) { |
| 5360 | | .union_tagged, .union_safety_tagged => .{ .identifier = "payload" }, |
| 5361 | | else => .none, |
| 5362 | | }; |
| 5363 | | |
| 5364 | 5359 | const field_name: CValue = switch (struct_ty.tag()) { |
| 5365 | 5360 | .tuple, .anon_struct, .@"struct" => switch (struct_ty.containerLayout()) { |
| 5366 | 5361 | .Auto, .Extern => if (struct_ty.isSimpleTuple()) |
| ... | ... | @@ -5458,31 +5453,29 @@ fn airStructFieldVal(f: *Function, inst: Air.Inst.Index) !CValue { |
| 5458 | 5453 | } |
| 5459 | 5454 | |
| 5460 | 5455 | return local; |
| 5461 | | } else .{ |
| 5462 | | .identifier = struct_ty.unionFields().keys()[extra.field_index], |
| 5456 | } else field_name: { |
| 5457 | const name = struct_ty.unionFields().keys()[extra.field_index]; |
| 5458 | break :field_name if (struct_ty.unionTagTypeSafety()) |_| |
| 5459 | .{ .payload_identifier = name } |
| 5460 | else |
| 5461 | .{ .identifier = name }; |
| 5463 | 5462 | }, |
| 5464 | 5463 | else => unreachable, |
| 5465 | 5464 | }; |
| 5466 | 5465 | |
| 5467 | | const is_array = lowersToArray(inst_ty, target); |
| 5468 | 5466 | const local = try f.allocLocal(inst, inst_ty); |
| 5469 | | if (is_array) { |
| 5467 | if (lowersToArray(inst_ty, target)) { |
| 5470 | 5468 | try writer.writeAll("memcpy("); |
| 5471 | 5469 | try f.writeCValue(writer, local, .FunctionArgument); |
| 5472 | 5470 | try writer.writeAll(", "); |
| 5473 | | } else { |
| 5474 | | try f.writeCValue(writer, local, .Other); |
| 5475 | | try writer.writeAll(" = "); |
| 5476 | | } |
| 5477 | | if (extra_name != .none) { |
| 5478 | | try f.writeCValueMember(writer, struct_byval, extra_name); |
| 5479 | | try writer.writeByte('.'); |
| 5480 | | try f.writeCValue(writer, field_name, .Other); |
| 5481 | | } else try f.writeCValueMember(writer, struct_byval, field_name); |
| 5482 | | if (is_array) { |
| 5471 | try f.writeCValueMember(writer, struct_byval, field_name); |
| 5483 | 5472 | try writer.writeAll(", sizeof("); |
| 5484 | 5473 | try f.renderType(writer, inst_ty); |
| 5485 | 5474 | try writer.writeAll("))"); |
| 5475 | } else { |
| 5476 | try f.writeCValue(writer, local, .Other); |
| 5477 | try writer.writeAll(" = "); |
| 5478 | try f.writeCValueMember(writer, struct_byval, field_name); |
| 5486 | 5479 | } |
| 5487 | 5480 | try writer.writeAll(";\n"); |
| 5488 | 5481 | return local; |
| ... | ... | @@ -6700,7 +6693,7 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6700 | 6693 | return local; |
| 6701 | 6694 | } |
| 6702 | 6695 | |
| 6703 | | if (union_ty.unionTagTypeSafety()) |tag_ty| { |
| 6696 | const field: CValue = if (union_ty.unionTagTypeSafety()) |tag_ty| field: { |
| 6704 | 6697 | const layout = union_ty.unionGetLayout(target); |
| 6705 | 6698 | if (layout.tag_size != 0) { |
| 6706 | 6699 | const field_index = tag_ty.enumFieldIndex(field_name).?; |
| ... | ... | @@ -6717,18 +6710,13 @@ fn airUnionInit(f: *Function, inst: Air.Inst.Index) !CValue { |
| 6717 | 6710 | try f.writeCValue(writer, local, .Other); |
| 6718 | 6711 | try writer.print(".tag = {}; ", .{try f.fmtIntLiteral(tag_ty, int_val)}); |
| 6719 | 6712 | } |
| 6720 | | try f.writeCValue(writer, local, .Other); |
| 6721 | | try writer.print(".payload.{ } = ", .{fmtIdent(field_name)}); |
| 6722 | | try f.writeCValue(writer, payload, .Other); |
| 6723 | | try writer.writeAll(";\n"); |
| 6724 | | return local; |
| 6725 | | } |
| 6713 | break :field .{ .payload_identifier = field_name }; |
| 6714 | } else .{ .identifier = field_name }; |
| 6726 | 6715 | |
| 6727 | | try f.writeCValue(writer, local, .Other); |
| 6728 | | try writer.print(".{ } = ", .{fmtIdent(field_name)}); |
| 6716 | try f.writeCValueMember(writer, local, field); |
| 6717 | try writer.writeAll(" = "); |
| 6729 | 6718 | try f.writeCValue(writer, payload, .Other); |
| 6730 | 6719 | try writer.writeAll(";\n"); |
| 6731 | | |
| 6732 | 6720 | return local; |
| 6733 | 6721 | } |
| 6734 | 6722 | |