authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-02 13:54:58-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-08-02 13:54:58-04:00
loga5cb0f77d11bdcc504fe3e6afa928c88de821518
treea110d7eead2bb71bca56154114c5ff9bd4dfaa5e
parent6cb4cac5cd1c68f41c62a3c23b09513988337c8d
signaturelock-open Commit is signed but in an unrecognized format.

assignment participates in result location

fix one regression with optionals but there are more

2 files changed, 25 insertions(+), 6 deletions(-)

src/ir.cpp+15-6
......@@ -4001,12 +4001,20 @@ static IrInstruction *ir_gen_bin_op_id(IrBuilder *irb, Scope *scope, AstNode *no
40014001
40024002static IrInstruction *ir_gen_assign(IrBuilder *irb, Scope *scope, AstNode *node) {
40034003 IrInstruction *lvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op1, scope, LValPtr, nullptr);
4004 IrInstruction *rvalue = ir_gen_node(irb, node->data.bin_op_expr.op2, scope);
4004 if (lvalue == irb->codegen->invalid_instruction)
4005 return irb->codegen->invalid_instruction;
40054006
4006 if (lvalue == irb->codegen->invalid_instruction || rvalue == irb->codegen->invalid_instruction)
4007 ResultLocInstruction *result_loc_inst = allocate<ResultLocInstruction>(1);
4008 result_loc_inst->base.id = ResultLocIdInstruction;
4009 result_loc_inst->base.source_instruction = lvalue;
4010 ir_ref_instruction(lvalue, irb->current_basic_block);
4011 ir_build_reset_result(irb, scope, node, &result_loc_inst->base);
4012
4013 IrInstruction *rvalue = ir_gen_node_extra(irb, node->data.bin_op_expr.op2, scope, LValNone,
4014 &result_loc_inst->base);
4015 if (rvalue == irb->codegen->invalid_instruction)
40074016 return irb->codegen->invalid_instruction;
40084017
4009 ir_build_store_ptr(irb, scope, node, lvalue, rvalue);
40104018 return ir_build_const_void(irb, scope, node);
40114019}
40124020
......@@ -17477,6 +17485,7 @@ static IrInstruction *ir_analyze_instruction_elem_ptr(IrAnalyze *ira, IrInstruct
1747717485 return result;
1747817486 } else if (is_slice(array_type)) {
1747917487 ConstExprValue *ptr_field = &array_ptr_val->data.x_struct.fields[slice_ptr_index];
17488 ir_assert(ptr_field != nullptr, &elem_ptr_instruction->base);
1748017489 if (ptr_field->data.x_ptr.special == ConstPtrSpecialHardCodedAddr) {
1748117490 IrInstruction *result = ir_build_elem_ptr(&ira->new_irb, elem_ptr_instruction->base.scope,
1748217491 elem_ptr_instruction->base.source_node, array_ptr, casted_elem_index, false,
......@@ -17663,7 +17672,7 @@ static IrInstruction *ir_analyze_struct_field_ptr(IrAnalyze *ira, IrInstruction
1766317672 return ira->codegen->invalid_instruction;
1766417673 if (type_is_invalid(struct_val->type))
1766517674 return ira->codegen->invalid_instruction;
17666 if (struct_val->special == ConstValSpecialUndef && initializing) {
17675 if (initializing && struct_val->special == ConstValSpecialUndef) {
1766717676 struct_val->data.x_struct.fields = create_const_vals(struct_type->data.structure.src_field_count);
1766817677 struct_val->special = ConstValSpecialStatic;
1766917678 for (size_t i = 0; i < struct_type->data.structure.src_field_count; i += 1) {
......@@ -18764,7 +18773,7 @@ static IrInstruction *ir_analyze_unwrap_optional_payload(IrAnalyze *ira, IrInstr
1876418773 if (optional_val == nullptr)
1876518774 return ira->codegen->invalid_instruction;
1876618775
18767 if (initializing && optional_val->special == ConstValSpecialUndef) {
18776 if (initializing) {
1876818777 switch (type_has_one_possible_value(ira->codegen, child_type)) {
1876918778 case OnePossibleValueInvalid:
1877018779 return ira->codegen->invalid_instruction;
......@@ -23260,7 +23269,7 @@ static IrInstruction *ir_analyze_unwrap_error_payload(IrAnalyze *ira, IrInstruct
2326023269 ConstExprValue *err_union_val = const_ptr_pointee(ira, ira->codegen, ptr_val, source_instr->source_node);
2326123270 if (err_union_val == nullptr)
2326223271 return ira->codegen->invalid_instruction;
23263 if (err_union_val->special == ConstValSpecialUndef && initializing) {
23272 if (initializing && err_union_val->special == ConstValSpecialUndef) {
2326423273 ConstExprValue *vals = create_const_vals(2);
2326523274 ConstExprValue *err_set_val = &vals[0];
2326623275 ConstExprValue *payload_val = &vals[1];
test/stage1/behavior/eval.zig+10
......@@ -1,5 +1,6 @@
11const std = @import("std");
22const expect = std.testing.expect;
3const expectEqual = std.testing.expectEqual;
34const builtin = @import("builtin");
45
56test "compile time recursion" {
......@@ -794,3 +795,12 @@ test "no undeclared identifier error in unanalyzed branches" {
794795 lol_this_doesnt_exist = nonsense;
795796 }
796797}
798
799test "comptime assign int to optional int" {
800 comptime {
801 var x: ?i32 = null;
802 x = 2;
803 x.? *= 10;
804 expectEqual(20, x.?);
805 }
806}