authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-20 19:56:07-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-02-20 19:56:07-05:00
log4709fe1176ce88a35e877622dc977948846a3a43
tree89c8a5e0c2b1d6ce4d34ef6e3cc6d474289d30d1
parentc4ee37f5067e7dd2c017df1fd6c57c1fad92cf85

more robust detection of types that failed to resolve


3 files changed, 246 insertions(+), 196 deletions(-)

src/analyze.cpp+2
......@@ -1120,6 +1120,8 @@ bool type_is_invalid(TypeTableEntry *type_entry) {
11201120 return type_entry->data.enumeration.is_invalid;
11211121 case TypeTableEntryIdUnion:
11221122 return type_entry->data.unionation.is_invalid;
1123 case TypeTableEntryIdTypeDecl:
1124 return type_is_invalid(type_entry->data.type_decl.canonical_type);
11231125 default:
11241126 return false;
11251127 }
src/ir.cpp+206-190
......@@ -5705,7 +5705,7 @@ static bool ir_emit_global_runtime_side_effect(IrAnalyze *ira, IrInstruction *so
57055705static bool ir_num_lit_fits_in_other_type(IrAnalyze *ira, IrInstruction *instruction, TypeTableEntry *other_type) {
57065706 TypeTableEntry *other_type_underlying = get_underlying_type(other_type);
57075707
5708 if (other_type_underlying->id == TypeTableEntryIdInvalid) {
5708 if (type_is_invalid(other_type_underlying)) {
57095709 return false;
57105710 }
57115711
......@@ -5865,7 +5865,7 @@ static ImplicitCastMatchResult ir_types_match_with_implicit_cast(IrAnalyze *ira,
58655865static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_node, IrInstruction **instructions, size_t instruction_count) {
58665866 assert(instruction_count >= 1);
58675867 IrInstruction *prev_inst = instructions[0];
5868 if (prev_inst->value.type->id == TypeTableEntryIdInvalid) {
5868 if (type_is_invalid(prev_inst->value.type)) {
58695869 return ira->codegen->builtin_types.entry_invalid;
58705870 }
58715871 bool any_are_pure_error = (prev_inst->value.type->id == TypeTableEntryIdPureError);
......@@ -5874,7 +5874,7 @@ static TypeTableEntry *ir_resolve_peer_types(IrAnalyze *ira, AstNode *source_nod
58745874 IrInstruction *cur_inst = instructions[i];
58755875 TypeTableEntry *cur_type = cur_inst->value.type;
58765876 TypeTableEntry *prev_type = prev_inst->value.type;
5877 if (cur_type->id == TypeTableEntryIdInvalid) {
5877 if (type_is_invalid(cur_type)) {
58785878 return cur_type;
58795879 } else if (prev_type->id == TypeTableEntryIdUnreachable) {
58805880 prev_inst = cur_inst;
......@@ -6317,7 +6317,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
63176317 analyzed_executable.backward_branch_quota = backward_branch_quota;
63186318 analyzed_executable.begin_scope = scope;
63196319 TypeTableEntry *result_type = ir_analyze(codegen, &ir_executable, &analyzed_executable, expected_type, node);
6320 if (result_type->id == TypeTableEntryIdInvalid)
6320 if (type_is_invalid(result_type))
63216321 return codegen->invalid_instruction;
63226322
63236323 if (codegen->verbose) {
......@@ -6330,7 +6330,7 @@ IrInstruction *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node
63306330}
63316331
63326332static TypeTableEntry *ir_resolve_type(IrAnalyze *ira, IrInstruction *type_value) {
6333 if (type_value->value.type->id == TypeTableEntryIdInvalid)
6333 if (type_is_invalid(type_value->value.type))
63346334 return ira->codegen->builtin_types.entry_invalid;
63356335
63366336 if (type_value->value.type->id != TypeTableEntryIdMetaType) {
......@@ -6350,7 +6350,7 @@ static FnTableEntry *ir_resolve_fn(IrAnalyze *ira, IrInstruction *fn_value) {
63506350 if (fn_value == ira->codegen->invalid_instruction)
63516351 return nullptr;
63526352
6353 if (fn_value->value.type->id == TypeTableEntryIdInvalid)
6353 if (type_is_invalid(fn_value->value.type))
63546354 return nullptr;
63556355
63566356 if (fn_value->value.type->id != TypeTableEntryIdFn) {
......@@ -6372,7 +6372,7 @@ static IrInstruction *ir_analyze_maybe_wrap(IrAnalyze *ira, IrInstruction *sourc
63726372 if (instr_is_comptime(value)) {
63736373 TypeTableEntry *payload_type = wanted_type->data.maybe.child_type;
63746374 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
6375 if (casted_payload->value.type->id == TypeTableEntryIdInvalid)
6375 if (type_is_invalid(casted_payload->value.type))
63766376 return ira->codegen->invalid_instruction;
63776377
63786378 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
......@@ -6430,7 +6430,7 @@ static IrInstruction *ir_analyze_err_wrap_payload(IrAnalyze *ira, IrInstruction
64306430 if (instr_is_comptime(value)) {
64316431 TypeTableEntry *payload_type = wanted_type->data.error.child_type;
64326432 IrInstruction *casted_payload = ir_implicit_cast(ira, value, payload_type);
6433 if (casted_payload->value.type->id == TypeTableEntryIdInvalid)
6433 if (type_is_invalid(casted_payload->value.type))
64346434 return ira->codegen->invalid_instruction;
64356435
64366436 ConstExprValue *val = ir_resolve_const(ira, casted_payload, UndefBad);
......@@ -6529,7 +6529,7 @@ static IrInstruction *ir_analyze_null_to_maybe(IrAnalyze *ira, IrInstruction *so
65296529static IrInstruction *ir_get_ref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *value,
65306530 bool is_const, bool is_volatile)
65316531{
6532 if (value->value.type->id == TypeTableEntryIdInvalid)
6532 if (type_is_invalid(value->value.type))
65336533 return ira->codegen->invalid_instruction;
65346534
65356535 if (value->id == IrInstructionIdLoadPtr) {
......@@ -6752,9 +6752,7 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
67526752 TypeTableEntry *isize_type = ira->codegen->builtin_types.entry_isize;
67536753 TypeTableEntry *usize_type = ira->codegen->builtin_types.entry_usize;
67546754
6755 if (wanted_type_canon->id == TypeTableEntryIdInvalid ||
6756 actual_type_canon->id == TypeTableEntryIdInvalid)
6757 {
6755 if (type_is_invalid(wanted_type_canon) || type_is_invalid(actual_type_canon)) {
67586756 return ira->codegen->invalid_instruction;
67596757 }
67606758
......@@ -7016,9 +7014,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
70167014static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, TypeTableEntry *expected_type) {
70177015 assert(value);
70187016 assert(value != ira->codegen->invalid_instruction);
7019 assert(!expected_type || expected_type->id != TypeTableEntryIdInvalid);
7017 assert(!expected_type || !type_is_invalid(expected_type));
70207018 assert(value->value.type);
7021 assert(value->value.type->id != TypeTableEntryIdInvalid);
7019 assert(!type_is_invalid(value->value.type));
70227020 if (expected_type == nullptr)
70237021 return value; // anything will do
70247022 if (expected_type == value->value.type)
......@@ -7046,7 +7044,7 @@ static IrInstruction *ir_implicit_cast(IrAnalyze *ira, IrInstruction *value, Typ
70467044
70477045static IrInstruction *ir_get_deref(IrAnalyze *ira, IrInstruction *source_instruction, IrInstruction *ptr) {
70487046 TypeTableEntry *type_entry = ptr->value.type;
7049 if (type_entry->id == TypeTableEntryIdInvalid) {
7047 if (type_is_invalid(type_entry)) {
70507048 return ira->codegen->invalid_instruction;
70517049 } else if (type_entry->id == TypeTableEntryIdPointer) {
70527050 TypeTableEntry *child_type = type_entry->data.pointer.child_type;
......@@ -7100,11 +7098,11 @@ static TypeTableEntry *ir_analyze_ref(IrAnalyze *ira, IrInstruction *source_inst
71007098}
71017099
71027100static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out) {
7103 if (value->value.type->id == TypeTableEntryIdInvalid)
7101 if (type_is_invalid(value->value.type))
71047102 return false;
71057103
71067104 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_usize);
7107 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
7105 if (type_is_invalid(casted_value->value.type))
71087106 return false;
71097107
71107108 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
......@@ -7116,11 +7114,11 @@ static bool ir_resolve_usize(IrAnalyze *ira, IrInstruction *value, uint64_t *out
71167114}
71177115
71187116static bool ir_resolve_bool(IrAnalyze *ira, IrInstruction *value, bool *out) {
7119 if (value->value.type->id == TypeTableEntryIdInvalid)
7117 if (type_is_invalid(value->value.type))
71207118 return false;
71217119
71227120 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_bool);
7123 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
7121 if (type_is_invalid(casted_value->value.type))
71247122 return false;
71257123
71267124 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
......@@ -7140,11 +7138,11 @@ static bool ir_resolve_comptime(IrAnalyze *ira, IrInstruction *value, bool *out)
71407138}
71417139
71427140static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, AtomicOrder *out) {
7143 if (value->value.type->id == TypeTableEntryIdInvalid)
7141 if (type_is_invalid(value->value.type))
71447142 return false;
71457143
71467144 IrInstruction *casted_value = ir_implicit_cast(ira, value, ira->codegen->builtin_types.entry_atomic_order_enum);
7147 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
7145 if (type_is_invalid(casted_value->value.type))
71487146 return false;
71497147
71507148 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
......@@ -7156,12 +7154,12 @@ static bool ir_resolve_atomic_order(IrAnalyze *ira, IrInstruction *value, Atomic
71567154}
71577155
71587156static Buf *ir_resolve_str(IrAnalyze *ira, IrInstruction *value) {
7159 if (value->value.type->id == TypeTableEntryIdInvalid)
7157 if (type_is_invalid(value->value.type))
71607158 return nullptr;
71617159
71627160 TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
71637161 IrInstruction *casted_value = ir_implicit_cast(ira, value, str_type);
7164 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
7162 if (type_is_invalid(casted_value->value.type))
71657163 return nullptr;
71667164
71677165 ConstExprValue *const_val = ir_resolve_const(ira, casted_value, UndefBad);
......@@ -7191,7 +7189,7 @@ static TypeTableEntry *ir_analyze_instruction_return(IrAnalyze *ira,
71917189 IrInstructionReturn *return_instruction)
71927190{
71937191 IrInstruction *value = return_instruction->value->other;
7194 if (value->value.type->id == TypeTableEntryIdInvalid)
7192 if (type_is_invalid(value->value.type))
71957193 return ir_unreach_error(ira);
71967194 ira->implicit_return_type_list.append(value);
71977195
......@@ -7211,11 +7209,11 @@ static TypeTableEntry *ir_analyze_instruction_const(IrAnalyze *ira, IrInstructio
72117209
72127210static TypeTableEntry *ir_analyze_bin_op_bool(IrAnalyze *ira, IrInstructionBinOp *bin_op_instruction) {
72137211 IrInstruction *op1 = bin_op_instruction->op1->other;
7214 if (op1->value.type->id == TypeTableEntryIdInvalid)
7212 if (type_is_invalid(op1->value.type))
72157213 return ira->codegen->builtin_types.entry_invalid;
72167214
72177215 IrInstruction *op2 = bin_op_instruction->op2->other;
7218 if (op2->value.type->id == TypeTableEntryIdInvalid)
7216 if (type_is_invalid(op2->value.type))
72197217 return ira->codegen->builtin_types.entry_invalid;
72207218
72217219 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
......@@ -7298,13 +7296,13 @@ static TypeTableEntry *ir_analyze_bin_op_cmp(IrAnalyze *ira, IrInstructionBinOp
72987296
72997297 IrInstruction *instructions[] = {op1, op2};
73007298 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, instructions, 2);
7301 if (resolved_type->id == TypeTableEntryIdInvalid)
7299 if (type_is_invalid(resolved_type))
73027300 return resolved_type;
73037301
73047302 AstNode *source_node = bin_op_instruction->base.source_node;
73057303 switch (resolved_type->id) {
73067304 case TypeTableEntryIdInvalid:
7307 return ira->codegen->builtin_types.entry_invalid;
7305 zig_unreachable(); // handled above
73087306
73097307 case TypeTableEntryIdNumLitFloat:
73107308 case TypeTableEntryIdNumLitInt:
......@@ -7532,7 +7530,7 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
75327530 IrInstruction *op2 = bin_op_instruction->op2->other;
75337531 IrInstruction *instructions[] = {op1, op2};
75347532 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, bin_op_instruction->base.source_node, instructions, 2);
7535 if (resolved_type->id == TypeTableEntryIdInvalid)
7533 if (type_is_invalid(resolved_type))
75367534 return resolved_type;
75377535 TypeTableEntry *canon_resolved_type = get_underlying_type(resolved_type);
75387536 IrBinOp op_id = bin_op_instruction->op_id;
......@@ -7602,12 +7600,12 @@ static TypeTableEntry *ir_analyze_bin_op_math(IrAnalyze *ira, IrInstructionBinOp
76027600static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *instruction) {
76037601 IrInstruction *op1 = instruction->op1->other;
76047602 TypeTableEntry *op1_canon_type = get_underlying_type(op1->value.type);
7605 if (op1_canon_type->id == TypeTableEntryIdInvalid)
7603 if (type_is_invalid(op1_canon_type))
76067604 return ira->codegen->builtin_types.entry_invalid;
76077605
76087606 IrInstruction *op2 = instruction->op2->other;
76097607 TypeTableEntry *op2_canon_type = get_underlying_type(op2->value.type);
7610 if (op2_canon_type->id == TypeTableEntryIdInvalid)
7608 if (type_is_invalid(op2_canon_type))
76117609 return ira->codegen->builtin_types.entry_invalid;
76127610
76137611 ConstExprValue *op1_val = ir_resolve_const(ira, op1, UndefBad);
......@@ -7741,11 +7739,11 @@ static TypeTableEntry *ir_analyze_array_cat(IrAnalyze *ira, IrInstructionBinOp *
77417739
77427740static TypeTableEntry *ir_analyze_array_mult(IrAnalyze *ira, IrInstructionBinOp *instruction) {
77437741 IrInstruction *op1 = instruction->op1->other;
7744 if (op1->value.type->id == TypeTableEntryIdInvalid)
7742 if (type_is_invalid(op1->value.type))
77457743 return ira->codegen->builtin_types.entry_invalid;
77467744
77477745 IrInstruction *op2 = instruction->op2->other;
7748 if (op2->value.type->id == TypeTableEntryIdInvalid)
7746 if (type_is_invalid(op2->value.type))
77497747 return ira->codegen->builtin_types.entry_invalid;
77507748
77517749 ConstExprValue *array_val = ir_resolve_const(ira, op1, UndefBad);
......@@ -7832,7 +7830,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
78327830 VariableTableEntry *var = decl_var_instruction->var;
78337831
78347832 IrInstruction *init_value = decl_var_instruction->init_value->other;
7835 if (init_value->value.type->id == TypeTableEntryIdInvalid) {
7833 if (type_is_invalid(init_value->value.type)) {
78367834 var->value.type = ira->codegen->builtin_types.entry_invalid;
78377835 return var->value.type;
78387836 }
......@@ -7849,7 +7847,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
78497847 var_type = decl_var_instruction->var_type->other;
78507848 TypeTableEntry *proposed_type = ir_resolve_type(ira, var_type);
78517849 explicit_type = validate_var_type(ira->codegen, var_type->source_node, proposed_type);
7852 if (explicit_type->id == TypeTableEntryIdInvalid) {
7850 if (type_is_invalid(explicit_type)) {
78537851 var->value.type = ira->codegen->builtin_types.entry_invalid;
78547852 return var->value.type;
78557853 }
......@@ -7859,12 +7857,15 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
78597857
78607858 IrInstruction *casted_init_value = ir_implicit_cast(ira, init_value, explicit_type);
78617859 TypeTableEntry *result_type = get_underlying_type(casted_init_value->value.type);
7860 if (type_is_invalid(result_type)) {
7861 result_type = ira->codegen->builtin_types.entry_invalid;
7862 }
7863
78627864 switch (result_type->id) {
78637865 case TypeTableEntryIdTypeDecl:
78647866 zig_unreachable();
78657867 case TypeTableEntryIdInvalid:
7866 result_type = ira->codegen->builtin_types.entry_invalid;
7867 break;
7868 break; // handled above
78687869 case TypeTableEntryIdNumLitFloat:
78697870 case TypeTableEntryIdNumLitInt:
78707871 if (is_export || is_extern || casted_init_value->value.special == ConstValSpecialRuntime) {
......@@ -7912,7 +7913,7 @@ static TypeTableEntry *ir_analyze_instruction_decl_var(IrAnalyze *ira, IrInstruc
79127913 var->value.type = result_type;
79137914 assert(var->value.type);
79147915
7915 if (result_type->id == TypeTableEntryIdInvalid) {
7916 if (type_is_invalid(result_type)) {
79167917 decl_var_instruction->base.other = &decl_var_instruction->base;
79177918 return ira->codegen->builtin_types.entry_void;
79187919 }
......@@ -7953,11 +7954,11 @@ static bool ir_analyze_fn_call_inline_arg(IrAnalyze *ira, AstNode *fn_proto_node
79537954 assert(param_decl_node->type == NodeTypeParamDecl);
79547955 AstNode *param_type_node = param_decl_node->data.param_decl.type;
79557956 TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *exec_scope, param_type_node);
7956 if (param_type->id == TypeTableEntryIdInvalid)
7957 if (type_is_invalid(param_type))
79577958 return false;
79587959
79597960 IrInstruction *casted_arg = ir_implicit_cast(ira, arg, param_type);
7960 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)
7961 if (type_is_invalid(casted_arg->value.type))
79617962 return false;
79627963
79637964 ConstExprValue *arg_val = ir_resolve_const(ira, casted_arg, UndefBad);
......@@ -7989,7 +7990,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
79897990 } else {
79907991 AstNode *param_type_node = param_decl_node->data.param_decl.type;
79917992 TypeTableEntry *param_type = analyze_type_expr(ira->codegen, *child_scope, param_type_node);
7992 if (param_type->id == TypeTableEntryIdInvalid)
7993 if (type_is_invalid(param_type))
79937994 return false;
79947995
79957996 bool is_var_type = (param_type->id == TypeTableEntryIdVar);
......@@ -7998,7 +7999,7 @@ static bool ir_analyze_fn_call_generic_arg(IrAnalyze *ira, AstNode *fn_proto_nod
79987999 casted_arg = arg;
79998000 } else {
80008001 casted_arg = ir_implicit_cast(ira, arg, param_type);
8001 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)
8002 if (type_is_invalid(casted_arg->value.type))
80028003 return false;
80038004 }
80048005 }
......@@ -8102,7 +8103,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
81028103 first_arg = first_arg_ptr;
81038104 } else {
81048105 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
8105 if (first_arg->value.type->id == TypeTableEntryIdInvalid)
8106 if (type_is_invalid(first_arg->value.type))
81068107 return ira->codegen->builtin_types.entry_invalid;
81078108 }
81088109
......@@ -8112,7 +8113,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
81128113
81138114 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
81148115 IrInstruction *old_arg = call_instruction->args[call_i]->other;
8115 if (old_arg->value.type->id == TypeTableEntryIdInvalid)
8116 if (type_is_invalid(old_arg->value.type))
81168117 return ira->codegen->builtin_types.entry_invalid;
81178118
81188119 if (!ir_analyze_fn_call_inline_arg(ira, fn_proto_node, old_arg, &exec_scope, &next_proto_i))
......@@ -8121,7 +8122,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
81218122
81228123 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
81238124 TypeTableEntry *return_type = analyze_type_expr(ira->codegen, exec_scope, return_type_node);
8124 if (return_type->id == TypeTableEntryIdInvalid)
8125 if (type_is_invalid(return_type))
81258126 return ira->codegen->builtin_types.entry_invalid;
81268127
81278128 IrInstruction *result;
......@@ -8135,7 +8136,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
81358136 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,
81368137 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,
81378138 nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec);
8138 if (result->value.type->id == TypeTableEntryIdInvalid)
8139 if (type_is_invalid(result->value.type))
81398140 return ira->codegen->builtin_types.entry_invalid;
81408141
81418142 ira->codegen->memoized_fn_eval_table.put(exec_scope, result);
......@@ -8178,7 +8179,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
81788179 first_arg = first_arg_ptr;
81798180 } else {
81808181 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
8181 if (first_arg->value.type->id == TypeTableEntryIdInvalid)
8182 if (type_is_invalid(first_arg->value.type))
81828183 return ira->codegen->builtin_types.entry_invalid;
81838184 }
81848185
......@@ -8193,7 +8194,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
81938194 size_t first_var_arg = inst_fn_type_id.param_count;
81948195 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
81958196 IrInstruction *arg = call_instruction->args[call_i]->other;
8196 if (arg->value.type->id == TypeTableEntryIdInvalid)
8197 if (type_is_invalid(arg->value.type))
81978198 return ira->codegen->builtin_types.entry_invalid;
81988199
81998200 AstNode *param_decl_node = fn_proto_node->data.fn_proto.params.at(next_proto_i);
......@@ -8224,7 +8225,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
82248225 {
82258226 AstNode *return_type_node = fn_proto_node->data.fn_proto.return_type;
82268227 TypeTableEntry *return_type = analyze_type_expr(ira->codegen, impl_fn->child_scope, return_type_node);
8227 if (return_type->id == TypeTableEntryIdInvalid)
8228 if (type_is_invalid(return_type))
82288229 return ira->codegen->builtin_types.entry_invalid;
82298230 inst_fn_type_id.return_type = return_type;
82308231
......@@ -8241,7 +8242,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
82418242 } else {
82428243 // finish instantiating the function
82438244 impl_fn->type_entry = get_fn_type(ira->codegen, &inst_fn_type_id);
8244 if (impl_fn->type_entry->id == TypeTableEntryIdInvalid)
8245 if (type_is_invalid(impl_fn->type_entry))
82458246 return ira->codegen->builtin_types.entry_invalid;
82468247
82478248 impl_fn->ir_executable.source_node = call_instruction->base.source_node;
......@@ -8272,16 +8273,16 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
82728273 first_arg = first_arg_ptr;
82738274 } else {
82748275 first_arg = ir_get_deref(ira, first_arg_ptr, first_arg_ptr);
8275 if (first_arg->value.type->id == TypeTableEntryIdInvalid)
8276 if (type_is_invalid(first_arg->value.type))
82768277 return ira->codegen->builtin_types.entry_invalid;
82778278 }
82788279
82798280 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
8280 if (param_type->id == TypeTableEntryIdInvalid)
8281 if (type_is_invalid(param_type))
82818282 return ira->codegen->builtin_types.entry_invalid;
82828283
82838284 IrInstruction *casted_arg = ir_implicit_cast(ira, first_arg, param_type);
8284 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)
8285 if (type_is_invalid(casted_arg->value.type))
82858286 return ira->codegen->builtin_types.entry_invalid;
82868287
82878288 casted_args[next_arg_index] = casted_arg;
......@@ -8289,15 +8290,15 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
82898290 }
82908291 for (size_t call_i = 0; call_i < call_instruction->arg_count; call_i += 1) {
82918292 IrInstruction *old_arg = call_instruction->args[call_i]->other;
8292 if (old_arg->value.type->id == TypeTableEntryIdInvalid)
8293 if (type_is_invalid(old_arg->value.type))
82938294 return ira->codegen->builtin_types.entry_invalid;
82948295 IrInstruction *casted_arg;
82958296 if (next_arg_index < src_param_count) {
82968297 TypeTableEntry *param_type = fn_type_id->param_info[next_arg_index].type;
8297 if (param_type->id == TypeTableEntryIdInvalid)
8298 if (type_is_invalid(param_type))
82988299 return ira->codegen->builtin_types.entry_invalid;
82998300 casted_arg = ir_implicit_cast(ira, old_arg, param_type);
8300 if (casted_arg->value.type->id == TypeTableEntryIdInvalid)
8301 if (type_is_invalid(casted_arg->value.type))
83018302 return ira->codegen->builtin_types.entry_invalid;
83028303 } else {
83038304 casted_arg = old_arg;
......@@ -8310,7 +8311,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
83108311 assert(next_arg_index == call_param_count);
83118312
83128313 TypeTableEntry *return_type = fn_type_id->return_type;
8313 if (return_type->id == TypeTableEntryIdInvalid)
8314 if (type_is_invalid(return_type))
83148315 return ira->codegen->builtin_types.entry_invalid;
83158316
83168317 IrInstruction *new_call_instruction = ir_build_call_from(&ira->new_irb, &call_instruction->base,
......@@ -8322,7 +8323,7 @@ static TypeTableEntry *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCall *cal
83228323
83238324static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstructionCall *call_instruction) {
83248325 IrInstruction *fn_ref = call_instruction->fn_ref->other;
8325 if (fn_ref->value.type->id == TypeTableEntryIdInvalid)
8326 if (type_is_invalid(fn_ref->value.type))
83268327 return ira->codegen->builtin_types.entry_invalid;
83278328
83288329 bool is_inline = call_instruction->is_comptime ||
......@@ -8331,7 +8332,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
83318332 if (is_inline || instr_is_comptime(fn_ref)) {
83328333 if (fn_ref->value.type->id == TypeTableEntryIdMetaType) {
83338334 TypeTableEntry *dest_type = ir_resolve_type(ira, fn_ref);
8334 if (dest_type->id == TypeTableEntryIdInvalid)
8335 if (type_is_invalid(dest_type))
83358336 return ira->codegen->builtin_types.entry_invalid;
83368337
83378338 size_t actual_param_count = call_instruction->arg_count;
......@@ -8345,7 +8346,7 @@ static TypeTableEntry *ir_analyze_instruction_call(IrAnalyze *ira, IrInstruction
83458346 IrInstruction *arg = call_instruction->args[0]->other;
83468347
83478348 IrInstruction *cast_instruction = ir_analyze_cast(ira, &call_instruction->base, dest_type, arg);
8348 if (cast_instruction->value.type->id == TypeTableEntryIdInvalid)
8349 if (type_is_invalid(cast_instruction->value.type))
83498350 return ira->codegen->builtin_types.entry_invalid;
83508351
83518352 ir_link_new_instruction(cast_instruction, &call_instruction->base);
......@@ -8383,11 +8384,16 @@ static TypeTableEntry *ir_analyze_unary_prefix_op_err(IrAnalyze *ira, IrInstruct
83838384
83848385 TypeTableEntry *meta_type = ir_resolve_type(ira, value);
83858386 TypeTableEntry *underlying_meta_type = get_underlying_type(meta_type);
8387
8388 if (type_is_invalid(underlying_meta_type))
8389 return ira->codegen->builtin_types.entry_invalid;
8390
8391
83868392 switch (underlying_meta_type->id) {
83878393 case TypeTableEntryIdTypeDecl:
8394 case TypeTableEntryIdInvalid: // handled above
83888395 zig_unreachable();
8389 case TypeTableEntryIdInvalid:
8390 return ira->codegen->builtin_types.entry_invalid;
8396
83918397 case TypeTableEntryIdVoid:
83928398 case TypeTableEntryIdBool:
83938399 case TypeTableEntryIdInt:
......@@ -8433,7 +8439,7 @@ static TypeTableEntry *ir_analyze_dereference(IrAnalyze *ira, IrInstructionUnOp
84338439
84348440 TypeTableEntry *ptr_type = value->value.type;
84358441 TypeTableEntry *child_type;
8436 if (ptr_type->id == TypeTableEntryIdInvalid) {
8442 if (type_is_invalid(ptr_type)) {
84378443 return ira->codegen->builtin_types.entry_invalid;
84388444 } else if (ptr_type->id == TypeTableEntryIdPointer) {
84398445 child_type = ptr_type->data.pointer.child_type;
......@@ -8509,7 +8515,7 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
85098515static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un_op_instruction) {
85108516 IrInstruction *value = un_op_instruction->value->other;
85118517 TypeTableEntry *expr_type = value->value.type;
8512 if (expr_type->id == TypeTableEntryIdInvalid)
8518 if (type_is_invalid(expr_type))
85138519 return ira->codegen->builtin_types.entry_invalid;
85148520
85158521 bool is_wrap_op = (un_op_instruction->op_id == IrUnOpNegationWrap);
......@@ -8555,7 +8561,7 @@ static TypeTableEntry *ir_analyze_negation(IrAnalyze *ira, IrInstructionUnOp *un
85558561static TypeTableEntry *ir_analyze_bin_not(IrAnalyze *ira, IrInstructionUnOp *instruction) {
85568562 IrInstruction *value = instruction->value->other;
85578563 TypeTableEntry *expr_type = value->value.type;
8558 if (expr_type->id == TypeTableEntryIdInvalid)
8564 if (type_is_invalid(expr_type))
85598565 return ira->codegen->builtin_types.entry_invalid;
85608566
85618567 if (expr_type->id == TypeTableEntryIdInt) {
......@@ -8616,7 +8622,7 @@ static TypeTableEntry *ir_analyze_instruction_br(IrAnalyze *ira, IrInstructionBr
86168622
86178623static TypeTableEntry *ir_analyze_instruction_cond_br(IrAnalyze *ira, IrInstructionCondBr *cond_br_instruction) {
86188624 IrInstruction *condition = cond_br_instruction->condition->other;
8619 if (condition->value.type->id == TypeTableEntryIdInvalid)
8625 if (type_is_invalid(condition->value.type))
86208626 return ir_unreach_error(ira);
86218627
86228628 bool is_comptime;
......@@ -8667,7 +8673,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
86678673 continue;
86688674 IrInstruction *value = phi_instruction->incoming_values[i]->other;
86698675 assert(value->value.type);
8670 if (value->value.type->id == TypeTableEntryIdInvalid)
8676 if (type_is_invalid(value->value.type))
86718677 return ira->codegen->builtin_types.entry_invalid;
86728678
86738679 if (value->value.special != ConstValSpecialRuntime) {
......@@ -8696,7 +8702,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
86968702 if (!new_value || new_value->value.type->id == TypeTableEntryIdUnreachable)
86978703 continue;
86988704
8699 if (new_value->value.type->id == TypeTableEntryIdInvalid)
8705 if (type_is_invalid(new_value->value.type))
87008706 return ira->codegen->builtin_types.entry_invalid;
87018707
87028708
......@@ -8718,7 +8724,7 @@ static TypeTableEntry *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionP
87188724
87198725 TypeTableEntry *resolved_type = ir_resolve_peer_types(ira, phi_instruction->base.source_node,
87208726 new_incoming_values.items, new_incoming_values.length);
8721 if (resolved_type->id == TypeTableEntryIdInvalid)
8727 if (type_is_invalid(resolved_type))
87228728 return resolved_type;
87238729
87248730 if (resolved_type->id == TypeTableEntryIdNumLitFloat ||
......@@ -8756,7 +8762,7 @@ static TypeTableEntry *ir_analyze_var_ptr(IrAnalyze *ira, IrInstruction *instruc
87568762 VariableTableEntry *var, bool is_const_ptr, bool is_volatile_ptr)
87578763{
87588764 assert(var->value.type);
8759 if (var->value.type->id == TypeTableEntryIdInvalid)
8765 if (type_is_invalid(var->value.type))
87608766 return var->value.type;
87618767
87628768 bool comptime_var_mem = ir_get_var_is_comptime(var);
......@@ -8816,11 +8822,11 @@ static VariableTableEntry *get_fn_var_by_index(FnTableEntry *fn_entry, size_t in
88168822
88178823static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstructionElemPtr *elem_ptr_instruction) {
88188824 IrInstruction *array_ptr = elem_ptr_instruction->array_ptr->other;
8819 if (array_ptr->value.type->id == TypeTableEntryIdInvalid)
8825 if (type_is_invalid(array_ptr->value.type))
88208826 return ira->codegen->builtin_types.entry_invalid;
88218827
88228828 IrInstruction *elem_index = elem_ptr_instruction->elem_index->other;
8823 if (elem_index->value.type->id == TypeTableEntryIdInvalid)
8829 if (type_is_invalid(elem_index->value.type))
88248830 return ira->codegen->builtin_types.entry_invalid;
88258831
88268832 // This will be a pointer type because elem ptr IR instruction operates on a pointer to a thing.
......@@ -8830,7 +8836,7 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
88308836 TypeTableEntry *array_type = ptr_type->data.pointer.child_type;
88318837 TypeTableEntry *return_type;
88328838
8833 if (array_type->id == TypeTableEntryIdInvalid) {
8839 if (type_is_invalid(array_type)) {
88348840 return array_type;
88358841 } else if (array_type->id == TypeTableEntryIdArray) {
88368842 if (array_type->data.array.len == 0) {
......@@ -9019,7 +9025,7 @@ static TypeTableEntry *ir_analyze_container_member_access_inner(IrAnalyze *ira,
90199025 return ira->codegen->builtin_types.entry_invalid;
90209026 TldFn *tld_fn = (TldFn *)tld;
90219027 FnTableEntry *fn_entry = tld_fn->fn_entry;
9022 if (fn_entry->type_entry->id == TypeTableEntryIdInvalid)
9028 if (type_is_invalid(fn_entry->type_entry))
90239029 return ira->codegen->builtin_types.entry_invalid;
90249030
90259031 IrInstruction *bound_fn_value = ir_build_const_bound_fn(&ira->new_irb, field_ptr_instruction->base.scope,
......@@ -9113,7 +9119,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
91139119 FnTableEntry *fn_entry = tld_fn->fn_entry;
91149120 assert(fn_entry->type_entry);
91159121
9116 if (fn_entry->type_entry->id == TypeTableEntryIdInvalid)
9122 if (type_is_invalid(fn_entry->type_entry))
91179123 return ira->codegen->builtin_types.entry_invalid;
91189124
91199125 // TODO instead of allocating this every time, put it in the tld value and we can reference
......@@ -9151,7 +9157,7 @@ static TypeTableEntry *ir_analyze_decl_ref(IrAnalyze *ira, IrInstruction *source
91519157
91529158static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstructionFieldPtr *field_ptr_instruction) {
91539159 IrInstruction *container_ptr = field_ptr_instruction->container_ptr->other;
9154 if (container_ptr->value.type->id == TypeTableEntryIdInvalid)
9160 if (type_is_invalid(container_ptr->value.type))
91559161 return ira->codegen->builtin_types.entry_invalid;
91569162
91579163 TypeTableEntry *container_type;
......@@ -9166,7 +9172,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
91669172 Buf *field_name = field_ptr_instruction->field_name;
91679173 AstNode *source_node = field_ptr_instruction->base.source_node;
91689174
9169 if (container_type->id == TypeTableEntryIdInvalid) {
9175 if (type_is_invalid(container_type)) {
91709176 return container_type;
91719177 } else if (is_container_ref(container_type)) {
91729178 assert(container_ptr->value.type->id == TypeTableEntryIdPointer);
......@@ -9234,7 +9240,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
92349240 zig_unreachable();
92359241 }
92369242
9237 if (child_type->id == TypeTableEntryIdInvalid) {
9243 if (type_is_invalid(child_type)) {
92389244 return ira->codegen->builtin_types.entry_invalid;
92399245 } else if (is_container(child_type)) {
92409246 if (child_type->id == TypeTableEntryIdEnum) {
......@@ -9371,11 +9377,11 @@ static TypeTableEntry *ir_analyze_instruction_load_ptr(IrAnalyze *ira, IrInstruc
93719377
93729378static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstructionStorePtr *store_ptr_instruction) {
93739379 IrInstruction *ptr = store_ptr_instruction->ptr->other;
9374 if (ptr->value.type->id == TypeTableEntryIdInvalid)
9380 if (type_is_invalid(ptr->value.type))
93759381 return ptr->value.type;
93769382
93779383 IrInstruction *value = store_ptr_instruction->value->other;
9378 if (value->value.type->id == TypeTableEntryIdInvalid)
9384 if (type_is_invalid(value->value.type))
93799385 return value->value.type;
93809386
93819387 assert(ptr->value.type->id == TypeTableEntryIdPointer);
......@@ -9412,9 +9418,11 @@ static TypeTableEntry *ir_analyze_instruction_store_ptr(IrAnalyze *ira, IrInstru
94129418static TypeTableEntry *ir_analyze_instruction_typeof(IrAnalyze *ira, IrInstructionTypeOf *typeof_instruction) {
94139419 IrInstruction *expr_value = typeof_instruction->value->other;
94149420 TypeTableEntry *type_entry = expr_value->value.type;
9421 if (type_is_invalid(type_entry))
9422 return ira->codegen->builtin_types.entry_invalid;
94159423 switch (type_entry->id) {
94169424 case TypeTableEntryIdInvalid:
9417 return type_entry;
9425 zig_unreachable(); // handled above
94189426 case TypeTableEntryIdVar:
94199427 ir_add_error_node(ira, expr_value->source_node,
94209428 buf_sprintf("type '%s' not eligible for @typeOf", buf_ptr(&type_entry->name)));
......@@ -9460,7 +9468,7 @@ static TypeTableEntry *ir_analyze_instruction_to_ptr_type(IrAnalyze *ira,
94609468{
94619469 IrInstruction *value = to_ptr_type_instruction->value->other;
94629470 TypeTableEntry *type_entry = value->value.type;
9463 if (type_entry->id == TypeTableEntryIdInvalid)
9471 if (type_is_invalid(type_entry))
94649472 return type_entry;
94659473
94669474 TypeTableEntry *ptr_type;
......@@ -9489,7 +9497,7 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type_child(IrAnalyze *ira,
94899497{
94909498 IrInstruction *type_value = ptr_type_child_instruction->value->other;
94919499 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
9492 if (type_entry->id == TypeTableEntryIdInvalid)
9500 if (type_is_invalid(type_entry))
94939501 return type_entry;
94949502
94959503 // TODO handle typedefs
......@@ -9651,7 +9659,7 @@ static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
96519659{
96529660 IrInstruction *target_instruction = set_debug_safety_instruction->scope_value->other;
96539661 TypeTableEntry *target_type = target_instruction->value.type;
9654 if (target_type->id == TypeTableEntryIdInvalid)
9662 if (type_is_invalid(target_type))
96559663 return ira->codegen->builtin_types.entry_invalid;
96569664 ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);
96579665 if (!target_val)
......@@ -9719,17 +9727,19 @@ static TypeTableEntry *ir_analyze_instruction_slice_type(IrAnalyze *ira,
97199727 IrInstructionSliceType *slice_type_instruction)
97209728{
97219729 IrInstruction *child_type = slice_type_instruction->child_type->other;
9722 if (child_type->value.type->id == TypeTableEntryIdInvalid)
9730 if (type_is_invalid(child_type->value.type))
97239731 return ira->codegen->builtin_types.entry_invalid;
97249732 bool is_const = slice_type_instruction->is_const;
97259733
97269734 TypeTableEntry *resolved_child_type = ir_resolve_type(ira, child_type);
97279735 TypeTableEntry *canon_child_type = get_underlying_type(resolved_child_type);
9736 if (type_is_invalid(canon_child_type))
9737 return ira->codegen->builtin_types.entry_invalid;
9738
97289739 switch (canon_child_type->id) {
97299740 case TypeTableEntryIdTypeDecl:
9741 case TypeTableEntryIdInvalid: // handled above
97309742 zig_unreachable();
9731 case TypeTableEntryIdInvalid:
9732 return ira->codegen->builtin_types.entry_invalid;
97339743 case TypeTableEntryIdVar:
97349744 case TypeTableEntryIdUnreachable:
97359745 case TypeTableEntryIdUndefLit:
......@@ -9789,14 +9799,14 @@ static TypeTableEntry *ir_analyze_instruction_asm(IrAnalyze *ira, IrInstructionA
97899799 if (asm_output->return_type) {
97909800 output_types[i] = asm_instruction->output_types[i]->other;
97919801 return_type = ir_resolve_type(ira, output_types[i]);
9792 if (return_type->id == TypeTableEntryIdInvalid)
9802 if (type_is_invalid(return_type))
97939803 return ira->codegen->builtin_types.entry_invalid;
97949804 }
97959805 }
97969806
97979807 for (size_t i = 0; i < asm_expr->input_list.length; i += 1) {
97989808 input_list[i] = asm_instruction->input_list[i]->other;
9799 if (input_list[i]->value.type->id == TypeTableEntryIdInvalid)
9809 if (type_is_invalid(input_list[i]->value.type))
98009810 return ira->codegen->builtin_types.entry_invalid;
98019811 }
98029812
......@@ -9816,11 +9826,12 @@ static TypeTableEntry *ir_analyze_instruction_array_type(IrAnalyze *ira,
98169826 IrInstruction *child_type_value = array_type_instruction->child_type->other;
98179827 TypeTableEntry *child_type = ir_resolve_type(ira, child_type_value);
98189828 TypeTableEntry *canon_child_type = get_underlying_type(child_type);
9829 if (type_is_invalid(canon_child_type))
9830 return ira->codegen->builtin_types.entry_invalid;
98199831 switch (canon_child_type->id) {
98209832 case TypeTableEntryIdTypeDecl:
9833 case TypeTableEntryIdInvalid: // handled above
98219834 zig_unreachable();
9822 case TypeTableEntryIdInvalid:
9823 return ira->codegen->builtin_types.entry_invalid;
98249835 case TypeTableEntryIdVar:
98259836 case TypeTableEntryIdUnreachable:
98269837 case TypeTableEntryIdUndefLit:
......@@ -9906,10 +9917,11 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
99069917 TypeTableEntry *canon_type_entry = get_underlying_type(type_entry);
99079918
99089919 ensure_complete_type(ira->codegen, type_entry);
9920 if (type_is_invalid(canon_type_entry))
9921 return ira->codegen->builtin_types.entry_invalid;
99099922
99109923 switch (canon_type_entry->id) {
9911 case TypeTableEntryIdInvalid:
9912 return ira->codegen->builtin_types.entry_invalid;
9924 case TypeTableEntryIdInvalid: // handled above
99139925 case TypeTableEntryIdTypeDecl:
99149926 zig_unreachable();
99159927 case TypeTableEntryIdVar:
......@@ -9953,7 +9965,7 @@ static TypeTableEntry *ir_analyze_instruction_size_of(IrAnalyze *ira,
99539965
99549966static TypeTableEntry *ir_analyze_instruction_test_non_null(IrAnalyze *ira, IrInstructionTestNonNull *instruction) {
99559967 IrInstruction *value = instruction->value->other;
9956 if (value->value.type->id == TypeTableEntryIdInvalid)
9968 if (type_is_invalid(value->value.type))
99579969 return ira->codegen->builtin_types.entry_invalid;
99589970
99599971 TypeTableEntry *type_entry = value->value.type;
......@@ -9986,7 +9998,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
99869998 IrInstructionUnwrapMaybe *unwrap_maybe_instruction)
99879999{
998810000 IrInstruction *value = unwrap_maybe_instruction->value->other;
9989 if (value->value.type->id == TypeTableEntryIdInvalid)
10001 if (type_is_invalid(value->value.type))
999010002 return ira->codegen->builtin_types.entry_invalid;
999110003
999210004 TypeTableEntry *ptr_type = value->value.type;
......@@ -10010,7 +10022,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1001010022
1001110023 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
1001210024 // TODO handle typedef
10013 if (type_entry->id == TypeTableEntryIdInvalid) {
10025 if (type_is_invalid(type_entry)) {
1001410026 return ira->codegen->builtin_types.entry_invalid;
1001510027 } else if (type_entry->id != TypeTableEntryIdMaybe) {
1001610028 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
......@@ -10047,7 +10059,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
1004710059
1004810060static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionCtz *ctz_instruction) {
1004910061 IrInstruction *value = ctz_instruction->value->other;
10050 if (value->value.type->id == TypeTableEntryIdInvalid) {
10062 if (type_is_invalid(value->value.type)) {
1005110063 return ira->codegen->builtin_types.entry_invalid;
1005210064 } else if (value->value.type->id == TypeTableEntryIdInt) {
1005310065 if (value->value.special != ConstValSpecialRuntime) {
......@@ -10069,7 +10081,7 @@ static TypeTableEntry *ir_analyze_instruction_ctz(IrAnalyze *ira, IrInstructionC
1006910081
1007010082static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionClz *clz_instruction) {
1007110083 IrInstruction *value = clz_instruction->value->other;
10072 if (value->value.type->id == TypeTableEntryIdInvalid) {
10084 if (type_is_invalid(value->value.type)) {
1007310085 return ira->codegen->builtin_types.entry_invalid;
1007410086 } else if (value->value.type->id == TypeTableEntryIdInt) {
1007510087 if (value->value.special != ConstValSpecialRuntime) {
......@@ -10090,7 +10102,7 @@ static TypeTableEntry *ir_analyze_instruction_clz(IrAnalyze *ira, IrInstructionC
1009010102}
1009110103
1009210104static IrInstruction *ir_analyze_enum_tag(IrAnalyze *ira, IrInstruction *source_instr, IrInstruction *value) {
10093 if (value->value.type->id == TypeTableEntryIdInvalid)
10105 if (type_is_invalid(value->value.type))
1009410106 return ira->codegen->invalid_instruction;
1009510107
1009610108 if (value->value.type->id != TypeTableEntryIdEnum) {
......@@ -10119,7 +10131,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1011910131 IrInstructionSwitchBr *switch_br_instruction)
1012010132{
1012110133 IrInstruction *target_value = switch_br_instruction->target_value->other;
10122 if (target_value->value.type->id == TypeTableEntryIdInvalid)
10134 if (type_is_invalid(target_value->value.type))
1012310135 return ir_unreach_error(ira);
1012410136
1012510137 size_t case_count = switch_br_instruction->case_count;
......@@ -10137,17 +10149,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1013710149 for (size_t i = 0; i < case_count; i += 1) {
1013810150 IrInstructionSwitchBrCase *old_case = &switch_br_instruction->cases[i];
1013910151 IrInstruction *case_value = old_case->value->other;
10140 if (case_value->value.type->id == TypeTableEntryIdInvalid)
10152 if (type_is_invalid(case_value->value.type))
1014110153 return ir_unreach_error(ira);
1014210154
1014310155 if (case_value->value.type->id == TypeTableEntryIdEnum) {
1014410156 case_value = ir_analyze_enum_tag(ira, &switch_br_instruction->base, case_value);
10145 if (case_value->value.type->id == TypeTableEntryIdInvalid)
10157 if (type_is_invalid(case_value->value.type))
1014610158 return ir_unreach_error(ira);
1014710159 }
1014810160
1014910161 IrInstruction *casted_case_value = ir_implicit_cast(ira, case_value, target_value->value.type);
10150 if (casted_case_value->value.type->id == TypeTableEntryIdInvalid)
10162 if (type_is_invalid(casted_case_value->value.type))
1015110163 return ir_unreach_error(ira);
1015210164
1015310165 ConstExprValue *case_val = ir_resolve_const(ira, casted_case_value, UndefBad);
......@@ -10184,17 +10196,17 @@ static TypeTableEntry *ir_analyze_instruction_switch_br(IrAnalyze *ira,
1018410196
1018510197 IrInstruction *old_value = old_case->value;
1018610198 IrInstruction *new_value = old_value->other;
10187 if (new_value->value.type->id == TypeTableEntryIdInvalid)
10199 if (type_is_invalid(new_value->value.type))
1018810200 continue;
1018910201
1019010202 if (new_value->value.type->id == TypeTableEntryIdEnum) {
1019110203 new_value = ir_analyze_enum_tag(ira, &switch_br_instruction->base, new_value);
10192 if (new_value->value.type->id == TypeTableEntryIdInvalid)
10204 if (type_is_invalid(new_value->value.type))
1019310205 continue;
1019410206 }
1019510207
1019610208 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, target_value->value.type);
10197 if (casted_new_value->value.type->id == TypeTableEntryIdInvalid)
10209 if (type_is_invalid(casted_new_value->value.type))
1019810210 continue;
1019910211
1020010212 if (!ir_resolve_const(ira, casted_new_value, UndefBad))
......@@ -10218,7 +10230,7 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1021810230 IrInstructionSwitchTarget *switch_target_instruction)
1021910231{
1022010232 IrInstruction *target_value_ptr = switch_target_instruction->target_value_ptr->other;
10221 if (target_value_ptr->value.type->id == TypeTableEntryIdInvalid)
10233 if (type_is_invalid(target_value_ptr->value.type))
1022210234 return ira->codegen->builtin_types.entry_invalid;
1022310235
1022410236 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
......@@ -10231,6 +10243,8 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1023110243 }
1023210244 TypeTableEntry *canon_target_type = get_underlying_type(target_type);
1023310245 ensure_complete_type(ira->codegen, target_type);
10246 if (type_is_invalid(canon_target_type))
10247 return ira->codegen->builtin_types.entry_invalid;
1023410248
1023510249 switch (canon_target_type->id) {
1023610250 case TypeTableEntryIdInvalid:
......@@ -10297,11 +10311,11 @@ static TypeTableEntry *ir_analyze_instruction_switch_target(IrAnalyze *ira,
1029710311
1029810312static TypeTableEntry *ir_analyze_instruction_switch_var(IrAnalyze *ira, IrInstructionSwitchVar *instruction) {
1029910313 IrInstruction *target_value_ptr = instruction->target_value_ptr->other;
10300 if (target_value_ptr->value.type->id == TypeTableEntryIdInvalid)
10314 if (type_is_invalid(target_value_ptr->value.type))
1030110315 return ira->codegen->builtin_types.entry_invalid;
1030210316
1030310317 IrInstruction *prong_value = instruction->prong_value->other;
10304 if (prong_value->value.type->id == TypeTableEntryIdInvalid)
10318 if (type_is_invalid(prong_value->value.type))
1030510319 return ira->codegen->builtin_types.entry_invalid;
1030610320
1030710321 assert(target_value_ptr->value.type->id == TypeTableEntryIdPointer);
......@@ -10357,7 +10371,7 @@ static TypeTableEntry *ir_analyze_instruction_enum_tag(IrAnalyze *ira, IrInstruc
1035710371
1035810372static TypeTableEntry *ir_analyze_instruction_generated_code(IrAnalyze *ira, IrInstructionGeneratedCode *instruction) {
1035910373 IrInstruction *value = instruction->value->other;
10360 if (value->value.type->id == TypeTableEntryIdInvalid)
10374 if (type_is_invalid(value->value.type))
1036110375 return ira->codegen->builtin_types.entry_invalid;
1036210376
1036310377 if (instr_is_comptime(value)) {
......@@ -10452,7 +10466,7 @@ static TypeTableEntry *ir_analyze_instruction_array_len(IrAnalyze *ira,
1045210466{
1045310467 IrInstruction *array_value = array_len_instruction->array_value->other;
1045410468 TypeTableEntry *canon_type = get_underlying_type(array_value->value.type);
10455 if (canon_type->id == TypeTableEntryIdInvalid) {
10469 if (type_is_invalid(canon_type)) {
1045610470 return ira->codegen->builtin_types.entry_invalid;
1045710471 } else if (canon_type->id == TypeTableEntryIdArray) {
1045810472 return ir_analyze_const_usize(ira, &array_len_instruction->base,
......@@ -10515,7 +10529,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
1051510529 IrInstructionContainerInitFieldsField *field = &fields[i];
1051610530
1051710531 IrInstruction *field_value = field->value->other;
10518 if (field_value->value.type->id == TypeTableEntryIdInvalid)
10532 if (type_is_invalid(field_value->value.type))
1051910533 return ira->codegen->builtin_types.entry_invalid;
1052010534
1052110535 TypeStructField *type_field = find_struct_type_field(container_type, field->name);
......@@ -10526,7 +10540,7 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
1052610540 return ira->codegen->builtin_types.entry_invalid;
1052710541 }
1052810542
10529 if (type_field->type_entry->id == TypeTableEntryIdInvalid)
10543 if (type_is_invalid(type_field->type_entry))
1053010544 return ira->codegen->builtin_types.entry_invalid;
1053110545
1053210546 IrInstruction *casted_field_value = ir_implicit_cast(ira, field_value, type_field->type_entry);
......@@ -10593,13 +10607,13 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
1059310607 IrInstructionContainerInitList *instruction)
1059410608{
1059510609 IrInstruction *container_type_value = instruction->container_type->other;
10596 if (container_type_value->value.type->id == TypeTableEntryIdInvalid)
10610 if (type_is_invalid(container_type_value->value.type))
1059710611 return ira->codegen->builtin_types.entry_invalid;
1059810612
1059910613 size_t elem_count = instruction->item_count;
1060010614 if (container_type_value->value.type->id == TypeTableEntryIdMetaType) {
1060110615 TypeTableEntry *container_type = ir_resolve_type(ira, container_type_value);
10602 if (container_type->id == TypeTableEntryIdInvalid)
10616 if (type_is_invalid(container_type))
1060310617 return ira->codegen->builtin_types.entry_invalid;
1060410618
1060510619 if (container_type->id == TypeTableEntryIdStruct && !is_slice(container_type) && elem_count == 0) {
......@@ -10624,7 +10638,7 @@ static TypeTableEntry *ir_analyze_instruction_container_init_list(IrAnalyze *ira
1062410638
1062510639 for (size_t i = 0; i < elem_count; i += 1) {
1062610640 IrInstruction *arg_value = instruction->items[i]->other;
10627 if (arg_value->value.type->id == TypeTableEntryIdInvalid)
10641 if (type_is_invalid(arg_value->value.type))
1062810642 return ira->codegen->builtin_types.entry_invalid;
1062910643
1063010644 IrInstruction *casted_arg = ir_implicit_cast(ira, arg_value, child_type);
......@@ -10744,9 +10758,11 @@ static TypeTableEntry *ir_analyze_min_max(IrAnalyze *ira, IrInstruction *source_
1074410758{
1074510759 TypeTableEntry *target_type = ir_resolve_type(ira, target_type_value);
1074610760 TypeTableEntry *canon_type = get_underlying_type(target_type);
10761 if (type_is_invalid(canon_type))
10762 return ira->codegen->builtin_types.entry_invalid;
1074710763 switch (canon_type->id) {
1074810764 case TypeTableEntryIdInvalid:
10749 return ira->codegen->builtin_types.entry_invalid;
10765 zig_unreachable();
1075010766 case TypeTableEntryIdInt:
1075110767 {
1075210768 ConstExprValue *out_val = ir_build_const_from(ira, source_instruction);
......@@ -10831,7 +10847,7 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst
1083110847 fprintf(stderr, "| ");
1083210848 for (size_t i = 0; i < instruction->msg_count; i += 1) {
1083310849 IrInstruction *msg = instruction->msg_list[i]->other;
10834 if (msg->value.type->id == TypeTableEntryIdInvalid)
10850 if (type_is_invalid(msg->value.type))
1083510851 return ira->codegen->builtin_types.entry_invalid;
1083610852 buf_resize(&buf, 0);
1083710853 render_const_value(&buf, &msg->value);
......@@ -10848,11 +10864,11 @@ static TypeTableEntry *ir_analyze_instruction_compile_log(IrAnalyze *ira, IrInst
1084810864
1084910865static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstructionErrName *instruction) {
1085010866 IrInstruction *value = instruction->value->other;
10851 if (value->value.type->id == TypeTableEntryIdInvalid)
10867 if (type_is_invalid(value->value.type))
1085210868 return ira->codegen->builtin_types.entry_invalid;
1085310869
1085410870 IrInstruction *casted_value = ir_implicit_cast(ira, value, value->value.type);
10855 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
10871 if (type_is_invalid(casted_value->value.type))
1085610872 return ira->codegen->builtin_types.entry_invalid;
1085710873
1085810874 TypeTableEntry *str_type = get_slice_type(ira->codegen, ira->codegen->builtin_types.entry_u8, true);
......@@ -10875,7 +10891,7 @@ static TypeTableEntry *ir_analyze_instruction_err_name(IrAnalyze *ira, IrInstruc
1087510891static TypeTableEntry *ir_analyze_instruction_type_name(IrAnalyze *ira, IrInstructionTypeName *instruction) {
1087610892 IrInstruction *type_value = instruction->type_value->other;
1087710893 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
10878 if (type_entry->id == TypeTableEntryIdInvalid)
10894 if (type_is_invalid(type_entry))
1087910895 return ira->codegen->builtin_types.entry_invalid;
1088010896
1088110897 if (!type_entry->cached_const_name_val) {
......@@ -10898,7 +10914,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
1089810914 IrInstruction *result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,
1089910915 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
1090010916 &cimport_scope->buf, block_node, nullptr, nullptr);
10901 if (result->value.type->id == TypeTableEntryIdInvalid)
10917 if (type_is_invalid(result->value.type))
1090210918 return ira->codegen->builtin_types.entry_invalid;
1090310919
1090410920 find_libc_include_path(ira->codegen);
......@@ -10937,7 +10953,7 @@ static TypeTableEntry *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruc
1093710953
1093810954static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstructionCInclude *instruction) {
1093910955 IrInstruction *name_value = instruction->name->other;
10940 if (name_value->value.type->id == TypeTableEntryIdInvalid)
10956 if (type_is_invalid(name_value->value.type))
1094110957 return ira->codegen->builtin_types.entry_invalid;
1094210958
1094310959 Buf *include_name = ir_resolve_str(ira, name_value);
......@@ -10956,7 +10972,7 @@ static TypeTableEntry *ir_analyze_instruction_c_include(IrAnalyze *ira, IrInstru
1095610972
1095710973static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstructionCDefine *instruction) {
1095810974 IrInstruction *name = instruction->name->other;
10959 if (name->value.type->id == TypeTableEntryIdInvalid)
10975 if (type_is_invalid(name->value.type))
1096010976 return ira->codegen->builtin_types.entry_invalid;
1096110977
1096210978 Buf *define_name = ir_resolve_str(ira, name);
......@@ -10964,7 +10980,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc
1096410980 return ira->codegen->builtin_types.entry_invalid;
1096510981
1096610982 IrInstruction *value = instruction->value->other;
10967 if (value->value.type->id == TypeTableEntryIdInvalid)
10983 if (type_is_invalid(value->value.type))
1096810984 return ira->codegen->builtin_types.entry_invalid;
1096910985
1097010986 Buf *define_value = ir_resolve_str(ira, value);
......@@ -10983,7 +10999,7 @@ static TypeTableEntry *ir_analyze_instruction_c_define(IrAnalyze *ira, IrInstruc
1098310999
1098411000static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstructionCUndef *instruction) {
1098511001 IrInstruction *name = instruction->name->other;
10986 if (name->value.type->id == TypeTableEntryIdInvalid)
11002 if (type_is_invalid(name->value.type))
1098711003 return ira->codegen->builtin_types.entry_invalid;
1098811004
1098911005 Buf *undef_name = ir_resolve_str(ira, name);
......@@ -11002,7 +11018,7 @@ static TypeTableEntry *ir_analyze_instruction_c_undef(IrAnalyze *ira, IrInstruct
1100211018
1100311019static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstructionEmbedFile *instruction) {
1100411020 IrInstruction *name = instruction->name->other;
11005 if (name->value.type->id == TypeTableEntryIdInvalid)
11021 if (type_is_invalid(name->value.type))
1100611022 return ira->codegen->builtin_types.entry_invalid;
1100711023
1100811024 Buf *rel_file_path = ir_resolve_str(ira, name);
......@@ -11041,19 +11057,19 @@ static TypeTableEntry *ir_analyze_instruction_embed_file(IrAnalyze *ira, IrInstr
1104111057
1104211058static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstructionCmpxchg *instruction) {
1104311059 IrInstruction *ptr = instruction->ptr->other;
11044 if (ptr->value.type->id == TypeTableEntryIdInvalid)
11060 if (type_is_invalid(ptr->value.type))
1104511061 return ira->codegen->builtin_types.entry_invalid;
1104611062
1104711063 IrInstruction *cmp_value = instruction->cmp_value->other;
11048 if (cmp_value->value.type->id == TypeTableEntryIdInvalid)
11064 if (type_is_invalid(cmp_value->value.type))
1104911065 return ira->codegen->builtin_types.entry_invalid;
1105011066
1105111067 IrInstruction *new_value = instruction->new_value->other;
11052 if (new_value->value.type->id == TypeTableEntryIdInvalid)
11068 if (type_is_invalid(new_value->value.type))
1105311069 return ira->codegen->builtin_types.entry_invalid;
1105411070
1105511071 IrInstruction *success_order_value = instruction->success_order_value->other;
11056 if (success_order_value->value.type->id == TypeTableEntryIdInvalid)
11072 if (type_is_invalid(success_order_value->value.type))
1105711073 return ira->codegen->builtin_types.entry_invalid;
1105811074
1105911075 AtomicOrder success_order;
......@@ -11061,7 +11077,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
1106111077 return ira->codegen->builtin_types.entry_invalid;
1106211078
1106311079 IrInstruction *failure_order_value = instruction->failure_order_value->other;
11064 if (failure_order_value->value.type->id == TypeTableEntryIdInvalid)
11080 if (type_is_invalid(failure_order_value->value.type))
1106511081 return ira->codegen->builtin_types.entry_invalid;
1106611082
1106711083 AtomicOrder failure_order;
......@@ -11077,11 +11093,11 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
1107711093 TypeTableEntry *child_type = ptr->value.type->data.pointer.child_type;
1107811094
1107911095 IrInstruction *casted_cmp_value = ir_implicit_cast(ira, cmp_value, child_type);
11080 if (casted_cmp_value->value.type->id == TypeTableEntryIdInvalid)
11096 if (type_is_invalid(casted_cmp_value->value.type))
1108111097 return ira->codegen->builtin_types.entry_invalid;
1108211098
1108311099 IrInstruction *casted_new_value = ir_implicit_cast(ira, new_value, child_type);
11084 if (casted_new_value->value.type->id == TypeTableEntryIdInvalid)
11100 if (type_is_invalid(casted_new_value->value.type))
1108511101 return ira->codegen->builtin_types.entry_invalid;
1108611102
1108711103 if (success_order < AtomicOrderMonotonic) {
......@@ -11112,7 +11128,7 @@ static TypeTableEntry *ir_analyze_instruction_cmpxchg(IrAnalyze *ira, IrInstruct
1111211128
1111311129static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructionFence *instruction) {
1111411130 IrInstruction *order_value = instruction->order_value->other;
11115 if (order_value->value.type->id == TypeTableEntryIdInvalid)
11131 if (type_is_invalid(order_value->value.type))
1111611132 return ira->codegen->builtin_types.entry_invalid;
1111711133
1111811134 AtomicOrder order;
......@@ -11125,18 +11141,18 @@ static TypeTableEntry *ir_analyze_instruction_fence(IrAnalyze *ira, IrInstructio
1112511141
1112611142static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstructionDivExact *instruction) {
1112711143 IrInstruction *op1 = instruction->op1->other;
11128 if (op1->value.type->id == TypeTableEntryIdInvalid)
11144 if (type_is_invalid(op1->value.type))
1112911145 return ira->codegen->builtin_types.entry_invalid;
1113011146
1113111147 IrInstruction *op2 = instruction->op2->other;
11132 if (op2->value.type->id == TypeTableEntryIdInvalid)
11148 if (type_is_invalid(op2->value.type))
1113311149 return ira->codegen->builtin_types.entry_invalid;
1113411150
1113511151
1113611152 IrInstruction *peer_instructions[] = { op1, op2 };
1113711153 TypeTableEntry *result_type = ir_resolve_peer_types(ira, instruction->base.source_node, peer_instructions, 2);
1113811154
11139 if (result_type->id == TypeTableEntryIdInvalid)
11155 if (type_is_invalid(result_type))
1114011156 return ira->codegen->builtin_types.entry_invalid;
1114111157
1114211158 TypeTableEntry *canon_type = get_underlying_type(result_type);
......@@ -11151,11 +11167,11 @@ static TypeTableEntry *ir_analyze_instruction_div_exact(IrAnalyze *ira, IrInstru
1115111167 }
1115211168
1115311169 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, result_type);
11154 if (casted_op1->value.type->id == TypeTableEntryIdInvalid)
11170 if (type_is_invalid(casted_op1->value.type))
1115511171 return ira->codegen->builtin_types.entry_invalid;
1115611172
1115711173 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, result_type);
11158 if (casted_op2->value.type->id == TypeTableEntryIdInvalid)
11174 if (type_is_invalid(casted_op2->value.type))
1115911175 return ira->codegen->builtin_types.entry_invalid;
1116011176
1116111177 if (casted_op1->value.special == ConstValSpecialStatic &&
......@@ -11196,7 +11212,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
1119611212 TypeTableEntry *dest_type = ir_resolve_type(ira, dest_type_value);
1119711213 TypeTableEntry *canon_dest_type = get_underlying_type(dest_type);
1119811214
11199 if (canon_dest_type->id == TypeTableEntryIdInvalid)
11215 if (type_is_invalid(canon_dest_type))
1120011216 return ira->codegen->builtin_types.entry_invalid;
1120111217
1120211218 if (canon_dest_type->id != TypeTableEntryIdInt &&
......@@ -11210,7 +11226,7 @@ static TypeTableEntry *ir_analyze_instruction_truncate(IrAnalyze *ira, IrInstruc
1121011226 IrInstruction *target = instruction->target->other;
1121111227 TypeTableEntry *src_type = target->value.type;
1121211228 TypeTableEntry *canon_src_type = get_underlying_type(src_type);
11213 if (canon_src_type->id == TypeTableEntryIdInvalid)
11229 if (type_is_invalid(canon_src_type))
1121411230 return ira->codegen->builtin_types.entry_invalid;
1121511231
1121611232 if (canon_src_type->id != TypeTableEntryIdInt &&
......@@ -11262,13 +11278,13 @@ static TypeTableEntry *ir_analyze_instruction_int_type(IrAnalyze *ira, IrInstruc
1126211278
1126311279static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstructionBoolNot *instruction) {
1126411280 IrInstruction *value = instruction->value->other;
11265 if (value->value.type->id == TypeTableEntryIdInvalid)
11281 if (type_is_invalid(value->value.type))
1126611282 return ira->codegen->builtin_types.entry_invalid;
1126711283
1126811284 TypeTableEntry *bool_type = ira->codegen->builtin_types.entry_bool;
1126911285
1127011286 IrInstruction *casted_value = ir_implicit_cast(ira, value, bool_type);
11271 if (casted_value->value.type->id == TypeTableEntryIdInvalid)
11287 if (type_is_invalid(casted_value->value.type))
1127211288 return ira->codegen->builtin_types.entry_invalid;
1127311289
1127411290 if (casted_value->value.special != ConstValSpecialRuntime) {
......@@ -11283,11 +11299,11 @@ static TypeTableEntry *ir_analyze_instruction_bool_not(IrAnalyze *ira, IrInstruc
1128311299
1128411300static TypeTableEntry *ir_analyze_instruction_alloca(IrAnalyze *ira, IrInstructionAlloca *instruction) {
1128511301 IrInstruction *type_value = instruction->type_value->other;
11286 if (type_value->value.type->id == TypeTableEntryIdInvalid)
11302 if (type_is_invalid(type_value->value.type))
1128711303 return ira->codegen->builtin_types.entry_invalid;
1128811304
1128911305 IrInstruction *count_value = instruction->count->other;
11290 if (count_value->value.type->id == TypeTableEntryIdInvalid)
11306 if (type_is_invalid(count_value->value.type))
1129111307 return ira->codegen->builtin_types.entry_invalid;
1129211308
1129311309 TypeTableEntry *child_type = ir_resolve_type(ira, type_value);
......@@ -11308,15 +11324,15 @@ static TypeTableEntry *ir_analyze_instruction_alloca(IrAnalyze *ira, IrInstructi
1130811324
1130911325static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructionMemset *instruction) {
1131011326 IrInstruction *dest_ptr = instruction->dest_ptr->other;
11311 if (dest_ptr->value.type->id == TypeTableEntryIdInvalid)
11327 if (type_is_invalid(dest_ptr->value.type))
1131211328 return ira->codegen->builtin_types.entry_invalid;
1131311329
1131411330 IrInstruction *byte_value = instruction->byte->other;
11315 if (byte_value->value.type->id == TypeTableEntryIdInvalid)
11331 if (type_is_invalid(byte_value->value.type))
1131611332 return ira->codegen->builtin_types.entry_invalid;
1131711333
1131811334 IrInstruction *count_value = instruction->count->other;
11319 if (count_value->value.type->id == TypeTableEntryIdInvalid)
11335 if (type_is_invalid(count_value->value.type))
1132011336 return ira->codegen->builtin_types.entry_invalid;
1132111337
1132211338 TypeTableEntry *dest_uncasted_type = get_underlying_type(dest_ptr->value.type);
......@@ -11328,15 +11344,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
1132811344 TypeTableEntry *u8_ptr = get_pointer_to_type_extra(ira->codegen, u8, false, dest_is_volatile, 0, 0);
1132911345
1133011346 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr);
11331 if (casted_dest_ptr->value.type->id == TypeTableEntryIdInvalid)
11347 if (type_is_invalid(casted_dest_ptr->value.type))
1133211348 return ira->codegen->builtin_types.entry_invalid;
1133311349
1133411350 IrInstruction *casted_byte = ir_implicit_cast(ira, byte_value, u8);
11335 if (casted_byte->value.type->id == TypeTableEntryIdInvalid)
11351 if (type_is_invalid(casted_byte->value.type))
1133611352 return ira->codegen->builtin_types.entry_invalid;
1133711353
1133811354 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
11339 if (casted_count->value.type->id == TypeTableEntryIdInvalid)
11355 if (type_is_invalid(casted_count->value.type))
1134011356 return ira->codegen->builtin_types.entry_invalid;
1134111357
1134211358 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
......@@ -11393,15 +11409,15 @@ static TypeTableEntry *ir_analyze_instruction_memset(IrAnalyze *ira, IrInstructi
1139311409
1139411410static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructionMemcpy *instruction) {
1139511411 IrInstruction *dest_ptr = instruction->dest_ptr->other;
11396 if (dest_ptr->value.type->id == TypeTableEntryIdInvalid)
11412 if (type_is_invalid(dest_ptr->value.type))
1139711413 return ira->codegen->builtin_types.entry_invalid;
1139811414
1139911415 IrInstruction *src_ptr = instruction->src_ptr->other;
11400 if (src_ptr->value.type->id == TypeTableEntryIdInvalid)
11416 if (type_is_invalid(src_ptr->value.type))
1140111417 return ira->codegen->builtin_types.entry_invalid;
1140211418
1140311419 IrInstruction *count_value = instruction->count->other;
11404 if (count_value->value.type->id == TypeTableEntryIdInvalid)
11420 if (type_is_invalid(count_value->value.type))
1140511421 return ira->codegen->builtin_types.entry_invalid;
1140611422
1140711423 TypeTableEntry *dest_uncasted_type = get_underlying_type(dest_ptr->value.type);
......@@ -11417,15 +11433,15 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
1141711433 TypeTableEntry *u8_ptr_const = get_pointer_to_type_extra(ira->codegen, u8, true, src_is_volatile, 0, 0);
1141811434
1141911435 IrInstruction *casted_dest_ptr = ir_implicit_cast(ira, dest_ptr, u8_ptr_mut);
11420 if (casted_dest_ptr->value.type->id == TypeTableEntryIdInvalid)
11436 if (type_is_invalid(casted_dest_ptr->value.type))
1142111437 return ira->codegen->builtin_types.entry_invalid;
1142211438
1142311439 IrInstruction *casted_src_ptr = ir_implicit_cast(ira, src_ptr, u8_ptr_const);
11424 if (casted_src_ptr->value.type->id == TypeTableEntryIdInvalid)
11440 if (type_is_invalid(casted_src_ptr->value.type))
1142511441 return ira->codegen->builtin_types.entry_invalid;
1142611442
1142711443 IrInstruction *casted_count = ir_implicit_cast(ira, count_value, usize);
11428 if (casted_count->value.type->id == TypeTableEntryIdInvalid)
11444 if (type_is_invalid(casted_count->value.type))
1142911445 return ira->codegen->builtin_types.entry_invalid;
1143011446
1143111447 if (casted_dest_ptr->value.special == ConstValSpecialStatic &&
......@@ -11514,7 +11530,7 @@ static TypeTableEntry *ir_analyze_instruction_memcpy(IrAnalyze *ira, IrInstructi
1151411530
1151511531static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructionSlice *instruction) {
1151611532 IrInstruction *ptr_ptr = instruction->ptr->other;
11517 if (ptr_ptr->value.type->id == TypeTableEntryIdInvalid)
11533 if (type_is_invalid(ptr_ptr->value.type))
1151811534 return ira->codegen->builtin_types.entry_invalid;
1151911535
1152011536 TypeTableEntry *ptr_type = ptr_ptr->value.type;
......@@ -11523,21 +11539,21 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1152311539 TypeTableEntry *canon_array_type = get_underlying_type(non_canon_array_type);
1152411540
1152511541 IrInstruction *start = instruction->start->other;
11526 if (start->value.type->id == TypeTableEntryIdInvalid)
11542 if (type_is_invalid(start->value.type))
1152711543 return ira->codegen->builtin_types.entry_invalid;
1152811544
1152911545 TypeTableEntry *usize = ira->codegen->builtin_types.entry_usize;
1153011546 IrInstruction *casted_start = ir_implicit_cast(ira, start, usize);
11531 if (casted_start->value.type->id == TypeTableEntryIdInvalid)
11547 if (type_is_invalid(casted_start->value.type))
1153211548 return ira->codegen->builtin_types.entry_invalid;
1153311549
1153411550 IrInstruction *end;
1153511551 if (instruction->end) {
1153611552 end = instruction->end->other;
11537 if (end->value.type->id == TypeTableEntryIdInvalid)
11553 if (type_is_invalid(end->value.type))
1153811554 return ira->codegen->builtin_types.entry_invalid;
1153911555 end = ir_implicit_cast(ira, end, usize);
11540 if (end->value.type->id == TypeTableEntryIdInvalid)
11556 if (type_is_invalid(end->value.type))
1154111557 return ira->codegen->builtin_types.entry_invalid;
1154211558 } else {
1154311559 end = nullptr;
......@@ -11692,13 +11708,13 @@ static TypeTableEntry *ir_analyze_instruction_slice(IrAnalyze *ira, IrInstructio
1169211708
1169311709static TypeTableEntry *ir_analyze_instruction_member_count(IrAnalyze *ira, IrInstructionMemberCount *instruction) {
1169411710 IrInstruction *container = instruction->container->other;
11695 if (container->value.type->id == TypeTableEntryIdInvalid)
11711 if (type_is_invalid(container->value.type))
1169611712 return ira->codegen->builtin_types.entry_invalid;
1169711713 TypeTableEntry *container_type = ir_resolve_type(ira, container);
1169811714 TypeTableEntry *canon_type = get_underlying_type(container_type);
1169911715
1170011716 uint64_t result;
11701 if (canon_type->id == TypeTableEntryIdInvalid) {
11717 if (type_is_invalid(canon_type)) {
1170211718 return ira->codegen->builtin_types.entry_invalid;
1170311719 } else if (canon_type->id == TypeTableEntryIdEnum) {
1170411720 result = canon_type->data.enumeration.src_field_count;
......@@ -11739,11 +11755,11 @@ static TypeTableEntry *ir_analyze_instruction_frame_address(IrAnalyze *ira, IrIn
1173911755
1174011756static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstructionAlignOf *instruction) {
1174111757 IrInstruction *type_value = instruction->type_value->other;
11742 if (type_value->value.type->id == TypeTableEntryIdInvalid)
11758 if (type_is_invalid(type_value->value.type))
1174311759 return ira->codegen->builtin_types.entry_invalid;
1174411760 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
1174511761
11746 if (type_entry->id == TypeTableEntryIdInvalid) {
11762 if (type_is_invalid(type_entry)) {
1174711763 return ira->codegen->builtin_types.entry_invalid;
1174811764 } else if (type_entry->id == TypeTableEntryIdUnreachable) {
1174911765 ir_add_error(ira, instruction->type_value,
......@@ -11759,11 +11775,11 @@ static TypeTableEntry *ir_analyze_instruction_alignof(IrAnalyze *ira, IrInstruct
1175911775
1176011776static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInstructionOverflowOp *instruction) {
1176111777 IrInstruction *type_value = instruction->type_value->other;
11762 if (type_value->value.type->id == TypeTableEntryIdInvalid)
11778 if (type_is_invalid(type_value->value.type))
1176311779 return ira->codegen->builtin_types.entry_invalid;
1176411780 TypeTableEntry *dest_type = ir_resolve_type(ira, type_value);
1176511781 TypeTableEntry *canon_type = get_underlying_type(dest_type);
11766 if (canon_type->id == TypeTableEntryIdInvalid)
11782 if (type_is_invalid(canon_type))
1176711783 return ira->codegen->builtin_types.entry_invalid;
1176811784
1176911785 if (canon_type->id != TypeTableEntryIdInt) {
......@@ -11774,28 +11790,28 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1177411790 }
1177511791
1177611792 IrInstruction *op1 = instruction->op1->other;
11777 if (op1->value.type->id == TypeTableEntryIdInvalid)
11793 if (type_is_invalid(op1->value.type))
1177811794 return ira->codegen->builtin_types.entry_invalid;
1177911795
1178011796 IrInstruction *casted_op1 = ir_implicit_cast(ira, op1, dest_type);
11781 if (casted_op1->value.type->id == TypeTableEntryIdInvalid)
11797 if (type_is_invalid(casted_op1->value.type))
1178211798 return ira->codegen->builtin_types.entry_invalid;
1178311799
1178411800 IrInstruction *op2 = instruction->op2->other;
11785 if (op2->value.type->id == TypeTableEntryIdInvalid)
11801 if (type_is_invalid(op2->value.type))
1178611802 return ira->codegen->builtin_types.entry_invalid;
1178711803
1178811804 IrInstruction *casted_op2 = ir_implicit_cast(ira, op2, dest_type);
11789 if (casted_op2->value.type->id == TypeTableEntryIdInvalid)
11805 if (type_is_invalid(casted_op2->value.type))
1179011806 return ira->codegen->builtin_types.entry_invalid;
1179111807
1179211808 IrInstruction *result_ptr = instruction->result_ptr->other;
11793 if (result_ptr->value.type->id == TypeTableEntryIdInvalid)
11809 if (type_is_invalid(result_ptr->value.type))
1179411810 return ira->codegen->builtin_types.entry_invalid;
1179511811
1179611812 TypeTableEntry *expected_ptr_type = get_pointer_to_type(ira->codegen, dest_type, false);
1179711813 IrInstruction *casted_result_ptr = ir_implicit_cast(ira, result_ptr, expected_ptr_type);
11798 if (casted_result_ptr->value.type->id == TypeTableEntryIdInvalid)
11814 if (type_is_invalid(casted_result_ptr->value.type))
1179911815 return ira->codegen->builtin_types.entry_invalid;
1180011816
1180111817 if (casted_op1->value.special == ConstValSpecialStatic &&
......@@ -11838,13 +11854,13 @@ static TypeTableEntry *ir_analyze_instruction_overflow_op(IrAnalyze *ira, IrInst
1183811854
1183911855static TypeTableEntry *ir_analyze_instruction_test_err(IrAnalyze *ira, IrInstructionTestErr *instruction) {
1184011856 IrInstruction *value = instruction->value->other;
11841 if (value->value.type->id == TypeTableEntryIdInvalid)
11857 if (type_is_invalid(value->value.type))
1184211858 return ira->codegen->builtin_types.entry_invalid;
1184311859
1184411860 TypeTableEntry *non_canon_type = value->value.type;
1184511861
1184611862 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);
11847 if (canon_type->id == TypeTableEntryIdInvalid) {
11863 if (type_is_invalid(canon_type)) {
1184811864 return ira->codegen->builtin_types.entry_invalid;
1184911865 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
1185011866 if (instr_is_comptime(value)) {
......@@ -11876,7 +11892,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
1187611892 IrInstructionUnwrapErrCode *instruction)
1187711893{
1187811894 IrInstruction *value = instruction->value->other;
11879 if (value->value.type->id == TypeTableEntryIdInvalid)
11895 if (type_is_invalid(value->value.type))
1188011896 return ira->codegen->builtin_types.entry_invalid;
1188111897 TypeTableEntry *ptr_type = value->value.type;
1188211898
......@@ -11885,7 +11901,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_code(IrAnalyze *ira,
1188511901
1188611902 TypeTableEntry *non_canon_type = ptr_type->data.pointer.child_type;
1188711903 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);
11888 if (canon_type->id == TypeTableEntryIdInvalid) {
11904 if (type_is_invalid(canon_type)) {
1188911905 return ira->codegen->builtin_types.entry_invalid;
1189011906 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
1189111907 if (instr_is_comptime(value)) {
......@@ -11918,7 +11934,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1191811934{
1191911935 assert(instruction->value->other);
1192011936 IrInstruction *value = instruction->value->other;
11921 if (value->value.type->id == TypeTableEntryIdInvalid)
11937 if (type_is_invalid(value->value.type))
1192211938 return ira->codegen->builtin_types.entry_invalid;
1192311939 TypeTableEntry *ptr_type = value->value.type;
1192411940
......@@ -11927,7 +11943,7 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_err_payload(IrAnalyze *ira,
1192711943
1192811944 TypeTableEntry *non_canon_type = ptr_type->data.pointer.child_type;
1192911945 TypeTableEntry *canon_type = get_underlying_type(non_canon_type);
11930 if (canon_type->id == TypeTableEntryIdInvalid) {
11946 if (type_is_invalid(canon_type)) {
1193111947 return ira->codegen->builtin_types.entry_invalid;
1193211948 } else if (canon_type->id == TypeTableEntryIdErrorUnion) {
1193311949 TypeTableEntry *child_type = canon_type->data.error.child_type;
......@@ -11980,13 +11996,13 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
1198011996 FnTypeParamInfo *param_info = &fn_type_id.param_info[fn_type_id.next_param_index];
1198111997 param_info->is_noalias = param_node->data.param_decl.is_noalias;
1198211998 param_info->type = ir_resolve_type(ira, param_type_value);
11983 if (param_info->type->id == TypeTableEntryIdInvalid)
11999 if (type_is_invalid(param_info->type))
1198412000 return ira->codegen->builtin_types.entry_invalid;
1198512001 }
1198612002
1198712003 IrInstruction *return_type_value = instruction->return_type->other;
1198812004 fn_type_id.return_type = ir_resolve_type(ira, return_type_value);
11989 if (fn_type_id.return_type->id == TypeTableEntryIdInvalid)
12005 if (type_is_invalid(fn_type_id.return_type))
1199012006 return ira->codegen->builtin_types.entry_invalid;
1199112007
1199212008 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
......@@ -11996,7 +12012,7 @@ static TypeTableEntry *ir_analyze_instruction_fn_proto(IrAnalyze *ira, IrInstruc
1199612012
1199712013static TypeTableEntry *ir_analyze_instruction_test_comptime(IrAnalyze *ira, IrInstructionTestComptime *instruction) {
1199812014 IrInstruction *value = instruction->value->other;
11999 if (value->value.type->id == TypeTableEntryIdInvalid)
12015 if (type_is_invalid(value->value.type))
1200012016 return ira->codegen->builtin_types.entry_invalid;
1200112017
1200212018 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
......@@ -12009,7 +12025,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1200912025{
1201012026 IrInstruction *target_value = instruction->target_value->other;
1201112027 TypeTableEntry *switch_type = target_value->value.type;
12012 if (switch_type->id == TypeTableEntryIdInvalid)
12028 if (type_is_invalid(switch_type))
1201312029 return ira->codegen->builtin_types.entry_invalid;
1201412030
1201512031 if (switch_type->id == TypeTableEntryIdEnumTag) {
......@@ -12019,11 +12035,11 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1201912035 IrInstructionCheckSwitchProngsRange *range = &instruction->ranges[range_i];
1202012036
1202112037 IrInstruction *start_value = range->start->other;
12022 if (start_value->value.type->id == TypeTableEntryIdInvalid)
12038 if (type_is_invalid(start_value->value.type))
1202312039 return ira->codegen->builtin_types.entry_invalid;
1202412040
1202512041 IrInstruction *end_value = range->end->other;
12026 if (end_value->value.type->id == TypeTableEntryIdInvalid)
12042 if (type_is_invalid(end_value->value.type))
1202712043 return ira->codegen->builtin_types.entry_invalid;
1202812044
1202912045 size_t start_index;
......@@ -12070,7 +12086,7 @@ static TypeTableEntry *ir_analyze_instruction_check_switch_prongs(IrAnalyze *ira
1207012086static TypeTableEntry *ir_analyze_instruction_test_type(IrAnalyze *ira, IrInstructionTestType *instruction) {
1207112087 IrInstruction *type_value = instruction->type_value->other;
1207212088 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
12073 if (type_entry->id == TypeTableEntryIdInvalid)
12089 if (type_is_invalid(type_entry))
1207412090 return ira->codegen->builtin_types.entry_invalid;
1207512091
1207612092 ConstExprValue *out_val = ir_build_const_from(ira, &instruction->base);
......@@ -12083,11 +12099,11 @@ static TypeTableEntry *ir_analyze_instruction_can_implicit_cast(IrAnalyze *ira,
1208312099{
1208412100 IrInstruction *type_value = instruction->type_value->other;
1208512101 TypeTableEntry *type_entry = ir_resolve_type(ira, type_value);
12086 if (type_entry->id == TypeTableEntryIdInvalid)
12102 if (type_is_invalid(type_entry))
1208712103 return ira->codegen->builtin_types.entry_invalid;
1208812104
1208912105 IrInstruction *target_value = instruction->target_value->other;
12090 if (target_value->value.type->id == TypeTableEntryIdInvalid)
12106 if (type_is_invalid(target_value->value.type))
1209112107 return ira->codegen->builtin_types.entry_invalid;
1209212108
1209312109 ImplicitCastMatchResult result = ir_types_match_with_implicit_cast(ira, type_entry, target_value->value.type,
test/run_tests.cpp+38-6
......@@ -93,10 +93,9 @@ static TestCase *add_simple_case_libc(const char *case_name, const char *source,
9393 return tc;
9494}
9595
96static TestCase *add_compile_fail_case(const char *case_name, const char *source, size_t count, ...) {
97 va_list ap;
98 va_start(ap, count);
99
96static TestCase *add_compile_fail_case_extra(const char *case_name, const char *source, bool check_unused,
97 size_t count, va_list ap)
98{
10099 TestCase *test_case = allocate<TestCase>(1);
101100 test_case->case_name = case_name;
102101 test_case->source_files.resize(1);
......@@ -122,13 +121,30 @@ static TestCase *add_compile_fail_case(const char *case_name, const char *source
122121
123122 test_case->compiler_args.append("--release");
124123 test_case->compiler_args.append("--strip");
125 test_case->compiler_args.append("--check-unused");
124
125 if (check_unused) {
126 test_case->compiler_args.append("--check-unused");
127 }
126128
127129 test_cases.append(test_case);
128130
131 return test_case;
132}
133
134static TestCase *add_compile_fail_case_no_check_unused(const char *case_name, const char *source, size_t count, ...) {
135 va_list ap;
136 va_start(ap, count);
137 TestCase *result = add_compile_fail_case_extra(case_name, source, false, count, ap);
129138 va_end(ap);
139 return result;
140}
130141
131 return test_case;
142static TestCase *add_compile_fail_case(const char *case_name, const char *source, size_t count, ...) {
143 va_list ap;
144 va_start(ap, count);
145 TestCase *result = add_compile_fail_case_extra(case_name, source, true, count, ap);
146 va_end(ap);
147 return result;
132148}
133149
134150static void add_debug_safety_case(const char *case_name, const char *source) {
......@@ -1646,6 +1662,22 @@ fn bar(x: &const u3) -> u3 {
16461662}
16471663 )SOURCE", 1, ".tmp_source.zig:12:26: error: expected type '&const u3', found '&:3:6 const u3'");
16481664
1665 add_compile_fail_case_no_check_unused("referring to a struct that is invalid without --check-unused", R"SOURCE(
1666const UsbDeviceRequest = struct {
1667 Type: u8,
1668};
1669
1670export fn foo() {
1671 comptime assert(@sizeOf(UsbDeviceRequest) == 0x8);
1672}
1673
1674fn assert(ok: bool) {
1675 if (!ok) @unreachable();
1676}
1677 )SOURCE", 2,
1678 ".tmp_source.zig:11:14: error: unable to evaluate constant expression",
1679 ".tmp_source.zig:7:20: note: called from here");
1680
16491681}
16501682
16511683//////////////////////////////////////////////////////////////////////////////