| author | |
| committer | |
| log | 85d0f0d45bf1529db8965b8176f8021d1ca27534 |
| tree | 7b919eae5611658bf0af9ffd9835a464344527b9 |
| parent | d21370833352369867596305dda99f8cafc69277 |
| signature |
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 | ... | @@ -1183,11 +1183,21 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1183 | "--output-dir", | 1183 | "--output-dir", |
| 1184 | tmp_dir_name, | 1184 | tmp_dir_name, |
| 1185 | }); | 1185 | }); |
| 1186 | var mode_arg: []const u8 = ""; | ||
| 1186 | switch (code.mode) { | 1187 | switch (code.mode) { |
| 1187 | builtin.Mode.Debug => {}, | 1188 | builtin.Mode.Debug => {}, |
| 1188 | builtin.Mode.ReleaseSafe => try test_args.append("--release-safe"), | 1189 | builtin.Mode.ReleaseSafe => { |
| 1189 | builtin.Mode.ReleaseFast => try test_args.append("--release-fast"), | 1190 | try test_args.append("--release-safe"); |
| 1190 | builtin.Mode.ReleaseSmall => try test_args.append("--release-small"), | 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 | }, | ||
| 1191 | } | 1201 | } |
| 1192 | 1202 | ||
| 1193 | const result = try os.ChildProcess.exec(allocator, test_args.toSliceConst(), null, &env_map, max_doc_file_size); | 1203 | 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 | ... | @@ -1217,7 +1227,12 @@ fn genHtml(allocator: *mem.Allocator, tokenizer: *Tokenizer, toc: *Toc, out: var |
| 1217 | } | 1227 | } |
| 1218 | const escaped_stderr = try escapeHtml(allocator, result.stderr); | 1228 | const escaped_stderr = try escapeHtml(allocator, result.stderr); |
| 1219 | const colored_stderr = try termColor(allocator, escaped_stderr); | 1229 | 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 | ); | ||
| 1221 | }, | 1236 | }, |
| 1222 | Code.Id.Obj => |maybe_error_match| { | 1237 | Code.Id.Obj => |maybe_error_match| { |
| 1223 | const name_plus_obj_ext = try std.fmt.allocPrint(allocator, "{}{}", code.name, obj_ext); | 1238 | 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 { | ... | @@ -6780,8 +6780,32 @@ pub const FloatMode = enum { |
| 6780 | {#header_open|@setRuntimeSafety#} | 6780 | {#header_open|@setRuntimeSafety#} |
| 6781 | <pre>{#syntax#}@setRuntimeSafety(safety_on: bool){#endsyntax#}</pre> | 6781 | <pre>{#syntax#}@setRuntimeSafety(safety_on: bool){#endsyntax#}</pre> |
| 6782 | <p> | 6782 | <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. |
| 6784 | </p> | 6784 | </p> |
| 6785 | {#code_begin|test_safety|integer overflow#} | ||
| 6786 | {#code_release_fast#} | ||
| 6787 | test "@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#} | ||
| 6785 | 6809 | ||
| 6786 | {#header_close#} | 6810 | {#header_close#} |
| 6787 | 6811 |
src/codegen.cpp+3-4| ... | @@ -878,9 +878,6 @@ static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) { | ... | @@ -878,9 +878,6 @@ static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) { |
| 878 | } | 878 | } |
| 879 | 879 | ||
| 880 | static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) { | 880 | static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) { |
| 881 | if (g->build_mode == BuildModeFastRelease || g->build_mode == BuildModeSmallRelease) | ||
| 882 | return false; | ||
| 883 | |||
| 884 | // TODO memoize | 881 | // TODO memoize |
| 885 | Scope *scope = instruction->scope; | 882 | Scope *scope = instruction->scope; |
| 886 | while (scope) { | 883 | while (scope) { |
| ... | @@ -895,7 +892,9 @@ static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) { | ... | @@ -895,7 +892,9 @@ static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) { |
| 895 | } | 892 | } |
| 896 | scope = scope->parent; | 893 | scope = scope->parent; |
| 897 | } | 894 | } |
| 898 | return true; | 895 | |
| 896 | return (g->build_mode != BuildModeFastRelease && | ||
| 897 | g->build_mode != BuildModeSmallRelease); | ||
| 899 | } | 898 | } |
| 900 | 899 | ||
| 901 | static Buf *panic_msg_buf(PanicMsgId msg_id) { | 900 | static Buf *panic_msg_buf(PanicMsgId msg_id) { |