authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-14 01:07:23-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-12-14 01:07:23-05:00
logc9e01412a451419491786bf3db1713875928092c
treeafb3832a64f5b8e942c24b076cc64dd39c5af406
parentf55fdc00fcde3cd17ed0ddb94c0997c882dbe6b9

fix compiler crash in a nullable if after an if in...

...a switch prong of a switch with 2 prongs in an else closes #656

3 files changed, 34 insertions(+), 3 deletions(-)

src/ir.cpp+3-3
...@@ -1191,6 +1191,8 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1191,6 +1191,8 @@ static IrInstruction *ir_build_var_decl(IrBuilder *irb, Scope *scope, AstNode *s
1191 if (align_value) ir_ref_instruction(align_value, irb->current_basic_block);1191 if (align_value) ir_ref_instruction(align_value, irb->current_basic_block);
1192 ir_ref_instruction(init_value, irb->current_basic_block);1192 ir_ref_instruction(init_value, irb->current_basic_block);
11931193
1194 var->decl_instruction = &decl_var_instruction->base;
1195
1194 return &decl_var_instruction->base;1196 return &decl_var_instruction->base;
1195}1197}
11961198
...@@ -5108,9 +5110,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod...@@ -5108,9 +5110,7 @@ static IrInstruction *ir_gen_var_decl(IrBuilder *irb, Scope *scope, AstNode *nod
5108 if (init_value == irb->codegen->invalid_instruction)5110 if (init_value == irb->codegen->invalid_instruction)
5109 return init_value;5111 return init_value;
51105112
5111 IrInstruction *result = ir_build_var_decl(irb, scope, node, var, type_instruction, align_value, init_value);5113 return ir_build_var_decl(irb, scope, node, var, type_instruction, align_value, init_value);
5112 var->decl_instruction = result;
5113 return result;
5114}5114}
51155115
5116static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node) {5116static IrInstruction *ir_gen_while_expr(IrBuilder *irb, Scope *scope, AstNode *node) {
test/behavior.zig+1
...@@ -8,6 +8,7 @@ comptime {...@@ -8,6 +8,7 @@ comptime {
8 _ = @import("cases/bool.zig");8 _ = @import("cases/bool.zig");
9 _ = @import("cases/bugs/394.zig");9 _ = @import("cases/bugs/394.zig");
10 _ = @import("cases/bugs/655.zig");10 _ = @import("cases/bugs/655.zig");
11 _ = @import("cases/bugs/656.zig");
11 _ = @import("cases/cast.zig");12 _ = @import("cases/cast.zig");
12 _ = @import("cases/const_slice_child.zig");13 _ = @import("cases/const_slice_child.zig");
13 _ = @import("cases/defer.zig");14 _ = @import("cases/defer.zig");
test/cases/bugs/656.zig created+30
...@@ -0,0 +1,30 @@
1const assert = @import("std").debug.assert;
2
3const PrefixOp = union(enum) {
4 Return,
5 AddrOf: Value,
6};
7
8const Value = struct {
9 align_expr: ?u32,
10};
11
12test "nullable if after an if in a switch prong of a switch with 2 prongs in an else" {
13 foo(false, true);
14}
15
16fn foo(a: bool, b: bool) {
17 var prefix_op = PrefixOp { .AddrOf = Value { .align_expr = 1234 } };
18 if (a) {
19 } else {
20 switch (prefix_op) {
21 PrefixOp.AddrOf => |addr_of_info| {
22 if (b) { }
23 if (addr_of_info.align_expr) |align_expr| {
24 assert(align_expr == 1234);
25 }
26 },
27 PrefixOp.Return => {},
28 }
29 }
30}