diff options
| author | Andrew Kelley <superjoe30@gmail.com> | 2017-05-02 12:59:09 -0400 |
|---|---|---|
| committer | Andrew Kelley <superjoe30@gmail.com> | 2017-05-02 12:59:09 -0400 |
| commit | 7c236f6dd8194500f459b48621e2eb1997563caf (patch) | |
| tree | c50e16f55a727f4f316ab2cda0e5cc97192edefc /src/ir.cpp | |
| parent | 9f92042da9a674bcef95f9ac18945371305e7f72 (diff) | |
| download | zig-7c236f6dd8194500f459b48621e2eb1997563caf.tar.gz zig-7c236f6dd8194500f459b48621e2eb1997563caf.zip | |
fix compiler crash when referencing a variable...
...in an if after an if in the 2nd switch prong
closes #355
Diffstat (limited to 'src/ir.cpp')
| -rw-r--r-- | src/ir.cpp | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/src/ir.cpp b/src/ir.cpp index 3c2d7b7d34..ebe5ada52e 100644 --- a/src/ir.cpp +++ b/src/ir.cpp @@ -2311,7 +2311,10 @@ static IrInstruction *ir_instruction_elemptr_get_dep(IrInstructionElemPtr *instr } static IrInstruction *ir_instruction_varptr_get_dep(IrInstructionVarPtr *instruction, size_t index) { - return nullptr; + switch (index) { + case 0: return instruction->var->decl_instruction; // can be null + default: return nullptr; + } } static IrInstruction *ir_instruction_call_get_dep(IrInstructionCall *instruction, size_t index) { @@ -4646,7 +4649,10 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod if (init_value == irb->codegen->invalid_instruction) return init_value; - return ir_build_var_decl(irb, scope, node, var, type_instruction, init_value); + + IrInstruction *result = ir_build_var_decl(irb, scope, node, var, type_instruction, init_value); + var->decl_instruction = result; + return result; } static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node) { |
