authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-25 10:11:58-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2017-08-25 10:20:06-04:00
log629aa10c5672926eb5f8494296f5d5492cc2833f
tree59db310d0a3317ff76f24d44598146fb794c73c4
parent5dddb45ec71ae93750fddda932ef8b7d2ffa293d

unreachable still codegens to unreachable in ReleaseFast test mode

closes #430

3 files changed, 11 insertions(+), 7 deletions(-)

src/codegen.cpp+1-1
......@@ -1879,7 +1879,7 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I
18791879static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
18801880 IrInstructionUnreachable *unreachable_instruction)
18811881{
1882 if (ir_want_debug_safety(g, &unreachable_instruction->base) || g->is_test_build) {
1882 if (ir_want_debug_safety(g, &unreachable_instruction->base)) {
18831883 gen_debug_safety_crash(g, PanicMsgIdUnreachable);
18841884 } else {
18851885 LLVMBuildUnreachable(g->builder);
std/debug.zig+9-1
......@@ -12,7 +12,15 @@ error InvalidDebugInfo;
1212error UnsupportedDebugInfo;
1313
1414pub fn assert(ok: bool) {
15 if (!ok) unreachable // assertion failure
15 if (!ok) {
16 // In ReleaseFast test mode, we still want assert(false) to crash, so
17 // we insert an explicit call to @panic instead of unreachable.
18 if (builtin.is_test) {
19 @panic("assertion failure")
20 } else {
21 unreachable // assertion failure
22 }
23 }
1624}
1725
1826var panicking = false;
std/special/compiler_rt/index.zig+1-5
......@@ -17,6 +17,7 @@ comptime {
1717
1818const builtin = @import("builtin");
1919const is_test = builtin.is_test;
20const assert = @import("../../debug.zig").assert;
2021
2122const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
2223
......@@ -292,8 +293,3 @@ fn test_one_udivsi3(a: u32, b: u32, expected_q: u32) {
292293 const q: u32 = __udivsi3(a, b);
293294 assert(q == expected_q);
294295}
295
296
297fn assert(ok: bool) {
298 if (!ok) unreachable;
299}