authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-11 01:24:55-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-06-11 01:24:55-04:00
loga431a73dabd205667c1226e4d265fca0d25e6356
tree9a79cf110fe7835f4984f5c5c2234f1924733b7d
parentb053a655734a35405f97818d1586d524f6b003b5
signature Commit is signed but in an unrecognized format.

fixes for crashes and compile errors


1 files changed, 54 insertions(+), 32 deletions(-)

src/ir.cpp+54-32
...@@ -3246,6 +3246,7 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s...@@ -3246,6 +3246,7 @@ static IrInstruction *ir_build_end_expr(IrBuilder *irb, Scope *scope, AstNode *s
3246 IrInstruction *value, ResultLoc *result_loc)3246 IrInstruction *value, ResultLoc *result_loc)
3247{3247{
3248 IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node);3248 IrInstructionEndExpr *instruction = ir_build_instruction<IrInstructionEndExpr>(irb, scope, source_node);
3249 instruction->base.is_gen = true;
3249 instruction->value = value;3250 instruction->value = value;
3250 instruction->result_loc = result_loc;3251 instruction->result_loc = result_loc;
32513252
...@@ -5487,8 +5488,10 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *...@@ -5487,8 +5488,10 @@ static IrInstruction *ir_lval_wrap(IrBuilder *irb, Scope *scope, IrInstruction *
5487 // We needed a pointer to a value, but we got a value. So we create5488 // We needed a pointer to a value, but we got a value. So we create
5488 // an instruction which just makes a pointer of it.5489 // an instruction which just makes a pointer of it.
5489 return ir_build_ref(irb, scope, value->source_node, value, false, false);5490 return ir_build_ref(irb, scope, value->source_node, value, false, false);
5490 } else {5491 } else if (result_loc != nullptr) {
5491 return ir_expr_wrap(irb, scope, value, result_loc);5492 return ir_expr_wrap(irb, scope, value, result_loc);
5493 } else {
5494 return value;
5492 }5495 }
54935496
5494}5497}
...@@ -5625,6 +5628,10 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -5625,6 +5628,10 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
5625{5628{
5626 assert(node->type == NodeTypeContainerInitExpr);5629 assert(node->type == NodeTypeContainerInitExpr);
56275630
5631 if (ir_should_inline(irb->exec, scope)) {
5632 result_loc = nullptr;
5633 }
5634
5628 AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr;5635 AstNodeContainerInitExpr *container_init_expr = &node->data.container_init_expr;
5629 ContainerInitKind kind = container_init_expr->kind;5636 ContainerInitKind kind = container_init_expr->kind;
56305637
...@@ -5648,12 +5655,15 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -5648,12 +5655,15 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
5648 return irb->codegen->invalid_instruction;5655 return irb->codegen->invalid_instruction;
5649 }5656 }
56505657
5651 src_assert(result_loc->scope_elide == nullptr, node);5658 IrInstruction *container_ptr = nullptr;
5652 result_loc->scope_elide = create_elide_scope(irb->codegen, node, scope);5659 if (result_loc != nullptr) {
5660 src_assert(result_loc->scope_elide == nullptr, node);
5661 result_loc->scope_elide = create_elide_scope(irb->codegen, node, scope);
56535662
5654 src_assert(result_loc != nullptr, node);5663 src_assert(result_loc != nullptr, node);
5655 IrInstruction *container_ptr = ir_build_resolve_result(irb, &result_loc->scope_elide->base,5664 container_ptr = ir_build_resolve_result(irb, &result_loc->scope_elide->base,
5656 node, result_loc, container_type);5665 node, result_loc, container_type);
5666 }
56575667
5658 size_t field_count = container_init_expr->entries.length;5668 size_t field_count = container_init_expr->entries.length;
5659 IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count);5669 IrInstructionContainerInitFieldsField *fields = allocate<IrInstructionContainerInitFieldsField>(field_count);
...@@ -5664,16 +5674,21 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -5664,16 +5674,21 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
5664 Buf *name = entry_node->data.struct_val_field.name;5674 Buf *name = entry_node->data.struct_val_field.name;
5665 AstNode *expr_node = entry_node->data.struct_val_field.expr;5675 AstNode *expr_node = entry_node->data.struct_val_field.expr;
56665676
5667 IrInstruction *field_ptr = ir_build_field_ptr(irb, &result_loc->scope_elide->base, expr_node,5677 Scope *val_scope = scope;
5668 container_ptr, name, true);5678 ResultLoc *child_result_loc = nullptr;
5669 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);5679 if (container_ptr != nullptr) {
5670 result_loc_inst->base.id = ResultLocIdInstruction;5680 IrInstruction *field_ptr = ir_build_field_ptr(irb, &result_loc->scope_elide->base, expr_node,
5671 result_loc_inst->base.source_instruction = field_ptr;5681 container_ptr, name, true);
5672 ir_ref_instruction(field_ptr, irb->current_basic_block);5682 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
5673 ResultLoc *child_result_loc = &result_loc_inst->base;5683 result_loc_inst->base.id = ResultLocIdInstruction;
5684 result_loc_inst->base.source_instruction = field_ptr;
5685 ir_ref_instruction(field_ptr, irb->current_basic_block);
5686 child_result_loc = &result_loc_inst->base;
5687 val_scope = &result_loc->scope_elide->base;
5688 }
56745689
5675 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, &result_loc->scope_elide->base,5690 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, val_scope, LValNone,
5676 LValNone, child_result_loc);5691 child_result_loc);
5677 if (expr_value == irb->codegen->invalid_instruction)5692 if (expr_value == irb->codegen->invalid_instruction)
5678 return expr_value;5693 return expr_value;
56795694
...@@ -5686,9 +5701,6 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -5686,9 +5701,6 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
5686 return ir_lval_wrap(irb, scope, init_fields, lval, result_loc);5701 return ir_lval_wrap(irb, scope, init_fields, lval, result_loc);
5687 }5702 }
5688 case ContainerInitKindArray: {5703 case ContainerInitKindArray: {
5689 src_assert(result_loc->scope_elide == nullptr, node);
5690 result_loc->scope_elide = create_elide_scope(irb->codegen, node, scope);
5691
5692 size_t item_count = container_init_expr->entries.length;5704 size_t item_count = container_init_expr->entries.length;
56935705
5694 if (container_type == nullptr) {5706 if (container_type == nullptr) {
...@@ -5696,25 +5708,35 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A...@@ -5696,25 +5708,35 @@ static IrInstruction *ir_gen_container_init_expr(IrBuilder *irb, Scope *scope, A
5696 container_type = ir_build_array_type(irb, scope, node, item_count_inst, elem_type);5708 container_type = ir_build_array_type(irb, scope, node, item_count_inst, elem_type);
5697 }5709 }
56985710
5699 src_assert(result_loc != nullptr, node);5711 IrInstruction *container_ptr = nullptr;
5700 IrInstruction *container_ptr = ir_build_resolve_result(irb, &result_loc->scope_elide->base,5712 if (result_loc != nullptr) {
5701 node, result_loc, container_type);5713 src_assert(result_loc->scope_elide == nullptr, node);
5714 result_loc->scope_elide = create_elide_scope(irb->codegen, node, scope);
5715
5716 container_ptr = ir_build_resolve_result(irb, &result_loc->scope_elide->base,
5717 node, result_loc, container_type);
5718 }
57025719
5703 IrInstruction **values = allocate<IrInstruction *>(item_count);5720 IrInstruction **values = allocate<IrInstruction *>(item_count);
5704 for (size_t i = 0; i < item_count; i += 1) {5721 for (size_t i = 0; i < item_count; i += 1) {
5705 AstNode *expr_node = container_init_expr->entries.at(i);5722 AstNode *expr_node = container_init_expr->entries.at(i);
57065723
5707 IrInstruction *elem_index = ir_build_const_usize(irb, &result_loc->scope_elide->base, expr_node, i);5724 ResultLoc *child_result_loc = nullptr;
5708 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, &result_loc->scope_elide->base, expr_node,5725 Scope *val_scope = scope;
5709 container_ptr, elem_index, false, PtrLenSingle);5726 if (container_ptr != nullptr) {
5710 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);5727 IrInstruction *elem_index = ir_build_const_usize(irb, &result_loc->scope_elide->base, expr_node, i);
5711 result_loc_inst->base.id = ResultLocIdInstruction;5728 IrInstruction *elem_ptr = ir_build_elem_ptr(irb, &result_loc->scope_elide->base, expr_node,
5712 result_loc_inst->base.source_instruction = elem_ptr;5729 container_ptr, elem_index, false, PtrLenSingle);
5713 ir_ref_instruction(elem_ptr, irb->current_basic_block);5730 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
5714 ResultLoc *child_result_loc = &result_loc_inst->base;5731 result_loc_inst->base.id = ResultLocIdInstruction;
57155732 result_loc_inst->base.source_instruction = elem_ptr;
5716 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, &result_loc->scope_elide->base,5733 ir_ref_instruction(elem_ptr, irb->current_basic_block);
5717 LValNone, child_result_loc);5734 child_result_loc = &result_loc_inst->base;
5735 val_scope = &result_loc->scope_elide->base;
5736 }
5737
5738 IrInstruction *expr_value = ir_gen_node_extra(irb, expr_node, val_scope, LValNone,
5739 child_result_loc);
5718 if (expr_value == irb->codegen->invalid_instruction)5740 if (expr_value == irb->codegen->invalid_instruction)
5719 return expr_value;5741 return expr_value;
57205742