authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-17 22:13:15-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2016-12-17 22:13:15-05:00
loge73faf9a9efad4c3a8deb1ae8a21302f4366c0ac
tree055aa42c4f4fea4bb94230b5b534ff8961568bde
parentd245fabb80c83d1f2b845c42658b6f82d3f89b6f

IR: allow undefined compile time values sometimes


1 files changed, 46 insertions(+), 44 deletions(-)

src/ir.cpp+46-44
...@@ -4533,7 +4533,12 @@ static TypeTableEntry *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *ins...@@ -4533,7 +4533,12 @@ static TypeTableEntry *ir_analyze_const_usize(IrAnalyze *ira, IrInstruction *ins
4533 return ira->codegen->builtin_types.entry_usize;4533 return ira->codegen->builtin_types.entry_usize;
4534}4534}
45354535
4536static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value) {4536enum UndefAllowed {
4537 UndefOk,
4538 UndefBad,
4539};
4540
4541static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, UndefAllowed undef_allowed) {
4537 switch (value->static_value.special) {4542 switch (value->static_value.special) {
4538 case ConstValSpecialStatic:4543 case ConstValSpecialStatic:
4539 return &value->static_value;4544 return &value->static_value;
...@@ -4541,8 +4546,12 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value) {...@@ -4541,8 +4546,12 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value) {
4541 ir_add_error(ira, value, buf_sprintf("unable to evaluate constant expression"));4546 ir_add_error(ira, value, buf_sprintf("unable to evaluate constant expression"));
4542 return nullptr;4547 return nullptr;
4543 case ConstValSpecialUndef:4548 case ConstValSpecialUndef:
4544 ir_add_error(ira, value, buf_sprintf("use of undefined value"));4549 if (undef_allowed == UndefOk) {
4545 return nullptr;4550 return &value->static_value;
4551 } else {
4552 ir_add_error(ira, value, buf_sprintf("use of undefined value"));
4553 return nullptr;
4554 }
4546 case ConstValSpecialZeroes:4555 case ConstValSpecialZeroes:
4547 ir_add_error(ira, value, buf_sprintf("zeroes is deprecated"));4556 ir_add_error(ira, value, buf_sprintf("zeroes is deprecated"));
4548 return nullptr;4557 return nullptr;
...@@ -4595,10 +4604,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node...@@ -4595,10 +4604,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
4595 return result;4604 return result;
4596}4605}
45974606
4598static TypeTableEntry *ir_resolve_type_lval(IrAnalyze *ira, IrInstruction *type_value, LValPurpose lval) {4607static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
4599 if (lval != LValPurposeNone)
4600 zig_panic("TODO");
4601
4602 if (type_value->type_entry->id == TypeTableEntryIdInvalid)4608 if (type_value->type_entry->id == TypeTableEntryIdInvalid)
4603 return ira->codegen->builtin_types.entry_invalid;4609 return ira->codegen->builtin_types.entry_invalid;
46044610
...@@ -4608,17 +4614,13 @@ static TypeTableEntry *ir_resolve_type_lval(IrAnalyze *ira, IrInstruction *type_...@@ -4608,17 +4614,13 @@ static TypeTableEntry *ir_resolve_type_lval(IrAnalyze *ira, IrInstruction *type_
4608 return ira->codegen->builtin_types.entry_invalid;4614 return ira->codegen->builtin_types.entry_invalid;
4609 }4615 }
46104616
4611 ConstExprValue *const_val = ir_resolve_const(ira, type_value);4617 ConstExprValue *const_val = ir_resolve_const(ira, type_value, UndefBad);
4612 if (!const_val)4618 if (!const_val)
4613 return ira->codegen->builtin_types.entry_invalid;4619 return ira->codegen->builtin_types.entry_invalid;
46144620
4615 return const_val->data.x_type;4621 return const_val->data.x_type;
4616}4622}
46174623
4618static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
4619 return ir_resolve_type_lval(ira, type_value, LValPurposeNone);
4620}
4621
4622static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {4624static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
4623 if (fn_value == ira->codegen->invalid_instruction)4625 if (fn_value == ira->codegen->invalid_instruction)
4624 return nullptr;4626 return nullptr;
...@@ -4632,7 +4634,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {...@@ -4632,7 +4634,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
4632 return nullptr;4634 return nullptr;
4633 }4635 }
46344636
4635 ConstExprValue *const_val = ir_resolve_const(ira, fn_value);4637 ConstExprValue *const_val = ir_resolve_const(ira, fn_value, UndefBad);
4636 if (!const_val)4638 if (!const_val)
4637 return nullptr;4639 return nullptr;
46384640
...@@ -4643,7 +4645,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc...@@ -4643,7 +4645,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
4643 assert(wanted_type->id == TypeTableEntryIdMaybe);4645 assert(wanted_type->id == TypeTableEntryIdMaybe);
46444646
4645 if (instr_is_comptime(value)) {4647 if (instr_is_comptime(value)) {
4646 ConstExprValue *val = ir_resolve_const(ira, value);4648 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
4647 if (!val)4649 if (!val)
4648 return ira->codegen->invalid_instruction;4650 return ira->codegen->invalid_instruction;
46494651
...@@ -4667,7 +4669,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction...@@ -4667,7 +4669,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
4667 assert(wanted_type->id == TypeTableEntryIdErrorUnion);4669 assert(wanted_type->id == TypeTableEntryIdErrorUnion);
46684670
4669 if (instr_is_comptime(value)) {4671 if (instr_is_comptime(value)) {
4670 ConstExprValue *val = ir_resolve_const(ira, value);4672 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
4671 if (!val)4673 if (!val)
4672 return ira->codegen->invalid_instruction;4674 return ira->codegen->invalid_instruction;
46734675
...@@ -4692,7 +4694,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so...@@ -4692,7 +4694,7 @@ static IrInstruction *ir_analyze_err_wrap_code(IrAnalyze *ira, IrInstruction *so
4692 assert(wanted_type->id == TypeTableEntryIdErrorUnion);4694 assert(wanted_type->id == TypeTableEntryIdErrorUnion);
46934695
4694 if (instr_is_comptime(value)) {4696 if (instr_is_comptime(value)) {
4695 ConstExprValue *val = ir_resolve_const(ira, value);4697 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
4696 if (!val)4698 if (!val)
4697 return ira->codegen->invalid_instruction;4699 return ira->codegen->invalid_instruction;
46984700
...@@ -4717,7 +4719,7 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so...@@ -4717,7 +4719,7 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
4717 assert(wanted_type->id == TypeTableEntryIdMaybe);4719 assert(wanted_type->id == TypeTableEntryIdMaybe);
4718 assert(instr_is_comptime(value));4720 assert(instr_is_comptime(value));
47194721
4720 ConstExprValue *val = ir_resolve_const(ira, value);4722 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
4721 assert(val);4723 assert(val);
47224724
4723 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, source_instr->scope, source_instr->source_node);4725 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(ira->new_irb.exec, source_instr->scope, source_instr->source_node);
...@@ -5020,7 +5022,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc...@@ -5020,7 +5022,7 @@ static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruc
5020 load_ptr_instruction->type_entry = child_type;5022 load_ptr_instruction->type_entry = child_type;
5021 return load_ptr_instruction;5023 return load_ptr_instruction;
5022 } else if (type_entry->id == TypeTableEntryIdMetaType) {5024 } else if (type_entry->id == TypeTableEntryIdMetaType) {
5023 ConstExprValue *ptr_val = ir_resolve_const(ira, ptr);5025 ConstExprValue *ptr_val = ir_resolve_const(ira, ptr, UndefBad);
5024 if (!ptr_val)5026 if (!ptr_val)
5025 return ira->codegen->invalid_instruction;5027 return ira->codegen->invalid_instruction;
50265028
...@@ -5047,7 +5049,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst...@@ -5047,7 +5049,7 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst
50475049
5048 bool is_inline = ir_should_inline(&ira->new_irb);5050 bool is_inline = ir_should_inline(&ira->new_irb);
5049 if (is_inline || value->static_value.special != ConstValSpecialRuntime) {5051 if (is_inline || value->static_value.special != ConstValSpecialRuntime) {
5050 ConstExprValue *val = ir_resolve_const(ira, value);5052 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
5051 if (!val)5053 if (!val)
5052 return ira->codegen->builtin_types.entry_invalid;5054 return ira->codegen->builtin_types.entry_invalid;
5053 bool ptr_is_const = true;5055 bool ptr_is_const = true;
...@@ -5071,7 +5073,7 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out...@@ -5071,7 +5073,7 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out
5071 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)5073 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
5072 return false;5074 return false;
50735075
5074 ConstExprValue *const_val = ir_resolve_const(ira, casted_value);5076 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
5075 if (!const_val)5077 if (!const_val)
5076 return false;5078 return false;
50775079
...@@ -5087,7 +5089,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {...@@ -5087,7 +5089,7 @@ static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
5087 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)5089 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
5088 return false;5090 return false;
50895091
5090 ConstExprValue *const_val = ir_resolve_const(ira, casted_value);5092 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
5091 if (!const_val)5093 if (!const_val)
5092 return false;5094 return false;
50935095
...@@ -5103,7 +5105,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic...@@ -5103,7 +5105,7 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
5103 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)5105 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
5104 return false;5106 return false;
51055107
5106 ConstExprValue *const_val = ir_resolve_const(ira, casted_value);5108 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
5107 if (!const_val)5109 if (!const_val)
5108 return false;5110 return false;
51095111
...@@ -5120,7 +5122,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {...@@ -5120,7 +5122,7 @@ static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
5120 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)5122 if (casted_value->type_entry->id == TypeTableEntryIdInvalid)
5121 return nullptr;5123 return nullptr;
51225124
5123 ConstExprValue *const_val = ir_resolve_const(ira, casted_value);5125 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
5124 if (!const_val)5126 if (!const_val)
5125 return nullptr;5127 return nullptr;
51265128
...@@ -5504,11 +5506,11 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *...@@ -5504,11 +5506,11 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
5504 if (op2_canon_type->id == TypeTableEntryIdInvalid)5506 if (op2_canon_type->id == TypeTableEntryIdInvalid)
5505 return ira->codegen->builtin_types.entry_invalid;5507 return ira->codegen->builtin_types.entry_invalid;
55065508
5507 ConstExprValue *op1_val = ir_resolve_const(ira, op1);5509 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
5508 if (!op1_val)5510 if (!op1_val)
5509 return ira->codegen->builtin_types.entry_invalid;5511 return ira->codegen->builtin_types.entry_invalid;
55105512
5511 ConstExprValue *op2_val = ir_resolve_const(ira, op2);5513 ConstExprValue *op2_val = ir_resolve_const(ira, op2, UndefBad);
5512 if (!op2_val)5514 if (!op2_val)
5513 return ira->codegen->builtin_types.entry_invalid;5515 return ira->codegen->builtin_types.entry_invalid;
55145516
...@@ -5620,7 +5622,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp...@@ -5620,7 +5622,7 @@ static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp
5620 if (op2->type_entry->id == TypeTableEntryIdInvalid)5622 if (op2->type_entry->id == TypeTableEntryIdInvalid)
5621 return ira->codegen->builtin_types.entry_invalid;5623 return ira->codegen->builtin_types.entry_invalid;
56225624
5623 ConstExprValue *array_val = ir_resolve_const(ira, op1);5625 ConstExprValue *array_val = ir_resolve_const(ira, op1, UndefBad);
5624 if (!array_val)5626 if (!array_val)
5625 return ira->codegen->builtin_types.entry_invalid;5627 return ira->codegen->builtin_types.entry_invalid;
56265628
...@@ -5825,7 +5827,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node...@@ -5825,7 +5827,7 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
5825 if (casted_arg->type_entry->id == TypeTableEntryIdInvalid)5827 if (casted_arg->type_entry->id == TypeTableEntryIdInvalid)
5826 return false;5828 return false;
58275829
5828 ConstExprValue *first_arg_val = ir_resolve_const(ira, casted_arg);5830 ConstExprValue *first_arg_val = ir_resolve_const(ira, casted_arg, UndefBad);
5829 if (!first_arg_val)5831 if (!first_arg_val)
5830 return false;5832 return false;
58315833
...@@ -5862,7 +5864,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod...@@ -5862,7 +5864,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
58625864
5863 bool inline_arg = param_decl_node->data.param_decl.is_inline;5865 bool inline_arg = param_decl_node->data.param_decl.is_inline;
5864 if (inline_arg || is_var_type) {5866 if (inline_arg || is_var_type) {
5865 ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg);5867 ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefBad);
5866 if (!arg_val)5868 if (!arg_val)
5867 return false;5869 return false;
58685870
...@@ -6797,7 +6799,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -6797,7 +6799,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
6797 return ira->codegen->builtin_types.entry_invalid;6799 return ira->codegen->builtin_types.entry_invalid;
6798 }6800 }
6799 } else if (container_type->id == TypeTableEntryIdMetaType) {6801 } else if (container_type->id == TypeTableEntryIdMetaType) {
6800 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr);6802 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
6801 if (!container_ptr_val)6803 if (!container_ptr_val)
6802 return ira->codegen->builtin_types.entry_invalid;6804 return ira->codegen->builtin_types.entry_invalid;
68036805
...@@ -6880,7 +6882,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -6880,7 +6882,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
6880 }6882 }
6881 } else if (container_type->id == TypeTableEntryIdNamespace) {6883 } else if (container_type->id == TypeTableEntryIdNamespace) {
6882 assert(container_ptr->type_entry->id == TypeTableEntryIdPointer);6884 assert(container_ptr->type_entry->id == TypeTableEntryIdPointer);
6883 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr);6885 ConstExprValue *container_ptr_val = ir_resolve_const(ira, container_ptr, UndefBad);
6884 if (!container_ptr_val)6886 if (!container_ptr_val)
6885 return ira->codegen->builtin_types.entry_invalid;6887 return ira->codegen->builtin_types.entry_invalid;
68866888
...@@ -7148,7 +7150,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,...@@ -7148,7 +7150,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
7148 TypeTableEntry *target_type = target_instruction->type_entry;7150 TypeTableEntry *target_type = target_instruction->type_entry;
7149 if (target_type->id == TypeTableEntryIdInvalid)7151 if (target_type->id == TypeTableEntryIdInvalid)
7150 return ira->codegen->builtin_types.entry_invalid;7152 return ira->codegen->builtin_types.entry_invalid;
7151 ConstExprValue *target_val = ir_resolve_const(ira, target_instruction);7153 ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);
7152 if (!target_val)7154 if (!target_val)
7153 return ira->codegen->builtin_types.entry_invalid;7155 return ira->codegen->builtin_types.entry_invalid;
71547156
...@@ -7495,7 +7497,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -7495,7 +7497,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
7495 TypeTableEntry *result_type = get_pointer_to_type(ira->codegen, child_type, false);7497 TypeTableEntry *result_type = get_pointer_to_type(ira->codegen, child_type, false);
74967498
7497 if (instr_is_comptime(value)) {7499 if (instr_is_comptime(value)) {
7498 ConstExprValue *val = ir_resolve_const(ira, value);7500 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
7499 if (!val)7501 if (!val)
7500 return ira->codegen->builtin_types.entry_invalid;7502 return ira->codegen->builtin_types.entry_invalid;
7501 ConstExprValue *maybe_val = val->data.x_ptr.base_ptr;7503 ConstExprValue *maybe_val = val->data.x_ptr.base_ptr;
...@@ -7579,7 +7581,7 @@ static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_...@@ -7579,7 +7581,7 @@ static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_
7579 }7581 }
75807582
7581 if (instr_is_comptime(value)) {7583 if (instr_is_comptime(value)) {
7582 ConstExprValue *val = ir_resolve_const(ira, value);7584 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
7583 if (!val)7585 if (!val)
7584 return ira->codegen->invalid_instruction;7586 return ira->codegen->invalid_instruction;
75857587
...@@ -7606,7 +7608,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -7606,7 +7608,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
7606 bool is_inline = ir_should_inline(&ira->new_irb) || switch_br_instruction->is_inline;7608 bool is_inline = ir_should_inline(&ira->new_irb) || switch_br_instruction->is_inline;
76077609
7608 if (is_inline || instr_is_comptime(target_value)) {7610 if (is_inline || instr_is_comptime(target_value)) {
7609 ConstExprValue *target_val = ir_resolve_const(ira, target_value);7611 ConstExprValue *target_val = ir_resolve_const(ira, target_value, UndefBad);
7610 if (!target_val)7612 if (!target_val)
7611 return ir_unreach_error(ira);7613 return ir_unreach_error(ira);
76127614
...@@ -7626,7 +7628,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -7626,7 +7628,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
7626 if (casted_case_value->type_entry->id == TypeTableEntryIdInvalid)7628 if (casted_case_value->type_entry->id == TypeTableEntryIdInvalid)
7627 return ir_unreach_error(ira);7629 return ir_unreach_error(ira);
76287630
7629 ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value);7631 ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad);
7630 if (!case_val)7632 if (!case_val)
7631 return ir_unreach_error(ira);7633 return ir_unreach_error(ira);
76327634
...@@ -7666,7 +7668,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,...@@ -7666,7 +7668,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
7666 if (casted_new_value->type_entry->id == TypeTableEntryIdInvalid)7668 if (casted_new_value->type_entry->id == TypeTableEntryIdInvalid)
7667 continue;7669 continue;
76687670
7669 if (!ir_resolve_const(ira, casted_new_value))7671 if (!ir_resolve_const(ira, casted_new_value, UndefBad))
7670 continue;7672 continue;
76717673
7672 new_case->value = casted_new_value;7674 new_case->value = casted_new_value;
...@@ -7776,7 +7778,7 @@ static TypeTableEntry *ir_analyze_instruction_static_eval(IrAnalyze *ira,...@@ -7776,7 +7778,7 @@ static TypeTableEntry *ir_analyze_instruction_static_eval(IrAnalyze *ira,
7776 if (value->type_entry->id == TypeTableEntryIdInvalid)7778 if (value->type_entry->id == TypeTableEntryIdInvalid)
7777 return ira->codegen->builtin_types.entry_invalid;7779 return ira->codegen->builtin_types.entry_invalid;
77787780
7779 ConstExprValue *val = ir_resolve_const(ira, value);7781 ConstExprValue *val = ir_resolve_const(ira, value, UndefBad);
7780 if (!val)7782 if (!val)
7781 return ira->codegen->builtin_types.entry_invalid;7783 return ira->codegen->builtin_types.entry_invalid;
77827784
...@@ -7949,7 +7951,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -7949,7 +7951,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
79497951
7950 if (const_val.special == ConstValSpecialStatic) {7952 if (const_val.special == ConstValSpecialStatic) {
7951 if (outside_fn || field_value->static_value.special != ConstValSpecialRuntime) {7953 if (outside_fn || field_value->static_value.special != ConstValSpecialRuntime) {
7952 ConstExprValue *field_val = ir_resolve_const(ira, field_value);7954 ConstExprValue *field_val = ir_resolve_const(ira, field_value, UndefOk);
7953 if (!field_val)7955 if (!field_val)
7954 return ira->codegen->builtin_types.entry_invalid;7956 return ira->codegen->builtin_types.entry_invalid;
79557957
...@@ -8030,7 +8032,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira...@@ -8030,7 +8032,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
80308032
8031 if (const_val.special == ConstValSpecialStatic) {8033 if (const_val.special == ConstValSpecialStatic) {
8032 if (outside_fn || arg_value->static_value.special != ConstValSpecialRuntime) {8034 if (outside_fn || arg_value->static_value.special != ConstValSpecialRuntime) {
8033 ConstExprValue *elem_val = ir_resolve_const(ira, arg_value);8035 ConstExprValue *elem_val = ir_resolve_const(ira, arg_value, UndefBad);
8034 if (!elem_val)8036 if (!elem_val)
8035 return ira->codegen->builtin_types.entry_invalid;8037 return ira->codegen->builtin_types.entry_invalid;
80368038
...@@ -8494,8 +8496,8 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru...@@ -8494,8 +8496,8 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru
8494 if (casted_op1->static_value.special == ConstValSpecialStatic &&8496 if (casted_op1->static_value.special == ConstValSpecialStatic &&
8495 casted_op2->static_value.special == ConstValSpecialStatic)8497 casted_op2->static_value.special == ConstValSpecialStatic)
8496 {8498 {
8497 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1);8499 ConstExprValue *op1_val = ir_resolve_const(ira, casted_op1, UndefBad);
8498 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2);8500 ConstExprValue *op2_val = ir_resolve_const(ira, casted_op2, UndefBad);
8499 assert(op1_val);8501 assert(op1_val);
8500 assert(op2_val);8502 assert(op2_val);
85018503
...@@ -9140,7 +9142,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc...@@ -9140,7 +9142,7 @@ static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstruc
9140 return ira->codegen->builtin_types.entry_invalid;9142 return ira->codegen->builtin_types.entry_invalid;
9141 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {9143 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
9142 if (instr_is_comptime(value)) {9144 if (instr_is_comptime(value)) {
9143 ConstExprValue *ptr_val = ir_resolve_const(ira, value);9145 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
9144 if (!ptr_val)9146 if (!ptr_val)
9145 return ira->codegen->builtin_types.entry_invalid;9147 return ira->codegen->builtin_types.entry_invalid;
9146 ConstExprValue *err_union_val = ptr_val->data.x_ptr.base_ptr;9148 ConstExprValue *err_union_val = ptr_val->data.x_ptr.base_ptr;
...@@ -9181,7 +9183,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,...@@ -9181,7 +9183,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
9181 return ira->codegen->builtin_types.entry_invalid;9183 return ira->codegen->builtin_types.entry_invalid;
9182 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {9184 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
9183 if (instr_is_comptime(value)) {9185 if (instr_is_comptime(value)) {
9184 ConstExprValue *ptr_val = ir_resolve_const(ira, value);9186 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
9185 if (!ptr_val)9187 if (!ptr_val)
9186 return ira->codegen->builtin_types.entry_invalid;9188 return ira->codegen->builtin_types.entry_invalid;
9187 ConstExprValue *err_union_val = ptr_val->data.x_ptr.base_ptr;9189 ConstExprValue *err_union_val = ptr_val->data.x_ptr.base_ptr;
...@@ -9226,7 +9228,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,...@@ -9226,7 +9228,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
9226 TypeTableEntry *child_type = canon_type->data.error.child_type;9228 TypeTableEntry *child_type = canon_type->data.error.child_type;
9227 TypeTableEntry *result_type = get_pointer_to_type(ira->codegen, child_type, false);9229 TypeTableEntry *result_type = get_pointer_to_type(ira->codegen, child_type, false);
9228 if (instr_is_comptime(value)) {9230 if (instr_is_comptime(value)) {
9229 ConstExprValue *ptr_val = ir_resolve_const(ira, value);9231 ConstExprValue *ptr_val = ir_resolve_const(ira, value, UndefBad);
9230 if (!ptr_val)9232 if (!ptr_val)
9231 return ira->codegen->builtin_types.entry_invalid;9233 return ira->codegen->builtin_types.entry_invalid;
9232 ConstExprValue *err_union_val = ptr_val->data.x_ptr.base_ptr;9234 ConstExprValue *err_union_val = ptr_val->data.x_ptr.base_ptr;