mirror of
https://github.com/ziglang/zig.git
synced 2025-01-31 14:21:14 +00:00
fix @setRuntimeSafety not able to override release modes
This commit is contained in:
parent
d213708333
commit
85d0f0d45b
@ -1183,11 +1183,21 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
|
|||||||
"--output-dir",
|
"--output-dir",
|
||||||
tmp_dir_name,
|
tmp_dir_name,
|
||||||
});
|
});
|
||||||
|
var mode_arg: []const u8 = "";
|
||||||
switch (code.mode) {
|
switch (code.mode) {
|
||||||
builtin.Mode.Debug => {},
|
builtin.Mode.Debug => {},
|
||||||
builtin.Mode.ReleaseSafe => try test_args.append("--release-safe"),
|
builtin.Mode.ReleaseSafe => {
|
||||||
builtin.Mode.ReleaseFast => try test_args.append("--release-fast"),
|
try test_args.append("--release-safe");
|
||||||
builtin.Mode.ReleaseSmall => try test_args.append("--release-small"),
|
mode_arg = " --release-safe";
|
||||||
|
},
|
||||||
|
builtin.Mode.ReleaseFast => {
|
||||||
|
try test_args.append("--release-fast");
|
||||||
|
mode_arg = " --release-fast";
|
||||||
|
},
|
||||||
|
builtin.Mode.ReleaseSmall => {
|
||||||
|
try test_args.append("--release-small");
|
||||||
|
mode_arg = " --release-small";
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
|
const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size);
|
||||||
@ -1217,7 +1227,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
|
|||||||
}
|
}
|
||||||
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
const escaped_stderr = try escapeHtml(allocator, result.stderr);
|
||||||
const colored_stderr = try termColor(allocator, escaped_stderr);
|
const colored_stderr = try termColor(allocator, escaped_stderr);
|
||||||
try out.print("<pre><code class=\"shell\">$ zig test {}.zig\n{}</code></pre>\n", code.name, colored_stderr);
|
try out.print(
|
||||||
|
"<pre><code class=\"shell\">$ zig test {}.zig{}\n{}</code></pre>\n",
|
||||||
|
code.name,
|
||||||
|
mode_arg,
|
||||||
|
colored_stderr,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
Code.Id.Obj => |maybe_error_match| {
|
Code.Id.Obj => |maybe_error_match| {
|
||||||
const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);
|
const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);
|
||||||
|
@ -6780,8 +6780,32 @@ pub const FloatMode = enum {
|
|||||||
{#header_open|@setRuntimeSafety#}
|
{#header_open|@setRuntimeSafety#}
|
||||||
<pre>{#syntax#}@setRuntimeSafety(safety_on: bool){#endsyntax#}</pre>
|
<pre>{#syntax#}@setRuntimeSafety(safety_on: bool){#endsyntax#}</pre>
|
||||||
<p>
|
<p>
|
||||||
Sets whether runtime safety checks are on for the scope that contains the function call.
|
Sets whether runtime safety checks are enabled for the scope that contains the function call.
|
||||||
</p>
|
</p>
|
||||||
|
{#code_begin|test_safety|integer overflow#}
|
||||||
|
{#code_release_fast#}
|
||||||
|
test "@setRuntimeSafety" {
|
||||||
|
// The builtin applies to the scope that it is called in. So here, integer overflow
|
||||||
|
// will not be caught in ReleaseFast and ReleaseSmall modes:
|
||||||
|
// var x: u8 = 255;
|
||||||
|
// x += 1; // undefined behavior in ReleaseFast/ReleaseSmall modes.
|
||||||
|
{
|
||||||
|
// However this block has safety enabled, so safety checks happen here,
|
||||||
|
// even in ReleaseFast and ReleaseSmall modes.
|
||||||
|
@setRuntimeSafety(true);
|
||||||
|
var x: u8 = 255;
|
||||||
|
x += 1;
|
||||||
|
|
||||||
|
{
|
||||||
|
// The value can be overridden at any scope. So here integer overflow
|
||||||
|
// would not be caught in any build mode.
|
||||||
|
@setRuntimeSafety(false);
|
||||||
|
// var x: u8 = 255;
|
||||||
|
// x += 1; // undefined behavior in all build modes.
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{#code_end#}
|
||||||
|
|
||||||
{#header_close#}
|
{#header_close#}
|
||||||
|
|
||||||
|
@ -878,9 +878,6 @@ static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
|
static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
|
||||||
if (g->build_mode == BuildModeFastRelease || g->build_mode == BuildModeSmallRelease)
|
|
||||||
return false;
|
|
||||||
|
|
||||||
// TODO memoize
|
// TODO memoize
|
||||||
Scope *scope = instruction->scope;
|
Scope *scope = instruction->scope;
|
||||||
while (scope) {
|
while (scope) {
|
||||||
@ -895,7 +892,9 @@ static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
|
|||||||
}
|
}
|
||||||
scope = scope->parent;
|
scope = scope->parent;
|
||||||
}
|
}
|
||||||
return true;
|
|
||||||
|
return (g->build_mode != BuildModeFastRelease &&
|
||||||
|
g->build_mode != BuildModeSmallRelease);
|
||||||
}
|
}
|
||||||
|
|
||||||
static Buf *panic_msg_buf(PanicMsgId msg_id) {
|
static Buf *panic_msg_buf(PanicMsgId msg_id) {
|
||||||
|
Loading…
Reference in New Issue
Block a user