authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-29 13:21:36-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-29 13:21:36-07:00
logd3426ce634a09ec289480510040b3decfbd38c39
tree7fe7bab9732fdd08b5b87cf96cd2d5a376d367fb
parentb613210140f649b11232fae8bad16867d122d0cb

AstGen: require binary operations to have reachable operands


2 files changed, 8 insertions(+), 3 deletions(-)

src/AstGen.zig+2-2
......@@ -4781,8 +4781,8 @@ fn simpleBinOp(
47814781 const node_datas = tree.nodes.items(.data);
47824782
47834783 const result = try gz.addPlNode(op_inst_tag, node, Zir.Inst.Bin{
4784 .lhs = try expr(gz, scope, .none, node_datas[node].lhs),
4785 .rhs = try expr(gz, scope, .none, node_datas[node].rhs),
4784 .lhs = try reachableExpr(gz, scope, .none, node_datas[node].lhs, node),
4785 .rhs = try reachableExpr(gz, scope, .none, node_datas[node].rhs, node),
47864786 });
47874787 return rvalue(gz, rl, result, node);
47884788}
test/compile_errors.zig+6-1
......@@ -5033,13 +5033,18 @@ pub fn addCases(ctx: *TestContext) !void {
50335033 "tmp.zig:2:5: note: control flow is diverted here",
50345034 });
50355035
5036 ctx.objErrStage1("unreachable code - return return",
5036 ctx.objErrStage1("unreachable code - multiple things",
50375037 \\export fn a() i32 {
50385038 \\ return return 1;
50395039 \\}
5040 \\export fn b(value: u32) bool {
5041 \\ return 1 < value < 1000;
5042 \\}
50405043 , &[_][]const u8{
50415044 "tmp.zig:2:5: error: unreachable code",
50425045 "tmp.zig:2:12: note: control flow is diverted here",
5046 "tmp.zig:5:22: error: unreachable code",
5047 "tmp.zig:5:5: note: control flow is diverted here",
50435048 });
50445049
50455050 ctx.objErrStage1("bad import",