diff options
| author | Andrew Kelley <andrew@ziglang.org> | 2021-04-06 23:19:46 -0700 |
|---|---|---|
| committer | Andrew Kelley <andrew@ziglang.org> | 2021-04-06 23:19:46 -0700 |
| commit | 19cf987198ff4de0b1460263a62ff6c41e1e3915 (patch) | |
| tree | 1acbb85972fbef799c1deb4de6a8c753b9b28a9e /src/Sema.zig | |
| parent | acf9151008d5a97e5d91b34cc29f73af79062b48 (diff) | |
| download | zig-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.zig | 19 |
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. |
