authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-13 14:46:53-04:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2019-03-13 14:46:53-04:00
log85d0f0d45bf1529db8965b8176f8021d1ca27534
tree7b919eae5611658bf0af9ffd9835a464344527b9
parentd21370833352369867596305dda99f8cafc69277
signaturelock-open Commit is signed but in an unrecognized format.

fix @setRuntimeSafety not able to override release modes


3 files changed, 47 insertions(+), 9 deletions(-)

doc/docgen.zig+19-4
......@@ -1183,11 +1183,21 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var
11831183 "--output-dir",
11841184 tmp_dir_name,
11851185 });
1186 var mode_arg: []const u8 = "";
11861187 switch (code.mode) {
11871188 builtin.Mode.Debug => {},
1188 builtin.Mode.ReleaseSafe => try test_args.append("--release-safe"),
1189 builtin.Mode.ReleaseFast => try test_args.append("--release-fast"),
1190 builtin.Mode.ReleaseSmall => try test_args.append("--release-small"),
1189 builtin.Mode.ReleaseSafe => {
1190 try test_args.append("--release-safe");
1191 mode_arg = " --release-safe";
1192 },
1193 builtin.Mode.ReleaseFast => {
1194 try test_args.append("--release-fast");
1195 mode_arg = " --release-fast";
1196 },
1197 builtin.Mode.ReleaseSmall => {
1198 try test_args.append("--release-small");
1199 mode_arg = " --release-small";
1200 },
11911201 }
11921202
11931203 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
12171227 }
12181228 const escaped_stderr = try escapeHtml(allocator, result.stderr);
12191229 const colored_stderr = try termColor(allocator, escaped_stderr);
1220 try out.print("<pre><code class=\"shell\">$ zig test {}.zig\n{}</code></pre>\n", code.name, colored_stderr);
1230 try out.print(
1231 "<pre><code class=\"shell\">$ zig test {}.zig{}\n{}</code></pre>\n",
1232 code.name,
1233 mode_arg,
1234 colored_stderr,
1235 );
12211236 },
12221237 Code.Id.Obj => |maybe_error_match| {
12231238 const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext);
doc/langref.html.in+25-1
......@@ -6780,8 +6780,32 @@ pub const FloatMode = enum {
67806780 {#header_open|@setRuntimeSafety#}
67816781 <pre>{#syntax#}@setRuntimeSafety(safety_on: bool){#endsyntax#}</pre>
67826782 <p>
6783 Sets whether runtime safety checks are on for the scope that contains the function call.
6783 Sets whether runtime safety checks are enabled for the scope that contains the function call.
67846784 </p>
6785 {#code_begin|test_safety|integer overflow#}
6786 {#code_release_fast#}
6787test "@setRuntimeSafety" {
6788 // The builtin applies to the scope that it is called in. So here, integer overflow
6789 // will not be caught in ReleaseFast and ReleaseSmall modes:
6790 // var x: u8 = 255;
6791 // x += 1; // undefined behavior in ReleaseFast/ReleaseSmall modes.
6792 {
6793 // However this block has safety enabled, so safety checks happen here,
6794 // even in ReleaseFast and ReleaseSmall modes.
6795 @setRuntimeSafety(true);
6796 var x: u8 = 255;
6797 x += 1;
6798
6799 {
6800 // The value can be overridden at any scope. So here integer overflow
6801 // would not be caught in any build mode.
6802 @setRuntimeSafety(false);
6803 // var x: u8 = 255;
6804 // x += 1; // undefined behavior in all build modes.
6805 }
6806 }
6807}
6808 {#code_end#}
67856809
67866810 {#header_close#}
67876811
src/codegen.cpp+3-4
......@@ -878,9 +878,6 @@ static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {
878878}
879879
880880static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
881 if (g->build_mode == BuildModeFastRelease || g->build_mode == BuildModeSmallRelease)
882 return false;
883
884881 // TODO memoize
885882 Scope *scope = instruction->scope;
886883 while (scope) {
......@@ -895,7 +892,9 @@ static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
895892 }
896893 scope = scope->parent;
897894 }
898 return true;
895
896 return (g->build_mode != BuildModeFastRelease &&
897 g->build_mode != BuildModeSmallRelease);
899898}
900899
901900static Buf *panic_msg_buf(PanicMsgId msg_id) {