| author | |
| committer | |
| log | 3c73f711771e41e9176e973c64484f0ce5e0eeed |
| tree | dbccc9029dee8e1412d30a3de4279166b2d1efe0 |
| parent | 3014a0d5f1dcbcfdcec3852ffd54f3c589fe3e83 |
13 files changed, 84 insertions(+), 84 deletions(-)
src/Sema.zig+2-1| ... | ... | @@ -4272,7 +4272,8 @@ fn zirCompileLog( |
| 4272 | 4272 | } |
| 4273 | 4273 | try writer.print("\n", .{}); |
| 4274 | 4274 | |
| 4275 | const gop = try sema.mod.compile_log_decls.getOrPut(sema.gpa, sema.owner_decl_index); | |
| 4275 | const decl_index = if (sema.func) |some| some.owner_decl else sema.owner_decl_index; | |
| 4276 | const gop = try sema.mod.compile_log_decls.getOrPut(sema.gpa, decl_index); | |
| 4276 | 4277 | if (!gop.found_existing) { |
| 4277 | 4278 | gop.value_ptr.* = src_node; |
| 4278 | 4279 | } |
test/cases/compile_errors/compile-time_division_by_zero.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | comptime { | |
| 2 | const a: i32 = 1; | |
| 3 | const b: i32 = 0; | |
| 4 | const c = a / b; | |
| 5 | _ = c; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :4:19: error: division by zero here causes undefined behavior |
test/cases/compile_errors/compile-time_remainder_division_by_zero.zig created+12| ... | ... | @@ -0,0 +1,12 @@ |
| 1 | comptime { | |
| 2 | const a: i32 = 1; | |
| 3 | const b: i32 = 0; | |
| 4 | const c = a % b; | |
| 5 | _ = c; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage2 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :4:19: error: division by zero here causes undefined behavior |
test/cases/compile_errors/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig created+17| ... | ... | @@ -0,0 +1,17 @@ |
| 1 | const Bar = union(enum(u32)) { | |
| 2 | X: i32 = 1 | |
| 3 | }; | |
| 4 | ||
| 5 | fn testCompileLog(x: Bar) void { | |
| 6 | @compileLog(x); | |
| 7 | } | |
| 8 | ||
| 9 | pub export fn entry() void { | |
| 10 | comptime testCompileLog(Bar{.X = 123}); | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage2 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // :6:5: error: found compile log statement |
test/cases/compile_errors/compile_log.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | export fn foo() void { | |
| 2 | comptime bar(12, "hi",); | |
| 3 | } | |
| 4 | fn bar(a: i32, b: []const u8) void { | |
| 5 | @compileLog("begin",); | |
| 6 | @compileLog("a", a, "b", b); | |
| 7 | @compileLog("end",); | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=llvm | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :5:5: error: found compile log statement |
test/cases/compile_errors/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig created+14| ... | ... | @@ -0,0 +1,14 @@ |
| 1 | fn Foo(comptime T: type) type { | |
| 2 | @compileLog(@typeName(T)); | |
| 3 | return T; | |
| 4 | } | |
| 5 | export fn entry() void { | |
| 6 | _ = Foo(i32); | |
| 7 | _ = @typeName(Foo(i32)); | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage2 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // :2:5: error: found compile log statement |
test/cases/compile_errors/compile_time_division_by_zero.zig created+13| ... | ... | @@ -0,0 +1,13 @@ |
| 1 | const y = foo(0); | |
| 2 | fn foo(x: u32) u32 { | |
| 3 | return 1 / x; | |
| 4 | } | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(y)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=llvm | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // :3:16: error: division by zero here causes undefined behavior | |
| 13 | // :1:14: note: called from here |
test/cases/compile_errors/stage1/obj/compile-time_division_by_zero.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | comptime { | |
| 2 | const a: i32 = 1; | |
| 3 | const b: i32 = 0; | |
| 4 | const c = a / b; | |
| 5 | _ = c; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:4:17: error: division by zero |
test/cases/compile_errors/stage1/obj/compile-time_remainder_division_by_zero.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | comptime { | |
| 2 | const a: i32 = 1; | |
| 3 | const b: i32 = 0; | |
| 4 | const c = a % b; | |
| 5 | _ = c; | |
| 6 | } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:4:17: error: division by zero |
test/cases/compile_errors/stage1/obj/compileLog_of_tagged_enum_doesnt_crash_the_compiler.zig deleted-17| ... | ... | @@ -1,17 +0,0 @@ |
| 1 | const Bar = union(enum(u32)) { | |
| 2 | X: i32 = 1 | |
| 3 | }; | |
| 4 | ||
| 5 | fn testCompileLog(x: Bar) void { | |
| 6 | @compileLog(x); | |
| 7 | } | |
| 8 | ||
| 9 | pub fn main () void { | |
| 10 | comptime testCompileLog(Bar{.X = 123}); | |
| 11 | } | |
| 12 | ||
| 13 | // error | |
| 14 | // backend=stage1 | |
| 15 | // target=native | |
| 16 | // | |
| 17 | // tmp.zig:6:5: error: found compile log statement |
test/cases/compile_errors/stage1/obj/compile_log.zig deleted-16| ... | ... | @@ -1,16 +0,0 @@ |
| 1 | export fn foo() void { | |
| 2 | comptime bar(12, "hi",); | |
| 3 | } | |
| 4 | fn bar(a: i32, b: []const u8) void { | |
| 5 | @compileLog("begin",); | |
| 6 | @compileLog("a", a, "b", b); | |
| 7 | @compileLog("end",); | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:5:5: error: found compile log statement | |
| 15 | // tmp.zig:6:5: error: found compile log statement | |
| 16 | // tmp.zig:7:5: error: found compile log statement |
test/cases/compile_errors/stage1/obj/compile_log_statement_inside_function_which_must_be_comptime_evaluated.zig deleted-14| ... | ... | @@ -1,14 +0,0 @@ |
| 1 | fn Foo(comptime T: type) type { | |
| 2 | @compileLog(@typeName(T)); | |
| 3 | return T; | |
| 4 | } | |
| 5 | export fn entry() void { | |
| 6 | _ = Foo(i32); | |
| 7 | _ = @typeName(Foo(i32)); | |
| 8 | } | |
| 9 | ||
| 10 | // error | |
| 11 | // backend=stage1 | |
| 12 | // target=native | |
| 13 | // | |
| 14 | // tmp.zig:2:5: error: found compile log statement |
test/cases/compile_errors/stage1/obj/compile_time_division_by_zero.zig deleted-12| ... | ... | @@ -1,12 +0,0 @@ |
| 1 | const y = foo(0); | |
| 2 | fn foo(x: u32) u32 { | |
| 3 | return 1 / x; | |
| 4 | } | |
| 5 | ||
| 6 | export fn entry() usize { return @sizeOf(@TypeOf(y)); } | |
| 7 | ||
| 8 | // error | |
| 9 | // backend=stage1 | |
| 10 | // target=native | |
| 11 | // | |
| 12 | // tmp.zig:3:14: error: division by zero |