authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-24 14:47:33-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2021-11-24 14:47:33-07:00
logc42763f8cc9223fc43ac3478a5f15d4bd9f438e4
tree8dc9c3e3cf9f6e5ebb4308da37142c70df947fb4
parent57e1f6a89f044e731fe60ce15e98b496dcbaa74f

AstGen: use reachableExpr for return operand

Related: #9630

7 files changed, 15 insertions(+), 6 deletions(-)

lib/std/math/ln.zig+1-1
......@@ -32,7 +32,7 @@ pub fn ln(x: anytype) @TypeOf(x) {
3232 return @as(comptime_int, math.floor(ln_64(@as(f64, x))));
3333 },
3434 .Int => |IntType| switch (IntType.signedness) {
35 .signed => return @compileError("ln not implemented for signed integers"),
35 .signed => @compileError("ln not implemented for signed integers"),
3636 .unsigned => return @as(T, math.floor(ln_64(@as(f64, x)))),
3737 },
3838 else => @compileError("ln not implemented for " ++ @typeName(T)),
lib/std/math/log.zig+1-1
......@@ -29,7 +29,7 @@ pub fn log(comptime T: type, base: T, x: T) T {
2929
3030 // TODO implement integer log without using float math
3131 .Int => |IntType| switch (IntType.signedness) {
32 .signed => return @compileError("log not implemented for signed integers"),
32 .signed => @compileError("log not implemented for signed integers"),
3333 .unsigned => return @floatToInt(T, math.floor(math.ln(@intToFloat(f64, x)) / math.ln(float_base))),
3434 },
3535
lib/std/math/log10.zig+1-1
......@@ -33,7 +33,7 @@ pub fn log10(x: anytype) @TypeOf(x) {
3333 return @as(comptime_int, math.floor(log10_64(@as(f64, x))));
3434 },
3535 .Int => |IntType| switch (IntType.signedness) {
36 .signed => return @compileError("log10 not implemented for signed integers"),
36 .signed => @compileError("log10 not implemented for signed integers"),
3737 .unsigned => return @floatToInt(T, math.floor(log10_64(@intToFloat(f64, x)))),
3838 },
3939 else => @compileError("log10 not implemented for " ++ @typeName(T)),
lib/std/math/log2.zig+1-1
......@@ -39,7 +39,7 @@ pub fn log2(x: anytype) @TypeOf(x) {
3939 return result;
4040 },
4141 .Int => |IntType| switch (IntType.signedness) {
42 .signed => return @compileError("log2 not implemented for signed integers"),
42 .signed => @compileError("log2 not implemented for signed integers"),
4343 .unsigned => return math.log2_int(T, x),
4444 },
4545 else => @compileError("log2 not implemented for " ++ @typeName(T)),
lib/std/math/sqrt.zig+1-1
......@@ -26,7 +26,7 @@ pub fn sqrt(x: anytype) Sqrt(@TypeOf(x)) {
2626 return @as(T, sqrt_int(u128, x));
2727 },
2828 .Int => |IntType| switch (IntType.signedness) {
29 .signed => return @compileError("sqrt not implemented for signed integers"),
29 .signed => @compileError("sqrt not implemented for signed integers"),
3030 .unsigned => return sqrt_int(T, x),
3131 },
3232 else => @compileError("sqrt not implemented for " ++ @typeName(T)),
src/AstGen.zig+1-1
......@@ -5963,7 +5963,7 @@ fn ret(gz: *GenZir, scope: *Scope, node: Ast.Node.Index) InnerError!Zir.Inst.Ref
59635963 } else .{
59645964 .ty = try gz.addNodeExtended(.ret_type, node),
59655965 };
5966 const operand = try expr(gz, scope, rl, operand_node);
5966 const operand = try reachableExpr(gz, scope, rl, operand_node, node);
59675967
59685968 switch (nodeMayEvalToError(tree, operand_node)) {
59695969 .never => {
test/compile_errors.zig+9
......@@ -4999,6 +4999,15 @@ pub fn addCases(ctx: *TestContext) !void {
49994999 "tmp.zig:2:5: note: control flow is diverted here",
50005000 });
50015001
5002 ctx.objErrStage1("unreachable code - return return",
5003 \\export fn a() i32 {
5004 \\ return return 1;
5005 \\}
5006 , &[_][]const u8{
5007 "tmp.zig:2:5: error: unreachable code",
5008 "tmp.zig:2:12: note: control flow is diverted here",
5009 });
5010
50025011 ctx.objErrStage1("bad import",
50035012 \\const bogus = @import("bogus-does-not-exist.zig",);
50045013 , &[_][]const u8{