diff options
| author | LemonBoy <thatlemon@gmail.com> | 2020-12-05 18:52:25 +0100 |
|---|---|---|
| committer | LemonBoy <thatlemon@gmail.com> | 2020-12-05 18:58:37 +0100 |
| commit | 865d6df03e20b3338bafb15c23bce6b5912ecf88 (patch) | |
| tree | 1ca85a887e3057457c672397c4d9925d0c954eaa /src | |
| parent | b6b7a6401c064582b610b8ca6935a388c3bb3c03 (diff) | |
| download | zig-865d6df03e20b3338bafb15c23bce6b5912ecf88.tar.gz zig-865d6df03e20b3338bafb15c23bce6b5912ecf88.zip | |
stage1: Fix constant folding of single-element enums
Fill in the correct value instead of leaving everything uninitialized.
This problem can be noticed in behavior/union.zig but it's masked by
some other "optimization" kicking in at the wrong time, the following
commits will address that.
Diffstat (limited to 'src')
| -rw-r--r-- | src/stage1/analyze.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/src/stage1/analyze.cpp b/src/stage1/analyze.cpp index c5a4a7aa2c..5b0ea53eb4 100644 --- a/src/stage1/analyze.cpp +++ b/src/stage1/analyze.cpp @@ -6122,6 +6122,11 @@ ZigValue *get_the_one_possible_value(CodeGen *g, ZigType *type_entry) { result->data.x_ptr.mut = ConstPtrMutComptimeConst; result->data.x_ptr.special = ConstPtrSpecialRef; result->data.x_ptr.data.ref.pointee = get_the_one_possible_value(g, result->type->data.pointer.child_type); + } else if (result->type->id == ZigTypeIdEnum) { + ZigType *enum_type = result->type; + assert(enum_type->data.enumeration.src_field_count == 1); + TypeEnumField *only_field = &result->type->data.enumeration.fields[0]; + bigint_init_bigint(&result->data.x_enum_tag, &only_field->value); } g->one_possible_values.put(type_entry, result); return result; |
