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 {
35943594 return result_id;
35953595 }
35963596
3597 const is_non_null_id = if (optional_ty.hasRuntimeBitsIgnoreComptime(mod))
3597 const is_non_null_id = if (payload_ty.hasRuntimeBitsIgnoreComptime(mod))
35983598 try self.extractField(Type.bool, operand_id, 1)
35993599 else
36003600 // 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
36033605 return switch (pred) {
36043606 .is_null => blk: {
......@@ -3677,17 +3679,19 @@ const DeclGen = struct {
36773679 const payload_ty = self.typeOf(ty_op.operand);
36783680
36793681 if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) {
3680 return try self.constBool(true, .direct);
3682 return try self.constBool(true, .indirect);
36813683 }
36823684
36833685 const operand_id = try self.resolve(ty_op.operand);
3686
36843687 const optional_ty = self.typeOfIndex(inst);
36853688 if (optional_ty.optionalReprIsPayload(mod)) {
36863689 return operand_id;
36873690 }
36883691
36893692 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) };
36913695 return try self.constructStruct(optional_ty_ref, &members);
36923696 }
36933697
test/behavior/cast.zig-1
......@@ -240,7 +240,6 @@ test "coerce undefined to optional" {
240240 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest;
241241 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest;
242242 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
243 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest;
244243
245244 try expect(MakeType(void).getNull() == null);
246245 try expect(MakeType(void).getNonNull() != null);
test/behavior/for.zig-1
......@@ -492,7 +492,6 @@ test "inferred alloc ptr of for loop" {
492492 if (builtin.zig_backend == .stage2_sparc64) return error.SkipZigTest; // TODO
493493 if (builtin.zig_backend == .stage2_arm) return error.SkipZigTest; // TODO
494494 if (builtin.zig_backend == .stage2_aarch64) return error.SkipZigTest; // TODO
495 if (builtin.zig_backend == .stage2_spirv64) return error.SkipZigTest; // TODO
496495
497496 {
498497 var cond = false;