fix declref not writing to result loc

```zig
const a: i32 = 0;
const b: i32 = 1;
const c: i32 = 2;
const d: i32 = 3;

export fn entry(x: bool) i32 {
    return if (x)
        if (x)
            a
        else if (x)
            b
        else
            c
    else
        d;
}
```
This commit is contained in:
Andrew Kelley 2019-06-12 19:43:24 -04:00
parent e6fa2ee706
commit 0d62c92947
No known key found for this signature in database
GPG Key ID: 7C5F548F728501A9
3 changed files with 10 additions and 6 deletions

View File

@ -10,5 +10,3 @@ get an empty file compiling successfully (with no panic fn override)
uncomment all the behavior tests
look at all the ir_gen_node ir_gen_node_extra calls and make sure result locations are properly propagated
return ir_gen_comptime(irb, scope, node, lval);

View File

@ -3247,8 +3247,8 @@ struct IrInstructionTypeName {
struct IrInstructionDeclRef {
IrInstruction base;
Tld *tld;
LVal lval;
Tld *tld;
};
struct IrInstructionPanic {

View File

@ -4166,8 +4166,14 @@ static IrInstruction *ir_gen_symbol(IrBuilder *irb, Scope *scope, AstNode *node,
}
Tld *tld = find_decl(irb->codegen, scope, variable_name);
if (tld)
return ir_build_decl_ref(irb, scope, node, tld, lval);
if (tld) {
IrInstruction *decl_ref = ir_build_decl_ref(irb, scope, node, tld, lval);
if (lval == LValPtr) {
return decl_ref;
} else {
return ir_expr_wrap(irb, scope, decl_ref, result_loc);
}
}
if (get_container_scope(node->owner)->any_imports_failed) {
// skip the error message since we had a failing import in this file
@ -16503,7 +16509,7 @@ static IrInstruction *ir_analyze_instruction_phi(IrAnalyze *ira, IrInstructionPh
IrInstruction *branch_instruction = predecessor->instruction_list.pop();
ir_set_cursor_at_end(&ira->new_irb, predecessor);
IrInstruction *casted_value = ir_implicit_cast(ira, new_value, resolved_type);
if (casted_value == ira->codegen->invalid_instruction) {
if (type_is_invalid(casted_value->value.type)) {
return ira->codegen->invalid_instruction;
}
new_incoming_values.items[i] = casted_value;