| ... | ... | @@ -10702,15 +10702,6 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 10702 | 10702 | ZigType *tag_type = enum_type->data.enumeration.tag_int_type; |
| 10703 | 10703 | assert(tag_type->id == ZigTypeIdInt || tag_type->id == ZigTypeIdComptimeInt); |
| 10704 | 10704 | |
| 10705 | | if (instr_is_comptime(enum_target)) { |
| 10706 | | ConstExprValue *val = ir_resolve_const(ira, enum_target, UndefBad); |
| 10707 | | if (!val) |
| 10708 | | return ira->codegen->invalid_instruction; |
| 10709 | | IrInstruction *result = ir_const(ira, source_instr, tag_type); |
| 10710 | | init_const_bigint(&result->value, tag_type, &val->data.x_enum_tag); |
| 10711 | | return result; |
| 10712 | | } |
| 10713 | | |
| 10714 | 10705 | // If there is only one possible tag, then we know at comptime what it is. |
| 10715 | 10706 | if (enum_type->data.enumeration.layout == ContainerLayoutAuto && |
| 10716 | 10707 | enum_type->data.enumeration.src_field_count == 1) |
| ... | ... | @@ -10722,6 +10713,15 @@ static IrInstruction *ir_analyze_enum_to_int(IrAnalyze *ira, IrInstruction *sour |
| 10722 | 10713 | return result; |
| 10723 | 10714 | } |
| 10724 | 10715 | |
| 10716 | if (instr_is_comptime(enum_target)) { |
| 10717 | ConstExprValue *val = ir_resolve_const(ira, enum_target, UndefBad); |
| 10718 | if (!val) |
| 10719 | return ira->codegen->invalid_instruction; |
| 10720 | IrInstruction *result = ir_const(ira, source_instr, tag_type); |
| 10721 | init_const_bigint(&result->value, tag_type, &val->data.x_enum_tag); |
| 10722 | return result; |
| 10723 | } |
| 10724 | |
| 10725 | 10725 | IrInstruction *result = ir_build_widen_or_shorten(&ira->new_irb, source_instr->scope, |
| 10726 | 10726 | source_instr->source_node, enum_target); |
| 10727 | 10727 | result->value.type = tag_type; |
| ... | ... | @@ -11809,11 +11809,14 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc |
| 11809 | 11809 | return ira->codegen->invalid_instruction; |
| 11810 | 11810 | } else if (type_entry->id == ZigTypeIdPointer) { |
| 11811 | 11811 | ZigType *child_type = type_entry->data.pointer.child_type; |
| 11812 | | // dereferencing a *u0 is comptime known to be 0 |
| 11813 | | if (child_type->id == ZigTypeIdInt && child_type->data.integral.bit_count == 0) { |
| 11814 | | IrInstruction *result = ir_const(ira, source_instruction, child_type); |
| 11815 | | init_const_unsigned_negative(&result->value, child_type, 0, false); |
| 11816 | | return result; |
| 11812 | // if the child type has one possible value, the deref is comptime |
| 11813 | switch (type_has_one_possible_value(ira->codegen, child_type)) { |
| 11814 | case OnePossibleValueInvalid: |
| 11815 | return ira->codegen->invalid_instruction; |
| 11816 | case OnePossibleValueYes: |
| 11817 | return ir_const(ira, source_instruction, child_type); |
| 11818 | case OnePossibleValueNo: |
| 11819 | break; |
| 11817 | 11820 | } |
| 11818 | 11821 | if (instr_is_comptime(ptr)) { |
| 11819 | 11822 | if (ptr->value.special == ConstValSpecialUndef) { |