aboutsummaryrefslogtreecommitdiff
path: root/src/Sema.zig
diff options
context:
space:
mode:
authorAndrew Kelley <andrew@ziglang.org>2021-04-06 23:19:46 -0700
committerAndrew Kelley <andrew@ziglang.org>2021-04-06 23:19:46 -0700
commit19cf987198ff4de0b1460263a62ff6c41e1e3915 (patch)
tree1acbb85972fbef799c1deb4de6a8c753b9b28a9e /src/Sema.zig
parentacf9151008d5a97e5d91b34cc29f73af79062b48 (diff)
downloadzig-19cf987198ff4de0b1460263a62ff6c41e1e3915.tar.gz
zig-19cf987198ff4de0b1460263a62ff6c41e1e3915.zip
C backend: implement Enum types and values
They are lowered directly as the integer tag type, with no typedef.
Diffstat (limited to 'src/Sema.zig')
-rw-r--r--src/Sema.zig19
1 files changed, 14 insertions, 5 deletions
diff --git a/src/Sema.zig b/src/Sema.zig
index 8ff71ce8f2..115ca11858 100644
--- a/src/Sema.zig
+++ b/src/Sema.zig
@@ -1918,11 +1918,20 @@ fn zirEnumToInt(sema: *Sema, block: *Scope.Block, inst: zir.Inst.Index) InnerErr
switch (enum_tag.ty.tag()) {
.enum_full => {
const enum_full = enum_tag.ty.castTag(.enum_full).?.data;
- const val = enum_full.values.entries.items[field_index].key;
- return mod.constInst(arena, src, .{
- .ty = int_tag_ty,
- .val = val,
- });
+ if (enum_full.values.count() != 0) {
+ const val = enum_full.values.entries.items[field_index].key;
+ return mod.constInst(arena, src, .{
+ .ty = int_tag_ty,
+ .val = val,
+ });
+ } else {
+ // Field index and integer values are the same.
+ const val = try Value.Tag.int_u64.create(arena, field_index);
+ return mod.constInst(arena, src, .{
+ .ty = int_tag_ty,
+ .val = val,
+ });
+ }
},
.enum_simple => {
// Field index and integer values are the same.