authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-08 00:06:06+02:00
committergravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-10-15 14:00:01+02:00
log15cf1315bb945f2a14a48e2cc7ee2eaf2e0536d2
tree8db727c9899dda804023db1de542cab3e40a778b
parent0a3e566f57063c42146aa2d64481a7eb1361f96f
signaturebadge-check Signed by SSH key SHA256:CQ99aPxq+RueiL9u7z0FEki5Fm7V6T8q4PrEGmINrA4

spirv: fix incorrect repr of some optional operations


3 files changed, 8 insertions(+), 6 deletions(-)

src/codegen/spirv.zig+8-4
...@@ -3594,11 +3594,13 @@ const DeclGen = struct {...@@ -3594,11 +3594,13 @@ const DeclGen = struct {
3594 return result_id;3594 return result_id;
3595 }3595 }
35963596
3597 const is_non_null_id = if (optional_ty.hasRuntimeBitsIgnoreComptime(mod))3597 const is_non_null_id = if (payload_ty.hasRuntimeBitsIgnoreComptime(mod))
3598 try self.extractField(Type.bool, operand_id, 1)3598 try self.extractField(Type.bool, operand_id, 1)
3599 else3599 else
3600 // Optional representation is bool indicating whether the optional is set3600 // Optional representation is bool indicating whether the optional is set
3601 operand_id;3601 // Optionals with no payload are represented as an (indirect) bool, so convert
3602 // it back to the direct bool here.
3603 try self.convertToDirect(Type.bool, operand_id);
36023604
3603 return switch (pred) {3605 return switch (pred) {
3604 .is_null => blk: {3606 .is_null => blk: {
...@@ -3677,17 +3679,19 @@ const DeclGen = struct {...@@ -3677,17 +3679,19 @@ const DeclGen = struct {
3677 const payload_ty = self.typeOf(ty_op.operand);3679 const payload_ty = self.typeOf(ty_op.operand);
36783680
3679 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {3681 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
3680 return try self.constBool(true, .direct);3682 return try self.constBool(true, .indirect);
3681 }3683 }
36823684
3683 const operand_id = try self.resolve(ty_op.operand);3685 const operand_id = try self.resolve(ty_op.operand);
3686
3684 const optional_ty = self.typeOfIndex(inst);3687 const optional_ty = self.typeOfIndex(inst);
3685 if (optional_ty.optionalReprIsPayload(mod)) {3688 if (optional_ty.optionalReprIsPayload(mod)) {
3686 return operand_id;3689 return operand_id;
3687 }3690 }
36883691
3689 const optional_ty_ref = try self.resolveType(optional_ty, .direct);3692 const optional_ty_ref = try self.resolveType(optional_ty, .direct);
3690 const members = [_]IdRef{ operand_id, try self.constBool(true, .indirect) };3693 const payload_id = try self.convertToIndirect(payload_ty, operand_id);
3694 const members = [_]IdRef{ payload_id, try self.constBool(true, .indirect) };
3691 return try self.constructStruct(optional_ty_ref, &members);3695 return try self.constructStruct(optional_ty_ref, &members);
3692 }3696 }
36933697
test/behavior/cast.zig-1
...@@ -240,7 +240,6 @@ test "coerce undefined to optional" {...@@ -240,7 +240,6 @@ test "coerce undefined to optional" {
240 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;240 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
241 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;241 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
242 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO242 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
243 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
244243
245 try expect(MakeType(void).getNull() == null);244 try expect(MakeType(void).getNull() == null);
246 try expect(MakeType(void).getNonNull() != null);245 try expect(MakeType(void).getNonNull() != null);
test/behavior/for.zig-1
...@@ -492,7 +492,6 @@ test "inferred alloc ptr of for loop" {...@@ -492,7 +492,6 @@ test "inferred alloc ptr of for loop" {
492 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO492 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
493 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO493 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
494 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO494 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
495 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
496495
497 {496 {
498 var cond = false;497 var cond = false;