authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-26 14:01:59-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-26 14:01:59-04:00
logd316f704501ff7fc809fdfb082226031ef875046
tree0f436bc3f8af84e90c13b42c3d5c45fa3d3f056d
parent73a7747a9cfb180a92fa0d98f9387d5ad1f47fd2
signaturelock-open Commit is signed but in an unrecognized format.

fix regression on struct field with undefined type


5 files changed, 40 insertions(+), 52 deletions(-)

src/analyze.cpp+25-34
...@@ -961,18 +961,14 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind...@@ -961,18 +961,14 @@ ZigType *get_partial_container_type(CodeGen *g, Scope *scope, ContainerKind kind
961 return entry;961 return entry;
962}962}
963963
964ConstExprValue *analyze_const_value_allow_lazy(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,964ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,
965 Buf *type_name, bool allow_lazy)965 Buf *type_name, UndefAllowed undef)
966{966{
967 size_t backward_branch_count = 0;967 size_t backward_branch_count = 0;
968 size_t backward_branch_quota = default_backward_branch_quota;968 size_t backward_branch_quota = default_backward_branch_quota;
969 return ir_eval_const_value(g, scope, node, type_entry,969 return ir_eval_const_value(g, scope, node, type_entry,
970 &backward_branch_count, &backward_branch_quota,970 &backward_branch_count, &backward_branch_quota,
971 nullptr, nullptr, node, type_name, nullptr, nullptr, allow_lazy);971 nullptr, nullptr, node, type_name, nullptr, nullptr, undef);
972}
973
974ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name) {
975 return analyze_const_value_allow_lazy(g, scope, node, type_entry, type_name, false);
976}972}
977973
978static Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type,974static Error type_val_resolve_zero_bits(CodeGen *g, ConstExprValue *type_val, ZigType *parent_type,
...@@ -1162,22 +1158,12 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons...@@ -1162,22 +1158,12 @@ static OnePossibleValue type_val_resolve_has_one_possible_value(CodeGen *g, Cons
1162}1158}
11631159
1164ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {1160ZigType *analyze_type_expr(CodeGen *g, Scope *scope, AstNode *node) {
1165 ConstExprValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type, nullptr);1161 ConstExprValue *result = analyze_const_value(g, scope, node, g->builtin_types.entry_type,
1162 nullptr, UndefBad);
1166 if (type_is_invalid(result->type))1163 if (type_is_invalid(result->type))
1167 return g->builtin_types.entry_invalid;1164 return g->builtin_types.entry_invalid;
11681165 src_assert(result->special == ConstValSpecialStatic, node);
1169 assert(result->special != ConstValSpecialRuntime);1166 src_assert(result->data.x_type != nullptr, node);
1170 // Reject undefined as valid `type` type even though the specification
1171 // allows it to be casted to anything.
1172 // See also ir_resolve_type()
1173 if (result->special == ConstValSpecialUndef) {
1174 add_node_error(g, node,
1175 buf_sprintf("expected type 'type', found '%s'",
1176 buf_ptr(&g->builtin_types.entry_undef->name)));
1177 return g->builtin_types.entry_invalid;
1178 }
1179
1180 assert(result->data.x_type != nullptr);
1181 return result->data.x_type;1167 return result->data.x_type;
1182}1168}
11831169
...@@ -1225,7 +1211,8 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_cou...@@ -1225,7 +1211,8 @@ void init_fn_type_id(FnTypeId *fn_type_id, AstNode *proto_node, size_t param_cou
1225}1211}
12261212
1227static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_t *result) {1213static bool analyze_const_align(CodeGen *g, Scope *scope, AstNode *node, uint32_t *result) {
1228 ConstExprValue *align_result = analyze_const_value(g, scope, node, get_align_amt_type(g), nullptr);1214 ConstExprValue *align_result = analyze_const_value(g, scope, node, get_align_amt_type(g),
1215 nullptr, UndefBad);
1229 if (type_is_invalid(align_result->type))1216 if (type_is_invalid(align_result->type))
1230 return false;1217 return false;
12311218
...@@ -1247,7 +1234,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **...@@ -1247,7 +1234,7 @@ static bool analyze_const_string(CodeGen *g, Scope *scope, AstNode *node, Buf **
1247 ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,1234 ZigType *ptr_type = get_pointer_to_type_extra(g, g->builtin_types.entry_u8, true, false,
1248 PtrLenUnknown, 0, 0, 0, false);1235 PtrLenUnknown, 0, 0, 0, false);
1249 ZigType *str_type = get_slice_type(g, ptr_type);1236 ZigType *str_type = get_slice_type(g, ptr_type);
1250 ConstExprValue *result_val = analyze_const_value(g, scope, node, str_type, nullptr);1237 ConstExprValue *result_val = analyze_const_value(g, scope, node, str_type, nullptr, UndefBad);
1251 if (type_is_invalid(result_val->type))1238 if (type_is_invalid(result_val->type))
1252 return false;1239 return false;
12531240
...@@ -2261,7 +2248,8 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {...@@ -2261,7 +2248,8 @@ static Error resolve_enum_zero_bits(CodeGen *g, ZigType *enum_type) {
22612248
2262 if (tag_value != nullptr) {2249 if (tag_value != nullptr) {
2263 // A user-specified value is available2250 // A user-specified value is available
2264 ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);2251 ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type,
2252 nullptr, UndefBad);
2265 if (type_is_invalid(result->type)) {2253 if (type_is_invalid(result->type)) {
2266 enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;2254 enum_type->data.enumeration.resolve_status = ResolveStatusInvalid;
2267 continue;2255 continue;
...@@ -2377,8 +2365,8 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {...@@ -2377,8 +2365,8 @@ static Error resolve_struct_zero_bits(CodeGen *g, ZigType *struct_type) {
2377 return ErrorSemanticAnalyzeFail;2365 return ErrorSemanticAnalyzeFail;
2378 }2366 }
23792367
2380 ConstExprValue *field_type_val = analyze_const_value_allow_lazy(g, scope,2368 ConstExprValue *field_type_val = analyze_const_value(g, scope,
2381 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, true);2369 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);
2382 if (type_is_invalid(field_type_val->type)) {2370 if (type_is_invalid(field_type_val->type)) {
2383 struct_type->data.structure.resolve_status = ResolveStatusInvalid;2371 struct_type->data.structure.resolve_status = ResolveStatusInvalid;
2384 return ErrorSemanticAnalyzeFail;2372 return ErrorSemanticAnalyzeFail;
...@@ -2660,8 +2648,8 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -2660,8 +2648,8 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2660 return ErrorSemanticAnalyzeFail;2648 return ErrorSemanticAnalyzeFail;
2661 }2649 }
2662 } else {2650 } else {
2663 ConstExprValue *field_type_val = analyze_const_value_allow_lazy(g, scope,2651 ConstExprValue *field_type_val = analyze_const_value(g, scope,
2664 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, true);2652 field_node->data.struct_field.type, g->builtin_types.entry_type, nullptr, LazyOkNoUndef);
2665 if (type_is_invalid(field_type_val->type)) {2653 if (type_is_invalid(field_type_val->type)) {
2666 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2654 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2667 return ErrorSemanticAnalyzeFail;2655 return ErrorSemanticAnalyzeFail;
...@@ -2726,7 +2714,8 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {...@@ -2726,7 +2714,8 @@ static Error resolve_union_zero_bits(CodeGen *g, ZigType *union_type) {
2726 // In a second pass we will fill in the unspecified ones.2714 // In a second pass we will fill in the unspecified ones.
2727 if (tag_value != nullptr) {2715 if (tag_value != nullptr) {
2728 ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;2716 ZigType *tag_int_type = tag_type->data.enumeration.tag_int_type;
2729 ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type, nullptr);2717 ConstExprValue *result = analyze_const_value(g, scope, tag_value, tag_int_type,
2718 nullptr, UndefBad);
2730 if (type_is_invalid(result->type)) {2719 if (type_is_invalid(result->type)) {
2731 union_type->data.unionation.resolve_status = ResolveStatusInvalid;2720 union_type->data.unionation.resolve_status = ResolveStatusInvalid;
2732 return ErrorSemanticAnalyzeFail;2721 return ErrorSemanticAnalyzeFail;
...@@ -2929,7 +2918,7 @@ void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn) {...@@ -2929,7 +2918,7 @@ void typecheck_panic_fn(CodeGen *g, TldFn *tld_fn, ZigFn *panic_fn) {
2929 fake_decl->data.symbol_expr.symbol = tld_fn->base.name;2918 fake_decl->data.symbol_expr.symbol = tld_fn->base.name;
29302919
2931 // call this for the side effects of casting to panic_fn_type2920 // call this for the side effects of casting to panic_fn_type
2932 analyze_const_value(g, tld_fn->base.parent_scope, fake_decl, panic_fn_type, nullptr);2921 analyze_const_value(g, tld_fn->base.parent_scope, fake_decl, panic_fn_type, nullptr, UndefBad);
2933}2922}
29342923
2935ZigType *get_test_fn_type(CodeGen *g) {2924ZigType *get_test_fn_type(CodeGen *g) {
...@@ -3075,7 +3064,8 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {...@@ -3075,7 +3064,8 @@ static void resolve_decl_fn(CodeGen *g, TldFn *tld_fn) {
3075static void resolve_decl_comptime(CodeGen *g, TldCompTime *tld_comptime) {3064static void resolve_decl_comptime(CodeGen *g, TldCompTime *tld_comptime) {
3076 assert(tld_comptime->base.source_node->type == NodeTypeCompTime);3065 assert(tld_comptime->base.source_node->type == NodeTypeCompTime);
3077 AstNode *expr_node = tld_comptime->base.source_node->data.comptime_expr.expr;3066 AstNode *expr_node = tld_comptime->base.source_node->data.comptime_expr.expr;
3078 analyze_const_value(g, tld_comptime->base.parent_scope, expr_node, g->builtin_types.entry_void, nullptr);3067 analyze_const_value(g, tld_comptime->base.parent_scope, expr_node, g->builtin_types.entry_void,
3068 nullptr, UndefBad);
3079}3069}
30803070
3081static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {3071static void add_top_level_decl(CodeGen *g, ScopeDecls *decls_scope, Tld *tld) {
...@@ -3443,8 +3433,8 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {...@@ -3443,8 +3433,8 @@ static void resolve_decl_var(CodeGen *g, TldVar *tld_var, bool allow_lazy) {
3443 if (explicit_type && explicit_type->id == ZigTypeIdInvalid) {3433 if (explicit_type && explicit_type->id == ZigTypeIdInvalid) {
3444 implicit_type = explicit_type;3434 implicit_type = explicit_type;
3445 } else if (var_decl->expr) {3435 } else if (var_decl->expr) {
3446 init_value = analyze_const_value_allow_lazy(g, tld_var->base.parent_scope, var_decl->expr, explicit_type,3436 init_value = analyze_const_value(g, tld_var->base.parent_scope, var_decl->expr, explicit_type,
3447 var_decl->symbol, allow_lazy);3437 var_decl->symbol, allow_lazy ? LazyOk : UndefOk);
3448 assert(init_value);3438 assert(init_value);
3449 implicit_type = init_value->type;3439 implicit_type = init_value->type;
34503440
...@@ -3599,7 +3589,8 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco...@@ -3599,7 +3589,8 @@ static void preview_use_decl(CodeGen *g, TldUsingNamespace *using_namespace, Sco
3599 using_namespace->base.resolution = TldResolutionResolving;3589 using_namespace->base.resolution = TldResolutionResolving;
3600 assert(using_namespace->base.source_node->type == NodeTypeUsingNamespace);3590 assert(using_namespace->base.source_node->type == NodeTypeUsingNamespace);
3601 ConstExprValue *result = analyze_const_value(g, &dest_decls_scope->base,3591 ConstExprValue *result = analyze_const_value(g, &dest_decls_scope->base,
3602 using_namespace->base.source_node->data.using_namespace.expr, g->builtin_types.entry_type, nullptr);3592 using_namespace->base.source_node->data.using_namespace.expr, g->builtin_types.entry_type,
3593 nullptr, UndefBad);
3603 using_namespace->using_namespace_value = result;3594 using_namespace->using_namespace_value = result;
36043595
3605 if (type_is_invalid(result->type)) {3596 if (type_is_invalid(result->type)) {
src/analyze.hpp+2-3
...@@ -240,9 +240,8 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa...@@ -240,9 +240,8 @@ void add_cc_args(CodeGen *g, ZigList<const char *> &args, const char *out_dep_pa
240240
241void src_assert(bool ok, AstNode *source_node);241void src_assert(bool ok, AstNode *source_node);
242bool is_container(ZigType *type_entry);242bool is_container(ZigType *type_entry);
243ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry, Buf *type_name);243ConstExprValue *analyze_const_value(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,
244ConstExprValue *analyze_const_value_allow_lazy(CodeGen *g, Scope *scope, AstNode *node, ZigType *type_entry,244 Buf *type_name, UndefAllowed undef);
245 Buf *type_name, bool allow_lazy);
246245
247void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn);246void resolve_llvm_types_fn(CodeGen *g, ZigFn *fn);
248bool fn_is_async(ZigFn *fn);247bool fn_is_async(ZigFn *fn);
src/ir.cpp+11-13
...@@ -398,7 +398,7 @@ static void ir_ref_var(ZigVar *var) {...@@ -398,7 +398,7 @@ static void ir_ref_var(ZigVar *var) {
398ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {398ZigType *ir_analyze_type_expr(IrAnalyze *ira, Scope *scope, AstNode *node) {
399 ConstExprValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type,399 ConstExprValue *result = ir_eval_const_value(ira->codegen, scope, node, ira->codegen->builtin_types.entry_type,
400 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr,400 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr, nullptr,
401 node, nullptr, ira->new_irb.exec, nullptr, false);401 node, nullptr, ira->new_irb.exec, nullptr, UndefBad);
402402
403 if (type_is_invalid(result->type))403 if (type_is_invalid(result->type))
404 return ira->codegen->builtin_types.entry_invalid;404 return ira->codegen->builtin_types.entry_invalid;
...@@ -10734,14 +10734,14 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode...@@ -10734,14 +10734,14 @@ static Error ir_resolve_const_val(CodeGen *codegen, IrExecutable *exec, AstNode
10734 buf_sprintf("unable to evaluate constant expression"));10734 buf_sprintf("unable to evaluate constant expression"));
10735 return ErrorSemanticAnalyzeFail;10735 return ErrorSemanticAnalyzeFail;
10736 case ConstValSpecialUndef:10736 case ConstValSpecialUndef:
10737 if (undef_allowed == UndefOk)10737 if (undef_allowed == UndefOk || undef_allowed == LazyOk)
10738 return ErrorNone;10738 return ErrorNone;
1073910739
10740 exec_add_error_node(codegen, exec, source_node,10740 exec_add_error_node(codegen, exec, source_node,
10741 buf_sprintf("use of undefined value here causes undefined behavior"));10741 buf_sprintf("use of undefined value here causes undefined behavior"));
10742 return ErrorSemanticAnalyzeFail;10742 return ErrorSemanticAnalyzeFail;
10743 case ConstValSpecialLazy:10743 case ConstValSpecialLazy:
10744 if (undef_allowed == LazyOk)10744 if (undef_allowed == LazyOk || undef_allowed == LazyOkNoUndef)
10745 return ErrorNone;10745 return ErrorNone;
1074610746
10747 if ((err = ir_resolve_lazy(codegen, source_node, val)))10747 if ((err = ir_resolve_lazy(codegen, source_node, val)))
...@@ -10765,7 +10765,7 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un...@@ -10765,7 +10765,7 @@ static ConstExprValue *ir_resolve_const(IrAnalyze *ira, IrInstruction *value, Un
10765ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,10765ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
10766 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,10766 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
10767 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,10767 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
10768 IrExecutable *parent_exec, AstNode *expected_type_source_node, bool allow_lazy)10768 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef_allowed)
10769{10769{
10770 Error err;10770 Error err;
1077110771
...@@ -10819,11 +10819,8 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod...@@ -10819,11 +10819,8 @@ ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *nod
1081910819
10820 ConstExprValue *result = ir_exec_const_result(codegen, analyzed_executable);10820 ConstExprValue *result = ir_exec_const_result(codegen, analyzed_executable);
1082110821
10822 if (!allow_lazy) {10822 if ((err = ir_resolve_const_val(codegen, analyzed_executable, node, result, undef_allowed)))
10823 if ((err = ir_resolve_lazy(codegen, node, result))) {10823 return &codegen->invalid_instruction->value;
10824 return &codegen->invalid_instruction->value;
10825 }
10826 }
1082710824
10828 return result;10825 return result;
10829}10826}
...@@ -15578,7 +15575,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -15578,7 +15575,8 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
15578 AstNode *body_node = fn_entry->body_node;15575 AstNode *body_node = fn_entry->body_node;
15579 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,15576 result = ir_eval_const_value(ira->codegen, exec_scope, body_node, return_type,
15580 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,15577 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, fn_entry,
15581 nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec, return_type_node, false);15578 nullptr, call_instruction->base.source_node, nullptr, ira->new_irb.exec, return_type_node,
15579 UndefOk);
1558215580
15583 if (inferred_err_set_type != nullptr) {15581 if (inferred_err_set_type != nullptr) {
15584 inferred_err_set_type->data.error_set.infer_fn = nullptr;15582 inferred_err_set_type->data.error_set.infer_fn = nullptr;
...@@ -15776,7 +15774,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c...@@ -15776,7 +15774,7 @@ static IrInstruction *ir_analyze_fn_call(IrAnalyze *ira, IrInstructionCallSrc *c
15776 fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen),15774 fn_proto_node->data.fn_proto.align_expr, get_align_amt_type(ira->codegen),
15777 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,15775 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota,
15778 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,15776 nullptr, nullptr, fn_proto_node->data.fn_proto.align_expr, nullptr, ira->new_irb.exec,
15779 nullptr, false);15777 nullptr, UndefBad);
15780 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,15778 IrInstructionConst *const_instruction = ir_create_instruction<IrInstructionConst>(&ira->new_irb,
15781 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);15779 impl_fn->child_scope, fn_proto_node->data.fn_proto.align_expr);
15782 copy_const_val(&const_instruction->base.value, align_result, true);15780 copy_const_val(&const_instruction->base.value, align_result, true);
...@@ -19129,7 +19127,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc...@@ -19129,7 +19127,7 @@ static IrInstruction *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstruc
19129 Scope *analyze_scope = &get_container_scope(container_type)->base;19127 Scope *analyze_scope = &get_container_scope(container_type)->base;
19130 // memoize it19128 // memoize it
19131 field->init_val = analyze_const_value(ira->codegen, analyze_scope, init_node,19129 field->init_val = analyze_const_value(ira->codegen, analyze_scope, init_node,
19132 field->type_entry, nullptr);19130 field->type_entry, nullptr, UndefOk);
19133 }19131 }
19134 if (type_is_invalid(field->init_val->type))19132 if (type_is_invalid(field->init_val->type))
19135 return ira->codegen->invalid_instruction;19133 return ira->codegen->invalid_instruction;
...@@ -20640,7 +20638,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct...@@ -20640,7 +20638,7 @@ static IrInstruction *ir_analyze_instruction_c_import(IrAnalyze *ira, IrInstruct
20640 ZigType *void_type = ira->codegen->builtin_types.entry_void;20638 ZigType *void_type = ira->codegen->builtin_types.entry_void;
20641 ConstExprValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,20639 ConstExprValue *cimport_result = ir_eval_const_value(ira->codegen, &cimport_scope->base, block_node, void_type,
20642 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,20640 ira->new_irb.exec->backward_branch_count, ira->new_irb.exec->backward_branch_quota, nullptr,
20643 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, false);20641 &cimport_scope->buf, block_node, nullptr, nullptr, nullptr, UndefBad);
20644 if (type_is_invalid(cimport_result->type))20642 if (type_is_invalid(cimport_result->type))
20645 return ira->codegen->invalid_instruction;20643 return ira->codegen->invalid_instruction;
2064620644
src/ir.hpp+1-1
...@@ -16,7 +16,7 @@ bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);...@@ -16,7 +16,7 @@ bool ir_gen_fn(CodeGen *g, ZigFn *fn_entry);
16ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,16ConstExprValue *ir_eval_const_value(CodeGen *codegen, Scope *scope, AstNode *node,
17 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,17 ZigType *expected_type, size_t *backward_branch_count, size_t *backward_branch_quota,
18 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,18 ZigFn *fn_entry, Buf *c_import_buf, AstNode *source_node, Buf *exec_name,
19 IrExecutable *parent_exec, AstNode *expected_type_source_node, bool allow_lazy);19 IrExecutable *parent_exec, AstNode *expected_type_source_node, UndefAllowed undef);
2020
21Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val);21Error ir_resolve_lazy(CodeGen *codegen, AstNode *source_node, ConstExprValue *val);
2222
test/compile_errors.zig+1-1
...@@ -404,7 +404,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -404,7 +404,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
404 \\ const foo: Foo = undefined;404 \\ const foo: Foo = undefined;
405 \\}405 \\}
406 ,406 ,
407 "tmp.zig:2:8: error: expected type 'type', found '(undefined)'",407 "tmp.zig:2:8: error: use of undefined value here causes undefined behavior",
408 );408 );
409409
410 cases.add(410 cases.add(