authorgravatar for robin@voetter.nlRobin Voetter <robin@voetter.nl> 2023-05-20 17:25:17+02:00
committergravatar for 63465728+alichraghi@users.noreply.github.comAli Chraghi <63465728+alichraghi@users.noreply.github.com> 2023-05-20 08:48:38-07:00
logd7ddaf64a2978d80814ac7f57e3db2d1c6a45c2e
treef323c9076d4cef92c48d25e23ba71f1a3d4c3a1b
parentfedc9a19e7909694fac107c3da245e08616fd6e4

spirv: don't generate union tag type if it doesnt exist

Previously the tag type was generated even if it was nonexistant, triggering an assertion that an integer type should never have zero bits. Now its only generated when the tag type is actually emitted.

1 files changed, 5 insertions(+), 5 deletions(-)

src/codegen/spirv.zig+5-5
...@@ -1116,21 +1116,20 @@ pub const DeclGen = struct {...@@ -1116,21 +1116,20 @@ pub const DeclGen = struct {
1116 return self.todo("packed union types", .{});1116 return self.todo("packed union types", .{});
1117 }1117 }
11181118
1119 const tag_ty_ref = try self.resolveType(union_ty.tag_ty, .indirect);
1120 if (layout.payload_size == 0) {1119 if (layout.payload_size == 0) {
1121 // No payload, so represent this as just the tag type.1120 // No payload, so represent this as just the tag type.
1122 return tag_ty_ref;1121 return try self.resolveType(union_ty.tag_ty, .indirect);
1123 }1122 }
11241123
1125 var members = std.BoundedArray(SpvType.Payload.Struct.Member, 4){};1124 var members = std.BoundedArray(SpvType.Payload.Struct.Member, 4){};
11261125
1127 const has_tag = layout.tag_size != 0;1126 const has_tag = layout.tag_size != 0;
1128 const tag_first = layout.tag_align >= layout.payload_align;1127 const tag_first = layout.tag_align >= layout.payload_align;
1129 const tag_member = .{ .name = "tag", .ty = tag_ty_ref };
1130 const u8_ty_ref = try self.intType(.unsigned, 8); // TODO: What if Int8Type is not enabled?1128 const u8_ty_ref = try self.intType(.unsigned, 8); // TODO: What if Int8Type is not enabled?
11311129
1132 if (has_tag and tag_first) {1130 if (has_tag and tag_first) {
1133 members.appendAssumeCapacity(tag_member);1131 const tag_ty_ref = try self.resolveType(union_ty.tag_ty, .indirect);
1132 members.appendAssumeCapacity(.{ .name = "tag", .ty = tag_ty_ref });
1134 }1133 }
11351134
1136 const active_field = maybe_active_field orelse layout.most_aligned_field;1135 const active_field = maybe_active_field orelse layout.most_aligned_field;
...@@ -1149,7 +1148,8 @@ pub const DeclGen = struct {...@@ -1149,7 +1148,8 @@ pub const DeclGen = struct {
1149 }1148 }
11501149
1151 if (has_tag and !tag_first) {1150 if (has_tag and !tag_first) {
1152 members.appendAssumeCapacity(tag_member);1151 const tag_ty_ref = try self.resolveType(union_ty.tag_ty, .indirect);
1152 members.appendAssumeCapacity(.{ .name = "tag", .ty = tag_ty_ref });
1153 }1153 }
11541154
1155 if (layout.padding != 0) {1155 if (layout.padding != 0) {