| author | |
| committer | |
| log | 485082064aa3dee6cffec8db9f8146f1cf2aefbc |
| tree | 7abdd1feefb22e672f7bb2d5edbc5f5752784309 |
| parent | d6e6162081ca853c8f3cf293b559e4e6d7d2a917 |
| signature |
2 files changed, 18 insertions(+), 5 deletions(-)
src/arch/aarch64/CodeGen.zig+18-3| ... | @@ -4043,9 +4043,24 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { | ... | @@ -4043,9 +4043,24 @@ fn airStructFieldVal(self: *Self, inst: Air.Inst.Index) !void { |
| 4043 | 4043 | ||
| 4044 | fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void { | 4044 | fn airFieldParentPtr(self: *Self, inst: Air.Inst.Index) !void { |
| 4045 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; | 4045 | const ty_pl = self.air.instructions.items(.data)[inst].ty_pl; |
| 4046 | const extra = self.air.extraData(Air.StructField, ty_pl.payload).data; | 4046 | const extra = self.air.extraData(Air.FieldParentPtr, ty_pl.payload).data; |
| 4047 | _ = extra; | 4047 | const result: MCValue = if (self.liveness.isUnused(inst)) .dead else result: { |
| 4048 | return self.fail("TODO implement codegen airFieldParentPtr", .{}); | 4048 | const field_ptr = try self.resolveInst(extra.field_ptr); |
| 4049 | const struct_ty = self.air.getRefType(ty_pl.ty).childType(); | ||
| 4050 | const struct_field_offset = @intCast(u32, struct_ty.structFieldOffset(extra.field_index, self.target.*)); | ||
| 4051 | switch (field_ptr) { | ||
| 4052 | .ptr_stack_offset => |off| { | ||
| 4053 | break :result MCValue{ .ptr_stack_offset = off + struct_field_offset }; | ||
| 4054 | }, | ||
| 4055 | else => { | ||
| 4056 | const lhs_bind: ReadArg.Bind = .{ .mcv = field_ptr }; | ||
| 4057 | const rhs_bind: ReadArg.Bind = .{ .mcv = .{ .immediate = struct_field_offset } }; | ||
| 4058 | |||
| 4059 | break :result try self.addSub(.sub, lhs_bind, rhs_bind, Type.usize, Type.usize, null); | ||
| 4060 | }, | ||
| 4061 | } | ||
| 4062 | }; | ||
| 4063 | return self.finishAir(inst, result, .{ extra.field_ptr, .none, .none }); | ||
| 4049 | } | 4064 | } |
| 4050 | 4065 | ||
| 4051 | fn airArg(self: *Self, inst: Air.Inst.Index) !void { | 4066 | fn airArg(self: *Self, inst: Air.Inst.Index) !void { |
test/behavior/field_parent_ptr.zig-2| ... | @@ -2,7 +2,6 @@ const expect = @import("std").testing.expect; | ... | @@ -2,7 +2,6 @@ const expect = @import("std").testing.expect; |
| 2 | const builtin = @import("builtin"); | 2 | const builtin = @import("builtin"); |
| 3 | 3 | ||
| 4 | test "@fieldParentPtr non-first field" { | 4 | test "@fieldParentPtr non-first field" { |
| 5 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 6 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 5 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 7 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 6 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 8 | try testParentFieldPtr(&foo.c); | 7 | try testParentFieldPtr(&foo.c); |
| ... | @@ -10,7 +9,6 @@ test "@fieldParentPtr non-first field" { | ... | @@ -10,7 +9,6 @@ test "@fieldParentPtr non-first field" { |
| 10 | } | 9 | } |
| 11 | 10 | ||
| 12 | test "@fieldParentPtr first field" { | 11 | test "@fieldParentPtr first field" { |
| 13 | if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; | ||
| 14 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; | 12 | if (builtin.zig_backend == .stage2_x86_64) return error.SkipZigTest; |
| 15 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO | 13 | if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO |
| 16 | try testParentFieldPtrFirst(&foo.a); | 14 | try testParentFieldPtrFirst(&foo.a); |