authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-01 00:07:40-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-06-01 00:17:31-04:00
log019217d7a23bee69bd5ceb38aeeb5f689d5c2a9c
tree4fea2ee348cbbb08f4a6f81ddc7437574e475617
parent2f614c42fe4f28e5adda8163bd50d6d3507d6353

fix regressions


4 files changed, 110 insertions(+), 47 deletions(-)

src/ir.cpp+84-21
...@@ -9433,6 +9433,8 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so...@@ -9433,6 +9433,8 @@ static IrInstruction *ir_analyze_enum_to_union(IrAnalyze *ira, IrInstruction *so
9433 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);9433 TypeUnionField *union_field = find_union_field_by_tag(wanted_type, &val->data.x_enum_tag);
9434 assert(union_field != nullptr);9434 assert(union_field != nullptr);
9435 type_ensure_zero_bits_known(ira->codegen, union_field->type_entry);9435 type_ensure_zero_bits_known(ira->codegen, union_field->type_entry);
9436 if (type_is_invalid(union_field->type_entry))
9437 return ira->codegen->invalid_instruction;
9436 if (!union_field->type_entry->zero_bits) {9438 if (!union_field->type_entry->zero_bits) {
9437 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(9439 AstNode *field_node = wanted_type->data.unionation.decl_node->data.container_decl.fields.at(
9438 union_field->enum_field->decl_index);9440 union_field->enum_field->decl_index);
...@@ -10015,6 +10017,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst...@@ -10015,6 +10017,9 @@ static IrInstruction *ir_analyze_cast(IrAnalyze *ira, IrInstruction *source_inst
10015 if (actual_type->id == TypeTableEntryIdNumLitFloat ||10017 if (actual_type->id == TypeTableEntryIdNumLitFloat ||
10016 actual_type->id == TypeTableEntryIdNumLitInt)10018 actual_type->id == TypeTableEntryIdNumLitInt)
10017 {10019 {
10020 ensure_complete_type(ira->codegen, wanted_type);
10021 if (type_is_invalid(wanted_type))
10022 return ira->codegen->invalid_instruction;
10018 if (wanted_type->id == TypeTableEntryIdEnum) {10023 if (wanted_type->id == TypeTableEntryIdEnum) {
10019 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);10024 IrInstruction *cast1 = ir_analyze_cast(ira, source_instr, wanted_type->data.enumeration.tag_int_type, value);
10020 if (type_is_invalid(cast1->value.type))10025 if (type_is_invalid(cast1->value.type))
...@@ -12766,6 +12771,10 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op...@@ -12766,6 +12771,10 @@ static TypeTableEntry *ir_analyze_maybe(IrAnalyze *ira, IrInstructionUnOp *un_op
12766 TypeTableEntry *type_entry = ir_resolve_type(ira, value);12771 TypeTableEntry *type_entry = ir_resolve_type(ira, value);
12767 if (type_is_invalid(type_entry))12772 if (type_is_invalid(type_entry))
12768 return ira->codegen->builtin_types.entry_invalid;12773 return ira->codegen->builtin_types.entry_invalid;
12774 ensure_complete_type(ira->codegen, type_entry);
12775 if (type_is_invalid(type_entry))
12776 return ira->codegen->builtin_types.entry_invalid;
12777
12769 switch (type_entry->id) {12778 switch (type_entry->id) {
12770 case TypeTableEntryIdInvalid:12779 case TypeTableEntryIdInvalid:
12771 zig_unreachable();12780 zig_unreachable();
...@@ -13187,6 +13196,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc...@@ -13187,6 +13196,9 @@ static TypeTableEntry *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruc
1318713196
13188 bool safety_check_on = elem_ptr_instruction->safety_check_on;13197 bool safety_check_on = elem_ptr_instruction->safety_check_on;
13189 ensure_complete_type(ira->codegen, return_type->data.pointer.child_type);13198 ensure_complete_type(ira->codegen, return_type->data.pointer.child_type);
13199 if (type_is_invalid(return_type->data.pointer.child_type))
13200 return ira->codegen->builtin_types.entry_invalid;
13201
13190 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);13202 uint64_t elem_size = type_size(ira->codegen, return_type->data.pointer.child_type);
13191 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);13203 uint64_t abi_align = get_abi_alignment(ira->codegen, return_type->data.pointer.child_type);
13192 uint64_t ptr_align = return_type->data.pointer.alignment;13204 uint64_t ptr_align = return_type->data.pointer.alignment;
...@@ -13696,7 +13708,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru...@@ -13696,7 +13708,7 @@ static TypeTableEntry *ir_analyze_instruction_field_ptr(IrAnalyze *ira, IrInstru
13696 }13708 }
13697 if (child_type->id == TypeTableEntryIdEnum) {13709 if (child_type->id == TypeTableEntryIdEnum) {
13698 ensure_complete_type(ira->codegen, child_type);13710 ensure_complete_type(ira->codegen, child_type);
13699 if (child_type->data.enumeration.is_invalid)13711 if (type_is_invalid(child_type))
13700 return ira->codegen->builtin_types.entry_invalid;13712 return ira->codegen->builtin_types.entry_invalid;
1370113713
13702 TypeEnumField *field = find_enum_type_field(child_type, field_name);13714 TypeEnumField *field = find_enum_type_field(child_type, field_name);
...@@ -14569,27 +14581,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,...@@ -14569,27 +14581,27 @@ static TypeTableEntry *ir_analyze_instruction_unwrap_maybe(IrAnalyze *ira,
14569 return ira->codegen->builtin_types.entry_invalid;14581 return ira->codegen->builtin_types.entry_invalid;
1457014582
14571 TypeTableEntry *ptr_type = value->value.type;14583 TypeTableEntry *ptr_type = value->value.type;
14572 if (ptr_type->id == TypeTableEntryIdMetaType) {14584 assert(ptr_type->id == TypeTableEntryIdPointer);
14585
14586 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
14587 if (type_is_invalid(type_entry)) {
14588 return ira->codegen->builtin_types.entry_invalid;
14589 } else if (type_entry->id == TypeTableEntryIdMetaType) {
14573 // surprise! actually this is just ??T not an unwrap maybe instruction14590 // surprise! actually this is just ??T not an unwrap maybe instruction
14574 TypeTableEntry *ptr_type_ptr = ir_resolve_type(ira, value);14591 ConstExprValue *ptr_val = const_ptr_pointee(ira->codegen, &value->value);
14575 assert(ptr_type_ptr->id == TypeTableEntryIdPointer);14592 assert(ptr_val->type->id == TypeTableEntryIdMetaType);
14576 TypeTableEntry *child_type = ptr_type_ptr->data.pointer.child_type;14593 TypeTableEntry *child_type = ptr_val->data.x_type;
14594
14577 type_ensure_zero_bits_known(ira->codegen, child_type);14595 type_ensure_zero_bits_known(ira->codegen, child_type);
14578 TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type);14596 TypeTableEntry *layer1 = get_maybe_type(ira->codegen, child_type);
14579 TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1);14597 TypeTableEntry *layer2 = get_maybe_type(ira->codegen, layer1);
14580 TypeTableEntry *result_type = get_pointer_to_type(ira->codegen, layer2, true);
1458114598
14582 IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope,14599 IrInstruction *const_instr = ir_build_const_type(&ira->new_irb, unwrap_maybe_instruction->base.scope,
14583 unwrap_maybe_instruction->base.source_node, result_type);14600 unwrap_maybe_instruction->base.source_node, layer2);
14584 ir_link_new_instruction(const_instr, &unwrap_maybe_instruction->base);14601 IrInstruction *result_instr = ir_get_ref(ira, &unwrap_maybe_instruction->base, const_instr,
14585 return const_instr->value.type;14602 ptr_type->data.pointer.is_const, ptr_type->data.pointer.is_volatile);
14586 }14603 ir_link_new_instruction(result_instr, &unwrap_maybe_instruction->base);
1458714604 return result_instr->value.type;
14588 assert(ptr_type->id == TypeTableEntryIdPointer);
14589
14590 TypeTableEntry *type_entry = ptr_type->data.pointer.child_type;
14591 if (type_is_invalid(type_entry)) {
14592 return ira->codegen->builtin_types.entry_invalid;
14593 } else if (type_entry->id != TypeTableEntryIdMaybe) {14605 } else if (type_entry->id != TypeTableEntryIdMaybe) {
14594 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,14606 ir_add_error_node(ira, unwrap_maybe_instruction->value->source_node,
14595 buf_sprintf("expected nullable type, found '%s'", buf_ptr(&type_entry->name)));14607 buf_sprintf("expected nullable type, found '%s'", buf_ptr(&type_entry->name)));
...@@ -15115,6 +15127,8 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir...@@ -15115,6 +15127,8 @@ static TypeTableEntry *ir_analyze_container_init_fields_union(IrAnalyze *ira, Ir
15115 assert(container_type->id == TypeTableEntryIdUnion);15127 assert(container_type->id == TypeTableEntryIdUnion);
1511615128
15117 ensure_complete_type(ira->codegen, container_type);15129 ensure_complete_type(ira->codegen, container_type);
15130 if (type_is_invalid(container_type))
15131 return ira->codegen->builtin_types.entry_invalid;
1511815132
15119 if (instr_field_count != 1) {15133 if (instr_field_count != 1) {
15120 ir_add_error(ira, instruction,15134 ir_add_error(ira, instruction,
...@@ -15182,6 +15196,8 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru...@@ -15182,6 +15196,8 @@ static TypeTableEntry *ir_analyze_container_init_fields(IrAnalyze *ira, IrInstru
15182 }15196 }
1518315197
15184 ensure_complete_type(ira->codegen, container_type);15198 ensure_complete_type(ira->codegen, container_type);
15199 if (type_is_invalid(container_type))
15200 return ira->codegen->builtin_types.entry_invalid;
1518515201
15186 size_t actual_field_count = container_type->data.structure.src_field_count;15202 size_t actual_field_count = container_type->data.structure.src_field_count;
1518715203
...@@ -15687,6 +15703,8 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,...@@ -15687,6 +15703,8 @@ static TypeTableEntry *ir_analyze_instruction_offset_of(IrAnalyze *ira,
15687 return ira->codegen->builtin_types.entry_invalid;15703 return ira->codegen->builtin_types.entry_invalid;
1568815704
15689 ensure_complete_type(ira->codegen, container_type);15705 ensure_complete_type(ira->codegen, container_type);
15706 if (type_is_invalid(container_type))
15707 return ira->codegen->builtin_types.entry_invalid;
1569015708
15691 IrInstruction *field_name_value = instruction->field_name->other;15709 IrInstruction *field_name_value = instruction->field_name->other;
15692 Buf *field_name = ir_resolve_str(ira, field_name_value);15710 Buf *field_name = ir_resolve_str(ira, field_name_value);
...@@ -15740,6 +15758,9 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na...@@ -15740,6 +15758,9 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
15740 assert(type_info_var->type->id == TypeTableEntryIdMetaType);15758 assert(type_info_var->type->id == TypeTableEntryIdMetaType);
1574115759
15742 ensure_complete_type(ira->codegen, type_info_var->data.x_type);15760 ensure_complete_type(ira->codegen, type_info_var->data.x_type);
15761 if (type_is_invalid(type_info_var->data.x_type))
15762 return ira->codegen->builtin_types.entry_invalid;
15763
15743 type_info_type = type_info_var->data.x_type;15764 type_info_type = type_info_var->data.x_type;
15744 assert(type_info_type->id == TypeTableEntryIdUnion);15765 assert(type_info_type->id == TypeTableEntryIdUnion);
15745 }15766 }
...@@ -15765,26 +15786,37 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na...@@ -15765,26 +15786,37 @@ static TypeTableEntry *ir_type_info_get_type(IrAnalyze *ira, const char *type_na
15765 VariableTableEntry *var = tld->var;15786 VariableTableEntry *var = tld->var;
1576615787
15767 ensure_complete_type(ira->codegen, var->value->type);15788 ensure_complete_type(ira->codegen, var->value->type);
15789 if (type_is_invalid(var->value->type))
15790 return ira->codegen->builtin_types.entry_invalid;
15768 assert(var->value->type->id == TypeTableEntryIdMetaType);15791 assert(var->value->type->id == TypeTableEntryIdMetaType);
15769 return var->value->data.x_type;15792 return var->value->data.x_type;
15770}15793}
1577115794
15772static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope)15795static bool ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, ScopeDecls *decls_scope)
15773{15796{
15774 TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition");15797 TypeTableEntry *type_info_definition_type = ir_type_info_get_type(ira, "Definition");
15775 ensure_complete_type(ira->codegen, type_info_definition_type);15798 ensure_complete_type(ira->codegen, type_info_definition_type);
15799 if (type_is_invalid(type_info_definition_type))
15800 return false;
15801
15776 ensure_field_index(type_info_definition_type, "name", 0);15802 ensure_field_index(type_info_definition_type, "name", 0);
15777 ensure_field_index(type_info_definition_type, "is_pub", 1);15803 ensure_field_index(type_info_definition_type, "is_pub", 1);
15778 ensure_field_index(type_info_definition_type, "data", 2);15804 ensure_field_index(type_info_definition_type, "data", 2);
1577915805
15780 TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);15806 TypeTableEntry *type_info_definition_data_type = ir_type_info_get_type(ira, "Data", type_info_definition_type);
15781 ensure_complete_type(ira->codegen, type_info_definition_data_type);15807 ensure_complete_type(ira->codegen, type_info_definition_data_type);
15808 if (type_is_invalid(type_info_definition_data_type))
15809 return false;
1578215810
15783 TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);15811 TypeTableEntry *type_info_fn_def_type = ir_type_info_get_type(ira, "FnDef", type_info_definition_data_type);
15784 ensure_complete_type(ira->codegen, type_info_fn_def_type);15812 ensure_complete_type(ira->codegen, type_info_fn_def_type);
15813 if (type_is_invalid(type_info_fn_def_type))
15814 return false;
1578515815
15786 TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);15816 TypeTableEntry *type_info_fn_def_inline_type = ir_type_info_get_type(ira, "Inline", type_info_fn_def_type);
15787 ensure_complete_type(ira->codegen, type_info_fn_def_inline_type);15817 ensure_complete_type(ira->codegen, type_info_fn_def_inline_type);
15818 if (type_is_invalid(type_info_fn_def_inline_type))
15819 return false;
1578815820
15789 // Loop through our definitions once to figure out how many definitions we will generate info for.15821 // Loop through our definitions once to figure out how many definitions we will generate info for.
15790 auto decl_it = decls_scope->decl_table.entry_iterator();15822 auto decl_it = decls_scope->decl_table.entry_iterator();
...@@ -15799,7 +15831,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -15799,7 +15831,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
15799 resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node);15831 resolve_top_level_decl(ira->codegen, curr_entry->value, false, curr_entry->value->source_node);
15800 if (curr_entry->value->resolution != TldResolutionOk)15832 if (curr_entry->value->resolution != TldResolutionOk)
15801 {15833 {
15802 return;15834 return false;
15803 }15835 }
15804 }15836 }
1580515837
...@@ -15864,6 +15896,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -15864,6 +15896,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
15864 {15896 {
15865 VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;15897 VariableTableEntry *var = ((TldVar *)curr_entry->value)->var;
15866 ensure_complete_type(ira->codegen, var->value->type);15898 ensure_complete_type(ira->codegen, var->value->type);
15899 if (type_is_invalid(var->value->type))
15900 return false;
15901
15867 if (var->value->type->id == TypeTableEntryIdMetaType)15902 if (var->value->type->id == TypeTableEntryIdMetaType)
15868 {15903 {
15869 // We have a variable of type 'type', so it's actually a type definition.15904 // We have a variable of type 'type', so it's actually a type definition.
...@@ -15991,6 +16026,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -15991,6 +16026,9 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
15991 {16026 {
15992 TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry;16027 TypeTableEntry *type_entry = ((TldContainer *)curr_entry->value)->type_entry;
15993 ensure_complete_type(ira->codegen, type_entry);16028 ensure_complete_type(ira->codegen, type_entry);
16029 if (type_is_invalid(type_entry))
16030 return false;
16031
15994 // This is a type.16032 // This is a type.
15995 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);16033 bigint_init_unsigned(&inner_fields[2].data.x_union.tag, 0);
1599616034
...@@ -16011,6 +16049,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop...@@ -16011,6 +16049,7 @@ static void ir_make_type_info_defs(IrAnalyze *ira, ConstExprValue *out_val, Scop
16011 }16049 }
1601216050
16013 assert(definition_index == definition_count);16051 assert(definition_index == definition_count);
16052 return true;
16014}16053}
1601516054
16016static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry)16055static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *type_entry)
...@@ -16019,6 +16058,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16019,6 +16058,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16019 assert(!type_is_invalid(type_entry));16058 assert(!type_is_invalid(type_entry));
1602016059
16021 ensure_complete_type(ira->codegen, type_entry);16060 ensure_complete_type(ira->codegen, type_entry);
16061 if (type_is_invalid(type_entry))
16062 return nullptr;
1602216063
16023 const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field,16064 const auto make_enum_field_val = [ira](ConstExprValue *enum_field_val, TypeEnumField *enum_field,
16024 TypeTableEntry *type_info_enum_field_type) {16065 TypeTableEntry *type_info_enum_field_type) {
...@@ -16246,7 +16287,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16246,7 +16287,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16246 }16287 }
16247 // defs: []TypeInfo.Definition16288 // defs: []TypeInfo.Definition
16248 ensure_field_index(result->type, "defs", 3);16289 ensure_field_index(result->type, "defs", 3);
16249 ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope);16290 if (!ir_make_type_info_defs(ira, &fields[3], type_entry->data.enumeration.decls_scope))
16291 return nullptr;
1625016292
16251 break;16293 break;
16252 }16294 }
...@@ -16401,7 +16443,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16401,7 +16443,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16401 }16443 }
16402 // defs: []TypeInfo.Definition16444 // defs: []TypeInfo.Definition
16403 ensure_field_index(result->type, "defs", 3);16445 ensure_field_index(result->type, "defs", 3);
16404 ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope);16446 if (!ir_make_type_info_defs(ira, &fields[3], type_entry->data.unionation.decls_scope))
16447 return nullptr;
1640516448
16406 break;16449 break;
16407 }16450 }
...@@ -16412,6 +16455,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16412,6 +16455,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16412 buf_init_from_str(&ptr_field_name, "ptr");16455 buf_init_from_str(&ptr_field_name, "ptr");
16413 TypeTableEntry *ptr_type = type_entry->data.structure.fields_by_name.get(&ptr_field_name)->type_entry;16456 TypeTableEntry *ptr_type = type_entry->data.structure.fields_by_name.get(&ptr_field_name)->type_entry;
16414 ensure_complete_type(ira->codegen, ptr_type);16457 ensure_complete_type(ira->codegen, ptr_type);
16458 if (type_is_invalid(ptr_type))
16459 return nullptr;
16415 buf_deinit(&ptr_field_name);16460 buf_deinit(&ptr_field_name);
1641616461
16417 result = create_ptr_like_type_info("Slice", ptr_type);16462 result = create_ptr_like_type_info("Slice", ptr_type);
...@@ -16482,7 +16527,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t...@@ -16482,7 +16527,8 @@ static ConstExprValue *ir_make_type_info_value(IrAnalyze *ira, TypeTableEntry *t
16482 }16527 }
16483 // defs: []TypeInfo.Definition16528 // defs: []TypeInfo.Definition
16484 ensure_field_index(result->type, "defs", 2);16529 ensure_field_index(result->type, "defs", 2);
16485 ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope);16530 if (!ir_make_type_info_defs(ira, &fields[2], type_entry->data.structure.decls_scope))
16531 return nullptr;
1648616532
16487 break;16533 break;
16488 }16534 }
...@@ -17502,6 +17548,11 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst...@@ -17502,6 +17548,11 @@ static TypeTableEntry *ir_analyze_instruction_member_type(IrAnalyze *ira, IrInst
17502 if (type_is_invalid(container_type))17548 if (type_is_invalid(container_type))
17503 return ira->codegen->builtin_types.entry_invalid;17549 return ira->codegen->builtin_types.entry_invalid;
1750417550
17551 ensure_complete_type(ira->codegen, container_type);
17552 if (type_is_invalid(container_type))
17553 return ira->codegen->builtin_types.entry_invalid;
17554
17555
17505 uint64_t member_index;17556 uint64_t member_index;
17506 IrInstruction *index_value = instruction->member_index->other;17557 IrInstruction *index_value = instruction->member_index->other;
17507 if (!ir_resolve_usize(ira, index_value, &member_index))17558 if (!ir_resolve_usize(ira, index_value, &member_index))
...@@ -17544,6 +17595,10 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst...@@ -17544,6 +17595,10 @@ static TypeTableEntry *ir_analyze_instruction_member_name(IrAnalyze *ira, IrInst
17544 if (type_is_invalid(container_type))17595 if (type_is_invalid(container_type))
17545 return ira->codegen->builtin_types.entry_invalid;17596 return ira->codegen->builtin_types.entry_invalid;
1754617597
17598 ensure_complete_type(ira->codegen, container_type);
17599 if (type_is_invalid(container_type))
17600 return ira->codegen->builtin_types.entry_invalid;
17601
17547 uint64_t member_index;17602 uint64_t member_index;
17548 IrInstruction *index_value = instruction->member_index->other;17603 IrInstruction *index_value = instruction->member_index->other;
17549 if (!ir_resolve_usize(ira, index_value, &member_index))17604 if (!ir_resolve_usize(ira, index_value, &member_index))
...@@ -18485,7 +18540,12 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc...@@ -18485,7 +18540,12 @@ static TypeTableEntry *ir_analyze_instruction_bit_cast(IrAnalyze *ira, IrInstruc
18485 return ira->codegen->builtin_types.entry_invalid;18540 return ira->codegen->builtin_types.entry_invalid;
1848618541
18487 ensure_complete_type(ira->codegen, dest_type);18542 ensure_complete_type(ira->codegen, dest_type);
18543 if (type_is_invalid(dest_type))
18544 return ira->codegen->builtin_types.entry_invalid;
18545
18488 ensure_complete_type(ira->codegen, src_type);18546 ensure_complete_type(ira->codegen, src_type);
18547 if (type_is_invalid(src_type))
18548 return ira->codegen->builtin_types.entry_invalid;
1848918549
18490 if (get_codegen_ptr_type(src_type) != nullptr) {18550 if (get_codegen_ptr_type(src_type) != nullptr) {
18491 ir_add_error(ira, value,18551 ir_add_error(ira, value,
...@@ -18724,6 +18784,9 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc...@@ -18724,6 +18784,9 @@ static TypeTableEntry *ir_analyze_instruction_ptr_type(IrAnalyze *ira, IrInstruc
18724 if (!ir_resolve_align(ira, instruction->align_value->other, &align_bytes))18784 if (!ir_resolve_align(ira, instruction->align_value->other, &align_bytes))
18725 return ira->codegen->builtin_types.entry_invalid;18785 return ira->codegen->builtin_types.entry_invalid;
18726 } else {18786 } else {
18787 type_ensure_zero_bits_known(ira->codegen, child_type);
18788 if (type_is_invalid(child_type))
18789 return ira->codegen->builtin_types.entry_invalid;
18727 align_bytes = get_abi_alignment(ira->codegen, child_type);18790 align_bytes = get_abi_alignment(ira->codegen, child_type);
18728 }18791 }
1872918792
test/compile_errors.zig+1-1
...@@ -3232,7 +3232,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {...@@ -3232,7 +3232,7 @@ pub fn addCases(cases: *tests.CompileErrorContext) void {
3232 \\ fn bar(self: *const Foo) void {}3232 \\ fn bar(self: *const Foo) void {}
3233 \\};3233 \\};
3234 ,3234 ,
3235 ".tmp_source.zig:4:4: error: variable of type '*const (integer literal)' must be const or comptime",3235 ".tmp_source.zig:4:4: error: variable of type '*(integer literal)' must be const or comptime",
3236 ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime",3236 ".tmp_source.zig:7:4: error: variable of type '(undefined)' must be const or comptime",
3237 ".tmp_source.zig:8:4: error: variable of type '(integer literal)' must be const or comptime",3237 ".tmp_source.zig:8:4: error: variable of type '(integer literal)' must be const or comptime",
3238 ".tmp_source.zig:9:4: error: variable of type '(float literal)' must be const or comptime",3238 ".tmp_source.zig:9:4: error: variable of type '(float literal)' must be const or comptime",
test/gen_h.zig+2-2
...@@ -54,7 +54,7 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -54,7 +54,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
54 cases.add("declare opaque type",54 cases.add("declare opaque type",
55 \\export const Foo = @OpaqueType();55 \\export const Foo = @OpaqueType();
56 \\56 \\
57 \\export fn entry(foo: ?&Foo) void { }57 \\export fn entry(foo: ?*Foo) void { }
58 ,58 ,
59 \\struct Foo;59 \\struct Foo;
60 \\60 \\
...@@ -64,7 +64,7 @@ pub fn addCases(cases: *tests.GenHContext) void {...@@ -64,7 +64,7 @@ pub fn addCases(cases: *tests.GenHContext) void {
64 cases.add("array field-type",64 cases.add("array field-type",
65 \\const Foo = extern struct {65 \\const Foo = extern struct {
66 \\ A: [2]i32,66 \\ A: [2]i32,
67 \\ B: [4]&u32,67 \\ B: [4]*u32,
68 \\};68 \\};
69 \\export fn entry(foo: Foo, bar: [3]u8) void { }69 \\export fn entry(foo: Foo, bar: [3]u8) void { }
70 ,70 ,
test/runtime_safety.zig+23-23
...@@ -2,7 +2,7 @@ const tests = @import("tests.zig");...@@ -2,7 +2,7 @@ const tests = @import("tests.zig");
22
3pub fn addCases(cases: *tests.CompareOutputContext) void {3pub fn addCases(cases: *tests.CompareOutputContext) void {
4 cases.addRuntimeSafety("calling panic",4 cases.addRuntimeSafety("calling panic",
5 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {5 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
6 \\ @import("std").os.exit(126);6 \\ @import("std").os.exit(126);
7 \\}7 \\}
8 \\pub fn main() void {8 \\pub fn main() void {
...@@ -11,7 +11,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -11,7 +11,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
11 );11 );
1212
13 cases.addRuntimeSafety("out of bounds slice access",13 cases.addRuntimeSafety("out of bounds slice access",
14 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {14 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
15 \\ @import("std").os.exit(126);15 \\ @import("std").os.exit(126);
16 \\}16 \\}
17 \\pub fn main() void {17 \\pub fn main() void {
...@@ -25,7 +25,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -25,7 +25,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
25 );25 );
2626
27 cases.addRuntimeSafety("integer addition overflow",27 cases.addRuntimeSafety("integer addition overflow",
28 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {28 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
29 \\ @import("std").os.exit(126);29 \\ @import("std").os.exit(126);
30 \\}30 \\}
31 \\pub fn main() !void {31 \\pub fn main() !void {
...@@ -38,7 +38,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -38,7 +38,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
38 );38 );
3939
40 cases.addRuntimeSafety("integer subtraction overflow",40 cases.addRuntimeSafety("integer subtraction overflow",
41 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {41 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
42 \\ @import("std").os.exit(126);42 \\ @import("std").os.exit(126);
43 \\}43 \\}
44 \\pub fn main() !void {44 \\pub fn main() !void {
...@@ -51,7 +51,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -51,7 +51,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
51 );51 );
5252
53 cases.addRuntimeSafety("integer multiplication overflow",53 cases.addRuntimeSafety("integer multiplication overflow",
54 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {54 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
55 \\ @import("std").os.exit(126);55 \\ @import("std").os.exit(126);
56 \\}56 \\}
57 \\pub fn main() !void {57 \\pub fn main() !void {
...@@ -64,7 +64,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -64,7 +64,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
64 );64 );
6565
66 cases.addRuntimeSafety("integer negation overflow",66 cases.addRuntimeSafety("integer negation overflow",
67 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {67 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
68 \\ @import("std").os.exit(126);68 \\ @import("std").os.exit(126);
69 \\}69 \\}
70 \\pub fn main() !void {70 \\pub fn main() !void {
...@@ -77,7 +77,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -77,7 +77,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
77 );77 );
7878
79 cases.addRuntimeSafety("signed integer division overflow",79 cases.addRuntimeSafety("signed integer division overflow",
80 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {80 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
81 \\ @import("std").os.exit(126);81 \\ @import("std").os.exit(126);
82 \\}82 \\}
83 \\pub fn main() !void {83 \\pub fn main() !void {
...@@ -90,7 +90,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -90,7 +90,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
90 );90 );
9191
92 cases.addRuntimeSafety("signed shift left overflow",92 cases.addRuntimeSafety("signed shift left overflow",
93 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {93 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
94 \\ @import("std").os.exit(126);94 \\ @import("std").os.exit(126);
95 \\}95 \\}
96 \\pub fn main() !void {96 \\pub fn main() !void {
...@@ -103,7 +103,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -103,7 +103,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
103 );103 );
104104
105 cases.addRuntimeSafety("unsigned shift left overflow",105 cases.addRuntimeSafety("unsigned shift left overflow",
106 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {106 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
107 \\ @import("std").os.exit(126);107 \\ @import("std").os.exit(126);
108 \\}108 \\}
109 \\pub fn main() !void {109 \\pub fn main() !void {
...@@ -116,7 +116,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -116,7 +116,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
116 );116 );
117117
118 cases.addRuntimeSafety("signed shift right overflow",118 cases.addRuntimeSafety("signed shift right overflow",
119 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {119 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
120 \\ @import("std").os.exit(126);120 \\ @import("std").os.exit(126);
121 \\}121 \\}
122 \\pub fn main() !void {122 \\pub fn main() !void {
...@@ -129,7 +129,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -129,7 +129,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
129 );129 );
130130
131 cases.addRuntimeSafety("unsigned shift right overflow",131 cases.addRuntimeSafety("unsigned shift right overflow",
132 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {132 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
133 \\ @import("std").os.exit(126);133 \\ @import("std").os.exit(126);
134 \\}134 \\}
135 \\pub fn main() !void {135 \\pub fn main() !void {
...@@ -142,7 +142,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -142,7 +142,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
142 );142 );
143143
144 cases.addRuntimeSafety("integer division by zero",144 cases.addRuntimeSafety("integer division by zero",
145 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {145 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
146 \\ @import("std").os.exit(126);146 \\ @import("std").os.exit(126);
147 \\}147 \\}
148 \\pub fn main() void {148 \\pub fn main() void {
...@@ -154,7 +154,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -154,7 +154,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
154 );154 );
155155
156 cases.addRuntimeSafety("exact division failure",156 cases.addRuntimeSafety("exact division failure",
157 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {157 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
158 \\ @import("std").os.exit(126);158 \\ @import("std").os.exit(126);
159 \\}159 \\}
160 \\pub fn main() !void {160 \\pub fn main() !void {
...@@ -167,7 +167,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -167,7 +167,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
167 );167 );
168168
169 cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size",169 cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size",
170 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {170 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
171 \\ @import("std").os.exit(126);171 \\ @import("std").os.exit(126);
172 \\}172 \\}
173 \\pub fn main() !void {173 \\pub fn main() !void {
...@@ -180,7 +180,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -180,7 +180,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
180 );180 );
181181
182 cases.addRuntimeSafety("value does not fit in shortening cast",182 cases.addRuntimeSafety("value does not fit in shortening cast",
183 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {183 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
184 \\ @import("std").os.exit(126);184 \\ @import("std").os.exit(126);
185 \\}185 \\}
186 \\pub fn main() !void {186 \\pub fn main() !void {
...@@ -193,7 +193,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -193,7 +193,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
193 );193 );
194194
195 cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",195 cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",
196 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {196 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
197 \\ @import("std").os.exit(126);197 \\ @import("std").os.exit(126);
198 \\}198 \\}
199 \\pub fn main() !void {199 \\pub fn main() !void {
...@@ -206,7 +206,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -206,7 +206,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
206 );206 );
207207
208 cases.addRuntimeSafety("unwrap error",208 cases.addRuntimeSafety("unwrap error",
209 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {209 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
210 \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {210 \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
211 \\ @import("std").os.exit(126); // good211 \\ @import("std").os.exit(126); // good
212 \\ }212 \\ }
...@@ -221,7 +221,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -221,7 +221,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
221 );221 );
222222
223 cases.addRuntimeSafety("cast integer to global error and no code matches",223 cases.addRuntimeSafety("cast integer to global error and no code matches",
224 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {224 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
225 \\ @import("std").os.exit(126);225 \\ @import("std").os.exit(126);
226 \\}226 \\}
227 \\pub fn main() void {227 \\pub fn main() void {
...@@ -233,7 +233,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -233,7 +233,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
233 );233 );
234234
235 cases.addRuntimeSafety("cast integer to non-global error set and no match",235 cases.addRuntimeSafety("cast integer to non-global error set and no match",
236 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {236 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
237 \\ @import("std").os.exit(126);237 \\ @import("std").os.exit(126);
238 \\}238 \\}
239 \\const Set1 = error{A, B};239 \\const Set1 = error{A, B};
...@@ -247,7 +247,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -247,7 +247,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
247 );247 );
248248
249 cases.addRuntimeSafety("@alignCast misaligned",249 cases.addRuntimeSafety("@alignCast misaligned",
250 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {250 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
251 \\ @import("std").os.exit(126);251 \\ @import("std").os.exit(126);
252 \\}252 \\}
253 \\pub fn main() !void {253 \\pub fn main() !void {
...@@ -263,7 +263,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -263,7 +263,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
263 );263 );
264264
265 cases.addRuntimeSafety("bad union field access",265 cases.addRuntimeSafety("bad union field access",
266 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {266 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
267 \\ @import("std").os.exit(126);267 \\ @import("std").os.exit(126);
268 \\}268 \\}
269 \\269 \\
...@@ -277,7 +277,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -277,7 +277,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
277 \\ bar(&f);277 \\ bar(&f);
278 \\}278 \\}
279 \\279 \\
280 \\fn bar(f: &Foo) void {280 \\fn bar(f: *Foo) void {
281 \\ f.float = 12.34;281 \\ f.float = 12.34;
282 \\}282 \\}
283 );283 );
...@@ -287,7 +287,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {...@@ -287,7 +287,7 @@ pub fn addCases(cases: *tests.CompareOutputContext) void {
287 cases.addRuntimeSafety("error return trace across suspend points",287 cases.addRuntimeSafety("error return trace across suspend points",
288 \\const std = @import("std");288 \\const std = @import("std");
289 \\289 \\
290 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) noreturn {290 \\pub fn panic(message: []const u8, stack_trace: ?*@import("builtin").StackTrace) noreturn {
291 \\ std.os.exit(126);291 \\ std.os.exit(126);
292 \\}292 \\}
293 \\293 \\