authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-09-17 14:01:11+02:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-09-23 12:36:56-07:00
log5141b4e05c08f394c4c0e76ea73f0547c9854288
tree1bea56ac716e6b973b0948fc0b5605a72708fbf0
parenta86c939857f494a1d8f5749db1a10f008cd40ef3

spirv: fix store of undef


1 files changed, 2 insertions(+), 9 deletions(-)

src/codegen/spirv.zig+2-9
...@@ -2753,20 +2753,12 @@ pub const DeclGen = struct {...@@ -2753,20 +2753,12 @@ pub const DeclGen = struct {
2753 }2753 }
27542754
2755 fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void {2755 fn airStore(self: *DeclGen, inst: Air.Inst.Index) !void {
2756 const mod = self.module;
2757 const bin_op = self.air.instructions.items(.data)[inst].bin_op;2756 const bin_op = self.air.instructions.items(.data)[inst].bin_op;
2758 const ptr_ty = self.typeOf(bin_op.lhs);2757 const ptr_ty = self.typeOf(bin_op.lhs);
2759 const ptr = try self.resolve(bin_op.lhs);2758 const ptr = try self.resolve(bin_op.lhs);
2760 const value = try self.resolve(bin_op.rhs);2759 const value = try self.resolve(bin_op.rhs);
2761 const ptr_ty_ref = try self.resolveType(ptr_ty, .direct);
27622760
2763 const val_is_undef = if (try self.air.value(bin_op.rhs, mod)) |val| val.isUndefDeep(mod) else false;2761 try self.store(ptr_ty, ptr, value);
2764 if (val_is_undef) {
2765 const undef = try self.spv.constUndef(ptr_ty_ref);
2766 try self.store(ptr_ty, ptr, undef);
2767 } else {
2768 try self.store(ptr_ty, ptr, value);
2769 }
2770 }2762 }
27712763
2772 fn airLoop(self: *DeclGen, inst: Air.Inst.Index) !void {2764 fn airLoop(self: *DeclGen, inst: Air.Inst.Index) !void {
...@@ -2790,6 +2782,7 @@ pub const DeclGen = struct {...@@ -2790,6 +2782,7 @@ pub const DeclGen = struct {
2790 const operand_ty = self.typeOf(operand);2782 const operand_ty = self.typeOf(operand);
2791 const mod = self.module;2783 const mod = self.module;
2792 if (operand_ty.hasRuntimeBits(mod)) {2784 if (operand_ty.hasRuntimeBits(mod)) {
2785 // TODO: If we return an empty struct, this branch is also hit incorrectly.
2793 const operand_id = try self.resolve(operand);2786 const operand_id = try self.resolve(operand);
2794 try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{ .value = operand_id });2787 try self.func.body.emit(self.spv.gpa, .OpReturnValue, .{ .value = operand_id });
2795 } else {2788 } else {