diff options
| author | Robin Voetter <robin@voetter.nl> | 2023-10-08 00:06:06 +0200 |
|---|---|---|
| committer | Robin Voetter <robin@voetter.nl> | 2023-10-15 14:00:01 +0200 |
| commit | 15cf1315bb945f2a14a48e2cc7ee2eaf2e0536d2 (patch) | |
| tree | 8db727c9899dda804023db1de542cab3e40a778b /src | |
| parent | 0a3e566f57063c42146aa2d64481a7eb1361f96f (diff) | |
| download | zig-15cf1315bb945f2a14a48e2cc7ee2eaf2e0536d2.tar.gz zig-15cf1315bb945f2a14a48e2cc7ee2eaf2e0536d2.zip | |
spirv: fix incorrect repr of some optional operations
Diffstat (limited to 'src')
| -rw-r--r-- | src/codegen/spirv.zig | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/src/codegen/spirv.zig b/src/codegen/spirv.zig index 82e172c0d7..41848644c4 100644 --- a/src/codegen/spirv.zig +++ b/src/codegen/spirv.zig @@ -3594,11 +3594,13 @@ const DeclGen = struct { return result_id; } - const is_non_null_id = if (optional_ty.hasRuntimeBitsIgnoreComptime(mod)) + const is_non_null_id = if (payload_ty.hasRuntimeBitsIgnoreComptime(mod)) try self.extractField(Type.bool, operand_id, 1) else // Optional representation is bool indicating whether the optional is set - operand_id; + // Optionals with no payload are represented as an (indirect) bool, so convert + // it back to the direct bool here. + try self.convertToDirect(Type.bool, operand_id); return switch (pred) { .is_null => blk: { @@ -3677,17 +3679,19 @@ const DeclGen = struct { const payload_ty = self.typeOf(ty_op.operand); if (!payload_ty.hasRuntimeBitsIgnoreComptime(mod)) { - return try self.constBool(true, .direct); + return try self.constBool(true, .indirect); } const operand_id = try self.resolve(ty_op.operand); + const optional_ty = self.typeOfIndex(inst); if (optional_ty.optionalReprIsPayload(mod)) { return operand_id; } const optional_ty_ref = try self.resolveType(optional_ty, .direct); - const members = [_]IdRef{ operand_id, try self.constBool(true, .indirect) }; + const payload_id = try self.convertToIndirect(payload_ty, operand_id); + const members = [_]IdRef{ payload_id, try self.constBool(true, .indirect) }; return try self.constructStruct(optional_ty_ref, &members); } |
