authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-25 01:46:12-05:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2018-01-25 01:46:12-05:00
loge5bc5873d74713bedbc32817ed31370c3256418d
treedbd196cb4242ae111591238d923d100062fb86c6
parentb71a56c9df5e3b20d06cac24062456821b69dbba

rename "debug safety" to "runtime safety"

closes #437

36 files changed, 487 insertions(+), 509 deletions(-)

build.zig+1-1
...@@ -116,7 +116,7 @@ pub fn build(b: &Builder) -> %void {...@@ -116,7 +116,7 @@ pub fn build(b: &Builder) -> %void {
116 test_step.dependOn(tests.addBuildExampleTests(b, test_filter));116 test_step.dependOn(tests.addBuildExampleTests(b, test_filter));
117 test_step.dependOn(tests.addCompileErrorTests(b, test_filter));117 test_step.dependOn(tests.addCompileErrorTests(b, test_filter));
118 test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter));118 test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter));
119 test_step.dependOn(tests.addDebugSafetyTests(b, test_filter));119 test_step.dependOn(tests.addRuntimeSafetyTests(b, test_filter));
120 test_step.dependOn(tests.addTranslateCTests(b, test_filter));120 test_step.dependOn(tests.addTranslateCTests(b, test_filter));
121 test_step.dependOn(tests.addGenHTests(b, test_filter));121 test_step.dependOn(tests.addGenHTests(b, test_filter));
122}122}
doc/docgen.zig+1-1
...@@ -896,7 +896,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io...@@ -896,7 +896,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io
896 }896 }
897 if (mem.indexOf(u8, result.stderr, error_match) == null) {897 if (mem.indexOf(u8, result.stderr, error_match) == null) {
898 warn("{}\nExpected to find '{}' in stderr", result.stderr, error_match);898 warn("{}\nExpected to find '{}' in stderr", result.stderr, error_match);
899 return parseError(tokenizer, code.source_token, "example did not have expected debug safety error message");899 return parseError(tokenizer, code.source_token, "example did not have expected runtime safety error message");
900 }900 }
901 const escaped_stderr = try escapeHtml(allocator, result.stderr);901 const escaped_stderr = try escapeHtml(allocator, result.stderr);
902 const colored_stderr = try termColor(allocator, escaped_stderr);902 const colored_stderr = try termColor(allocator, escaped_stderr);
doc/langref.html.in+6-6
...@@ -3090,7 +3090,7 @@ fn doAThing(nullable_foo: ?&Foo) {...@@ -3090,7 +3090,7 @@ fn doAThing(nullable_foo: ?&Foo) {
3090 {#header_open|this#}3090 {#header_open|this#}
3091 <p>TODO: example of this referring to Self struct</p>3091 <p>TODO: example of this referring to Self struct</p>
3092 <p>TODO: example of this referring to recursion function</p>3092 <p>TODO: example of this referring to recursion function</p>
3093 <p>TODO: example of this referring to basic block for @setDebugSafety</p>3093 <p>TODO: example of this referring to basic block for @setRuntimeSafety</p>
3094 {#header_close#}3094 {#header_close#}
3095 {#header_open|comptime#}3095 {#header_open|comptime#}
3096 <p>3096 <p>
...@@ -4325,10 +4325,10 @@ test "call foo" {...@@ -4325,10 +4325,10 @@ test "call foo" {
4325 Tells the optimizer that a function is rarely called.4325 Tells the optimizer that a function is rarely called.
4326 </p>4326 </p>
4327 {#header_close#}4327 {#header_close#}
4328 {#header_open|@setDebugSafety#}4328 {#header_open|@setRuntimeSafety#}
4329 <pre><code class="zig">@setDebugSafety(scope, safety_on: bool)</code></pre>4329 <pre><code class="zig">@setRuntimeSafety(safety_on: bool)</code></pre>
4330 <p>4330 <p>
4331 Sets whether debug safety checks are on for a given scope.4331 Sets whether runtime safety checks are on for the scope that contains the function call.
4332 </p>4332 </p>
43334333
4334 {#header_close#}4334 {#header_close#}
...@@ -4595,7 +4595,7 @@ pub fn build(b: &Builder) -> %void {...@@ -4595,7 +4595,7 @@ pub fn build(b: &Builder) -> %void {
4595 detected at compile-time, Zig emits an error. Most undefined behavior that4595 detected at compile-time, Zig emits an error. Most undefined behavior that
4596 cannot be detected at compile-time can be detected at runtime. In these cases,4596 cannot be detected at compile-time can be detected at runtime. In these cases,
4597 Zig has safety checks. Safety checks can be disabled on a per-block basis4597 Zig has safety checks. Safety checks can be disabled on a per-block basis
4598 with <code>@setDebugSafety</code>. The {#link|ReleaseFast#}4598 with <code>@setRuntimeSafety</code>. The {#link|ReleaseFast#}
4599 build mode disables all safety checks in order to facilitate optimizations.4599 build mode disables all safety checks in order to facilitate optimizations.
4600 </p>4600 </p>
4601 <p>4601 <p>
...@@ -5765,7 +5765,7 @@ hljs.registerLanguage("zig", function(t) {...@@ -5765,7 +5765,7 @@ hljs.registerLanguage("zig", function(t) {
5765 a = t.IR + "\\s*\\(",5765 a = t.IR + "\\s*\\(",
5766 c = {5766 c = {
5767 keyword: "const align var extern stdcallcc nakedcc volatile export pub noalias inline struct packed enum union break return try catch test continue unreachable comptime and or asm defer errdefer if else switch while for fn use bool f32 f64 void type noreturn error i8 u8 i16 u16 i32 u32 i64 u64 isize usize i8w u8w i16w i32w u32w i64w u64w isizew usizew c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong",5767 keyword: "const align var extern stdcallcc nakedcc volatile export pub noalias inline struct packed enum union break return try catch test continue unreachable comptime and or asm defer errdefer if else switch while for fn use bool f32 f64 void type noreturn error i8 u8 i16 u16 i32 u32 i64 u64 isize usize i8w u8w i16w i32w u32w i64w u64w isizew usizew c_short c_ushort c_int c_uint c_long c_ulong c_longlong c_ulonglong",
5768 built_in: "breakpoint returnAddress frameAddress fieldParentPtr setFloatMode IntType OpaqueType compileError compileLog setCold setDebugSafety setEvalBranchQuota offsetOf memcpy inlineCall setGlobalLinkage setGlobalSection divTrunc divFloor enumTagName intToPtr ptrToInt panic canImplicitCast ptrCast bitCast rem mod memset sizeOf alignOf alignCast maxValue minValue memberCount typeOf addWithOverflow subWithOverflow mulWithOverflow shlWithOverflow shlExact shrExact cInclude cDefine cUndef ctz clz import cImport errorName embedFile cmpxchg fence divExact truncate",5768 built_in: "breakpoint returnAddress frameAddress fieldParentPtr setFloatMode IntType OpaqueType compileError compileLog setCold setRuntimeSafety setEvalBranchQuota offsetOf memcpy inlineCall setGlobalLinkage setGlobalSection divTrunc divFloor enumTagName intToPtr ptrToInt panic canImplicitCast ptrCast bitCast rem mod memset sizeOf alignOf alignCast maxValue minValue memberCount typeOf addWithOverflow subWithOverflow mulWithOverflow shlWithOverflow shlExact shrExact cInclude cDefine cUndef ctz clz import cImport errorName embedFile cmpxchg fence divExact truncate",
5769 literal: "true false null undefined"5769 literal: "true false null undefined"
5770 },5770 },
5771 n = [e, t.CLCM, t.CBCM, s, r];5771 n = [e, t.CLCM, t.CBCM, s, r];
src-self-hosted/ir.zig+1-1
...@@ -33,7 +33,7 @@ pub const Instruction = struct {...@@ -33,7 +33,7 @@ pub const Instruction = struct {
33 TypeOf,33 TypeOf,
34 ToPtrType,34 ToPtrType,
35 PtrTypeChild,35 PtrTypeChild,
36 SetDebugSafety,36 SetRuntimeSafety,
37 SetFloatMode,37 SetFloatMode,
38 ArrayType,38 ArrayType,
39 SliceType,39 SliceType,
src/all_types.hpp+4-5
...@@ -1255,7 +1255,7 @@ enum BuiltinFnId {...@@ -1255,7 +1255,7 @@ enum BuiltinFnId {
1255 BuiltinFnIdTruncate,1255 BuiltinFnIdTruncate,
1256 BuiltinFnIdIntType,1256 BuiltinFnIdIntType,
1257 BuiltinFnIdSetCold,1257 BuiltinFnIdSetCold,
1258 BuiltinFnIdSetDebugSafety,1258 BuiltinFnIdSetRuntimeSafety,
1259 BuiltinFnIdSetFloatMode,1259 BuiltinFnIdSetFloatMode,
1260 BuiltinFnIdTypeName,1260 BuiltinFnIdTypeName,
1261 BuiltinFnIdCanImplicitCast,1261 BuiltinFnIdCanImplicitCast,
...@@ -1836,7 +1836,7 @@ enum IrInstructionId {...@@ -1836,7 +1836,7 @@ enum IrInstructionId {
1836 IrInstructionIdToPtrType,1836 IrInstructionIdToPtrType,
1837 IrInstructionIdPtrTypeChild,1837 IrInstructionIdPtrTypeChild,
1838 IrInstructionIdSetCold,1838 IrInstructionIdSetCold,
1839 IrInstructionIdSetDebugSafety,1839 IrInstructionIdSetRuntimeSafety,
1840 IrInstructionIdSetFloatMode,1840 IrInstructionIdSetFloatMode,
1841 IrInstructionIdArrayType,1841 IrInstructionIdArrayType,
1842 IrInstructionIdSliceType,1842 IrInstructionIdSliceType,
...@@ -2214,11 +2214,10 @@ struct IrInstructionSetCold {...@@ -2214,11 +2214,10 @@ struct IrInstructionSetCold {
2214 IrInstruction *is_cold;2214 IrInstruction *is_cold;
2215};2215};
22162216
2217struct IrInstructionSetDebugSafety {2217struct IrInstructionSetRuntimeSafety {
2218 IrInstruction base;2218 IrInstruction base;
22192219
2220 IrInstruction *scope_value;2220 IrInstruction *safety_on;
2221 IrInstruction *debug_safety_on;
2222};2221};
22232222
2224struct IrInstructionSetFloatMode {2223struct IrInstructionSetFloatMode {
src/codegen.cpp+68-68
...@@ -806,7 +806,7 @@ static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {...@@ -806,7 +806,7 @@ static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {
806 return true;806 return true;
807}807}
808808
809static bool ir_want_debug_safety(CodeGen *g, IrInstruction *instruction) {809static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
810 if (g->build_mode == BuildModeFastRelease)810 if (g->build_mode == BuildModeFastRelease)
811 return false;811 return false;
812812
...@@ -901,7 +901,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace...@@ -901,7 +901,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace
901 LLVMBuildUnreachable(g->builder);901 LLVMBuildUnreachable(g->builder);
902}902}
903903
904static void gen_debug_safety_crash(CodeGen *g, PanicMsgId msg_id) {904static void gen_safety_crash(CodeGen *g, PanicMsgId msg_id) {
905 gen_panic(g, get_panic_msg_ptr_val(g, msg_id), nullptr);905 gen_panic(g, get_panic_msg_ptr_val(g, msg_id), nullptr);
906}906}
907907
...@@ -1140,7 +1140,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {...@@ -1140,7 +1140,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
1140 return fn_val;1140 return fn_val;
1141}1141}
11421142
1143static void gen_debug_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val) {1143static void gen_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val) {
1144 LLVMValueRef safety_crash_err_fn = get_safety_crash_err_fn(g);1144 LLVMValueRef safety_crash_err_fn = get_safety_crash_err_fn(g);
1145 LLVMValueRef err_ret_trace_val = g->cur_err_ret_trace_val;1145 LLVMValueRef err_ret_trace_val = g->cur_err_ret_trace_val;
1146 if (err_ret_trace_val == nullptr) {1146 if (err_ret_trace_val == nullptr) {
...@@ -1179,7 +1179,7 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,...@@ -1179,7 +1179,7 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,
1179 LLVMBuildCondBr(g->builder, lower_ok_val, lower_ok_block, bounds_check_fail_block);1179 LLVMBuildCondBr(g->builder, lower_ok_val, lower_ok_block, bounds_check_fail_block);
11801180
1181 LLVMPositionBuilderAtEnd(g->builder, bounds_check_fail_block);1181 LLVMPositionBuilderAtEnd(g->builder, bounds_check_fail_block);
1182 gen_debug_safety_crash(g, PanicMsgIdBoundsCheckFailure);1182 gen_safety_crash(g, PanicMsgIdBoundsCheckFailure);
11831183
1184 if (upper_value) {1184 if (upper_value) {
1185 LLVMPositionBuilderAtEnd(g->builder, lower_ok_block);1185 LLVMPositionBuilderAtEnd(g->builder, lower_ok_block);
...@@ -1190,7 +1190,7 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,...@@ -1190,7 +1190,7 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,
1190 LLVMPositionBuilderAtEnd(g->builder, ok_block);1190 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1191}1191}
11921192
1193static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, TypeTableEntry *actual_type,1193static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, TypeTableEntry *actual_type,
1194 TypeTableEntry *wanted_type, LLVMValueRef expr_val)1194 TypeTableEntry *wanted_type, LLVMValueRef expr_val)
1195{1195{
1196 assert(actual_type->id == wanted_type->id);1196 assert(actual_type->id == wanted_type->id);
...@@ -1209,7 +1209,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ...@@ -1209,7 +1209,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ
12091209
1210 if (actual_bits >= wanted_bits && actual_type->id == TypeTableEntryIdInt &&1210 if (actual_bits >= wanted_bits && actual_type->id == TypeTableEntryIdInt &&
1211 !wanted_type->data.integral.is_signed && actual_type->data.integral.is_signed &&1211 !wanted_type->data.integral.is_signed && actual_type->data.integral.is_signed &&
1212 want_debug_safety)1212 want_runtime_safety)
1213 {1213 {
1214 LLVMValueRef zero = LLVMConstNull(actual_type->type_ref);1214 LLVMValueRef zero = LLVMConstNull(actual_type->type_ref);
1215 LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntSGE, expr_val, zero, "");1215 LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntSGE, expr_val, zero, "");
...@@ -1219,7 +1219,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ...@@ -1219,7 +1219,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ
1219 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);1219 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
12201220
1221 LLVMPositionBuilderAtEnd(g->builder, fail_block);1221 LLVMPositionBuilderAtEnd(g->builder, fail_block);
1222 gen_debug_safety_crash(g, PanicMsgIdCastNegativeToUnsigned);1222 gen_safety_crash(g, PanicMsgIdCastNegativeToUnsigned);
12231223
1224 LLVMPositionBuilderAtEnd(g->builder, ok_block);1224 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1225 }1225 }
...@@ -1243,7 +1243,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ...@@ -1243,7 +1243,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ
1243 return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, "");1243 return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, "");
1244 } else if (actual_type->id == TypeTableEntryIdInt) {1244 } else if (actual_type->id == TypeTableEntryIdInt) {
1245 LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");1245 LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");
1246 if (!want_debug_safety) {1246 if (!want_runtime_safety) {
1247 return trunc_val;1247 return trunc_val;
1248 }1248 }
1249 LLVMValueRef orig_val;1249 LLVMValueRef orig_val;
...@@ -1258,7 +1258,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ...@@ -1258,7 +1258,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ
1258 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);1258 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
12591259
1260 LLVMPositionBuilderAtEnd(g->builder, fail_block);1260 LLVMPositionBuilderAtEnd(g->builder, fail_block);
1261 gen_debug_safety_crash(g, PanicMsgIdCastTruncatedData);1261 gen_safety_crash(g, PanicMsgIdCastTruncatedData);
12621262
1263 LLVMPositionBuilderAtEnd(g->builder, ok_block);1263 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1264 return trunc_val;1264 return trunc_val;
...@@ -1286,7 +1286,7 @@ static LLVMValueRef gen_overflow_op(CodeGen *g, TypeTableEntry *type_entry, AddS...@@ -1286,7 +1286,7 @@ static LLVMValueRef gen_overflow_op(CodeGen *g, TypeTableEntry *type_entry, AddS
1286 LLVMBuildCondBr(g->builder, overflow_bit, fail_block, ok_block);1286 LLVMBuildCondBr(g->builder, overflow_bit, fail_block, ok_block);
12871287
1288 LLVMPositionBuilderAtEnd(g->builder, fail_block);1288 LLVMPositionBuilderAtEnd(g->builder, fail_block);
1289 gen_debug_safety_crash(g, PanicMsgIdIntegerOverflow);1289 gen_safety_crash(g, PanicMsgIdIntegerOverflow);
12901290
1291 LLVMPositionBuilderAtEnd(g->builder, ok_block);1291 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1292 return result;1292 return result;
...@@ -1494,7 +1494,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,...@@ -1494,7 +1494,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,
1494 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);1494 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
14951495
1496 LLVMPositionBuilderAtEnd(g->builder, fail_block);1496 LLVMPositionBuilderAtEnd(g->builder, fail_block);
1497 gen_debug_safety_crash(g, PanicMsgIdShlOverflowedBits);1497 gen_safety_crash(g, PanicMsgIdShlOverflowedBits);
14981498
1499 LLVMPositionBuilderAtEnd(g->builder, ok_block);1499 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1500 return result;1500 return result;
...@@ -1519,7 +1519,7 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry,...@@ -1519,7 +1519,7 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry,
1519 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);1519 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
15201520
1521 LLVMPositionBuilderAtEnd(g->builder, fail_block);1521 LLVMPositionBuilderAtEnd(g->builder, fail_block);
1522 gen_debug_safety_crash(g, PanicMsgIdShrOverflowedBits);1522 gen_safety_crash(g, PanicMsgIdShrOverflowedBits);
15231523
1524 LLVMPositionBuilderAtEnd(g->builder, ok_block);1524 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1525 return result;1525 return result;
...@@ -1565,14 +1565,14 @@ static LLVMValueRef bigint_to_llvm_const(LLVMTypeRef type_ref, BigInt *bigint) {...@@ -1565,14 +1565,14 @@ static LLVMValueRef bigint_to_llvm_const(LLVMTypeRef type_ref, BigInt *bigint) {
1565 }1565 }
1566}1566}
15671567
1568static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_math,1568static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast_math,
1569 LLVMValueRef val1, LLVMValueRef val2,1569 LLVMValueRef val1, LLVMValueRef val2,
1570 TypeTableEntry *type_entry, DivKind div_kind)1570 TypeTableEntry *type_entry, DivKind div_kind)
1571{1571{
1572 ZigLLVMSetFastMath(g->builder, want_fast_math);1572 ZigLLVMSetFastMath(g->builder, want_fast_math);
15731573
1574 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);1574 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
1575 if (want_debug_safety && (want_fast_math || type_entry->id != TypeTableEntryIdFloat)) {1575 if (want_runtime_safety && (want_fast_math || type_entry->id != TypeTableEntryIdFloat)) {
1576 LLVMValueRef is_zero_bit;1576 LLVMValueRef is_zero_bit;
1577 if (type_entry->id == TypeTableEntryIdInt) {1577 if (type_entry->id == TypeTableEntryIdInt) {
1578 is_zero_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, val2, zero, "");1578 is_zero_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, val2, zero, "");
...@@ -1586,7 +1586,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m...@@ -1586,7 +1586,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m
1586 LLVMBuildCondBr(g->builder, is_zero_bit, div_zero_fail_block, div_zero_ok_block);1586 LLVMBuildCondBr(g->builder, is_zero_bit, div_zero_fail_block, div_zero_ok_block);
15871587
1588 LLVMPositionBuilderAtEnd(g->builder, div_zero_fail_block);1588 LLVMPositionBuilderAtEnd(g->builder, div_zero_fail_block);
1589 gen_debug_safety_crash(g, PanicMsgIdDivisionByZero);1589 gen_safety_crash(g, PanicMsgIdDivisionByZero);
15901590
1591 LLVMPositionBuilderAtEnd(g->builder, div_zero_ok_block);1591 LLVMPositionBuilderAtEnd(g->builder, div_zero_ok_block);
15921592
...@@ -1603,7 +1603,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m...@@ -1603,7 +1603,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m
1603 LLVMBuildCondBr(g->builder, overflow_fail_bit, overflow_fail_block, overflow_ok_block);1603 LLVMBuildCondBr(g->builder, overflow_fail_bit, overflow_fail_block, overflow_ok_block);
16041604
1605 LLVMPositionBuilderAtEnd(g->builder, overflow_fail_block);1605 LLVMPositionBuilderAtEnd(g->builder, overflow_fail_block);
1606 gen_debug_safety_crash(g, PanicMsgIdIntegerOverflow);1606 gen_safety_crash(g, PanicMsgIdIntegerOverflow);
16071607
1608 LLVMPositionBuilderAtEnd(g->builder, overflow_ok_block);1608 LLVMPositionBuilderAtEnd(g->builder, overflow_ok_block);
1609 }1609 }
...@@ -1615,7 +1615,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m...@@ -1615,7 +1615,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m
1615 case DivKindFloat:1615 case DivKindFloat:
1616 return result;1616 return result;
1617 case DivKindExact:1617 case DivKindExact:
1618 if (want_debug_safety) {1618 if (want_runtime_safety) {
1619 LLVMValueRef floored = gen_floor(g, result, type_entry);1619 LLVMValueRef floored = gen_floor(g, result, type_entry);
1620 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "DivExactOk");1620 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "DivExactOk");
1621 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "DivExactFail");1621 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "DivExactFail");
...@@ -1624,7 +1624,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m...@@ -1624,7 +1624,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m
1624 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);1624 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
16251625
1626 LLVMPositionBuilderAtEnd(g->builder, fail_block);1626 LLVMPositionBuilderAtEnd(g->builder, fail_block);
1627 gen_debug_safety_crash(g, PanicMsgIdExactDivisionRemainder);1627 gen_safety_crash(g, PanicMsgIdExactDivisionRemainder);
16281628
1629 LLVMPositionBuilderAtEnd(g->builder, ok_block);1629 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1630 }1630 }
...@@ -1672,7 +1672,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m...@@ -1672,7 +1672,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m
1672 return LLVMBuildUDiv(g->builder, val1, val2, "");1672 return LLVMBuildUDiv(g->builder, val1, val2, "");
1673 }1673 }
1674 case DivKindExact:1674 case DivKindExact:
1675 if (want_debug_safety) {1675 if (want_runtime_safety) {
1676 LLVMValueRef remainder_val;1676 LLVMValueRef remainder_val;
1677 if (type_entry->data.integral.is_signed) {1677 if (type_entry->data.integral.is_signed) {
1678 remainder_val = LLVMBuildSRem(g->builder, val1, val2, "");1678 remainder_val = LLVMBuildSRem(g->builder, val1, val2, "");
...@@ -1686,7 +1686,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m...@@ -1686,7 +1686,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m
1686 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);1686 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
16871687
1688 LLVMPositionBuilderAtEnd(g->builder, fail_block);1688 LLVMPositionBuilderAtEnd(g->builder, fail_block);
1689 gen_debug_safety_crash(g, PanicMsgIdExactDivisionRemainder);1689 gen_safety_crash(g, PanicMsgIdExactDivisionRemainder);
16901690
1691 LLVMPositionBuilderAtEnd(g->builder, ok_block);1691 LLVMPositionBuilderAtEnd(g->builder, ok_block);
1692 }1692 }
...@@ -1724,14 +1724,14 @@ enum RemKind {...@@ -1724,14 +1724,14 @@ enum RemKind {
1724 RemKindMod,1724 RemKindMod,
1725};1725};
17261726
1727static LLVMValueRef gen_rem(CodeGen *g, bool want_debug_safety, bool want_fast_math,1727static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast_math,
1728 LLVMValueRef val1, LLVMValueRef val2,1728 LLVMValueRef val1, LLVMValueRef val2,
1729 TypeTableEntry *type_entry, RemKind rem_kind)1729 TypeTableEntry *type_entry, RemKind rem_kind)
1730{1730{
1731 ZigLLVMSetFastMath(g->builder, want_fast_math);1731 ZigLLVMSetFastMath(g->builder, want_fast_math);
17321732
1733 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);1733 LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
1734 if (want_debug_safety) {1734 if (want_runtime_safety) {
1735 LLVMValueRef is_zero_bit;1735 LLVMValueRef is_zero_bit;
1736 if (type_entry->id == TypeTableEntryIdInt) {1736 if (type_entry->id == TypeTableEntryIdInt) {
1737 LLVMIntPredicate pred = type_entry->data.integral.is_signed ? LLVMIntSLE : LLVMIntEQ;1737 LLVMIntPredicate pred = type_entry->data.integral.is_signed ? LLVMIntSLE : LLVMIntEQ;
...@@ -1746,7 +1746,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_debug_safety, bool want_fast_m...@@ -1746,7 +1746,7 @@ static LLVMValueRef gen_rem(CodeGen *g, bool want_debug_safety, bool want_fast_m
1746 LLVMBuildCondBr(g->builder, is_zero_bit, rem_zero_fail_block, rem_zero_ok_block);1746 LLVMBuildCondBr(g->builder, is_zero_bit, rem_zero_fail_block, rem_zero_ok_block);
17471747
1748 LLVMPositionBuilderAtEnd(g->builder, rem_zero_fail_block);1748 LLVMPositionBuilderAtEnd(g->builder, rem_zero_fail_block);
1749 gen_debug_safety_crash(g, PanicMsgIdRemainderDivisionByZero);1749 gen_safety_crash(g, PanicMsgIdRemainderDivisionByZero);
17501750
1751 LLVMPositionBuilderAtEnd(g->builder, rem_zero_ok_block);1751 LLVMPositionBuilderAtEnd(g->builder, rem_zero_ok_block);
1752 }1752 }
...@@ -1792,8 +1792,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -1792,8 +1792,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
1792 op_id == IrBinOpBitShiftRightExact);1792 op_id == IrBinOpBitShiftRightExact);
1793 TypeTableEntry *type_entry = op1->value.type;1793 TypeTableEntry *type_entry = op1->value.type;
17941794
1795 bool want_debug_safety = bin_op_instruction->safety_check_on &&1795 bool want_runtime_safety = bin_op_instruction->safety_check_on &&
1796 ir_want_debug_safety(g, &bin_op_instruction->base);1796 ir_want_runtime_safety(g, &bin_op_instruction->base);
17971797
1798 LLVMValueRef op1_value = ir_llvm_value(g, op1);1798 LLVMValueRef op1_value = ir_llvm_value(g, op1);
1799 LLVMValueRef op2_value = ir_llvm_value(g, op2);1799 LLVMValueRef op2_value = ir_llvm_value(g, op2);
...@@ -1841,7 +1841,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -1841,7 +1841,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
1841 bool is_wrapping = (op_id == IrBinOpAddWrap);1841 bool is_wrapping = (op_id == IrBinOpAddWrap);
1842 if (is_wrapping) {1842 if (is_wrapping) {
1843 return LLVMBuildAdd(g->builder, op1_value, op2_value, "");1843 return LLVMBuildAdd(g->builder, op1_value, op2_value, "");
1844 } else if (want_debug_safety) {1844 } else if (want_runtime_safety) {
1845 return gen_overflow_op(g, type_entry, AddSubMulAdd, op1_value, op2_value);1845 return gen_overflow_op(g, type_entry, AddSubMulAdd, op1_value, op2_value);
1846 } else if (type_entry->data.integral.is_signed) {1846 } else if (type_entry->data.integral.is_signed) {
1847 return LLVMBuildNSWAdd(g->builder, op1_value, op2_value, "");1847 return LLVMBuildNSWAdd(g->builder, op1_value, op2_value, "");
...@@ -1866,7 +1866,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -1866,7 +1866,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
1866 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);1866 bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);
1867 if (is_sloppy) {1867 if (is_sloppy) {
1868 return LLVMBuildShl(g->builder, op1_value, op2_casted, "");1868 return LLVMBuildShl(g->builder, op1_value, op2_casted, "");
1869 } else if (want_debug_safety) {1869 } else if (want_runtime_safety) {
1870 return gen_overflow_shl_op(g, type_entry, op1_value, op2_casted);1870 return gen_overflow_shl_op(g, type_entry, op1_value, op2_casted);
1871 } else if (type_entry->data.integral.is_signed) {1871 } else if (type_entry->data.integral.is_signed) {
1872 return ZigLLVMBuildNSWShl(g->builder, op1_value, op2_casted, "");1872 return ZigLLVMBuildNSWShl(g->builder, op1_value, op2_casted, "");
...@@ -1887,7 +1887,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -1887,7 +1887,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
1887 } else {1887 } else {
1888 return LLVMBuildLShr(g->builder, op1_value, op2_casted, "");1888 return LLVMBuildLShr(g->builder, op1_value, op2_casted, "");
1889 }1889 }
1890 } else if (want_debug_safety) {1890 } else if (want_runtime_safety) {
1891 return gen_overflow_shr_op(g, type_entry, op1_value, op2_casted);1891 return gen_overflow_shr_op(g, type_entry, op1_value, op2_casted);
1892 } else if (type_entry->data.integral.is_signed) {1892 } else if (type_entry->data.integral.is_signed) {
1893 return ZigLLVMBuildAShrExact(g->builder, op1_value, op2_casted, "");1893 return ZigLLVMBuildAShrExact(g->builder, op1_value, op2_casted, "");
...@@ -1904,7 +1904,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -1904,7 +1904,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
1904 bool is_wrapping = (op_id == IrBinOpSubWrap);1904 bool is_wrapping = (op_id == IrBinOpSubWrap);
1905 if (is_wrapping) {1905 if (is_wrapping) {
1906 return LLVMBuildSub(g->builder, op1_value, op2_value, "");1906 return LLVMBuildSub(g->builder, op1_value, op2_value, "");
1907 } else if (want_debug_safety) {1907 } else if (want_runtime_safety) {
1908 return gen_overflow_op(g, type_entry, AddSubMulSub, op1_value, op2_value);1908 return gen_overflow_op(g, type_entry, AddSubMulSub, op1_value, op2_value);
1909 } else if (type_entry->data.integral.is_signed) {1909 } else if (type_entry->data.integral.is_signed) {
1910 return LLVMBuildNSWSub(g->builder, op1_value, op2_value, "");1910 return LLVMBuildNSWSub(g->builder, op1_value, op2_value, "");
...@@ -1923,7 +1923,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -1923,7 +1923,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
1923 bool is_wrapping = (op_id == IrBinOpMultWrap);1923 bool is_wrapping = (op_id == IrBinOpMultWrap);
1924 if (is_wrapping) {1924 if (is_wrapping) {
1925 return LLVMBuildMul(g->builder, op1_value, op2_value, "");1925 return LLVMBuildMul(g->builder, op1_value, op2_value, "");
1926 } else if (want_debug_safety) {1926 } else if (want_runtime_safety) {
1927 return gen_overflow_op(g, type_entry, AddSubMulMul, op1_value, op2_value);1927 return gen_overflow_op(g, type_entry, AddSubMulMul, op1_value, op2_value);
1928 } else if (type_entry->data.integral.is_signed) {1928 } else if (type_entry->data.integral.is_signed) {
1929 return LLVMBuildNSWMul(g->builder, op1_value, op2_value, "");1929 return LLVMBuildNSWMul(g->builder, op1_value, op2_value, "");
...@@ -1934,22 +1934,22 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,...@@ -1934,22 +1934,22 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
1934 zig_unreachable();1934 zig_unreachable();
1935 }1935 }
1936 case IrBinOpDivUnspecified:1936 case IrBinOpDivUnspecified:
1937 return gen_div(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),1937 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
1938 op1_value, op2_value, type_entry, DivKindFloat);1938 op1_value, op2_value, type_entry, DivKindFloat);
1939 case IrBinOpDivExact:1939 case IrBinOpDivExact:
1940 return gen_div(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),1940 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
1941 op1_value, op2_value, type_entry, DivKindExact);1941 op1_value, op2_value, type_entry, DivKindExact);
1942 case IrBinOpDivTrunc:1942 case IrBinOpDivTrunc:
1943 return gen_div(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),1943 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
1944 op1_value, op2_value, type_entry, DivKindTrunc);1944 op1_value, op2_value, type_entry, DivKindTrunc);
1945 case IrBinOpDivFloor:1945 case IrBinOpDivFloor:
1946 return gen_div(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),1946 return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
1947 op1_value, op2_value, type_entry, DivKindFloor);1947 op1_value, op2_value, type_entry, DivKindFloor);
1948 case IrBinOpRemRem:1948 case IrBinOpRemRem:
1949 return gen_rem(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),1949 return gen_rem(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
1950 op1_value, op2_value, type_entry, RemKindRem);1950 op1_value, op2_value, type_entry, RemKindRem);
1951 case IrBinOpRemMod:1951 case IrBinOpRemMod:
1952 return gen_rem(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),1952 return gen_rem(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
1953 op1_value, op2_value, type_entry, RemKindMod);1953 op1_value, op2_value, type_entry, RemKindMod);
1954 }1954 }
1955 zig_unreachable();1955 zig_unreachable();
...@@ -2007,7 +2007,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2007,7 +2007,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2007 new_len = LLVMBuildMul(g->builder, src_len, src_size_val, "");2007 new_len = LLVMBuildMul(g->builder, src_len, src_size_val, "");
2008 } else if (src_size == 1) {2008 } else if (src_size == 1) {
2009 LLVMValueRef dest_size_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, dest_size, false);2009 LLVMValueRef dest_size_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, dest_size, false);
2010 if (ir_want_debug_safety(g, &cast_instruction->base)) {2010 if (ir_want_runtime_safety(g, &cast_instruction->base)) {
2011 LLVMValueRef remainder_val = LLVMBuildURem(g->builder, src_len, dest_size_val, "");2011 LLVMValueRef remainder_val = LLVMBuildURem(g->builder, src_len, dest_size_val, "");
2012 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_usize->type_ref);2012 LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_usize->type_ref);
2013 LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, remainder_val, zero, "");2013 LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, remainder_val, zero, "");
...@@ -2016,7 +2016,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,...@@ -2016,7 +2016,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
2016 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);2016 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
20172017
2018 LLVMPositionBuilderAtEnd(g->builder, fail_block);2018 LLVMPositionBuilderAtEnd(g->builder, fail_block);
2019 gen_debug_safety_crash(g, PanicMsgIdSliceWidenRemainder);2019 gen_safety_crash(g, PanicMsgIdSliceWidenRemainder);
20202020
2021 LLVMPositionBuilderAtEnd(g->builder, ok_block);2021 LLVMPositionBuilderAtEnd(g->builder, ok_block);
2022 }2022 }
...@@ -2111,7 +2111,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa...@@ -2111,7 +2111,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
2111 int_type = actual_type;2111 int_type = actual_type;
2112 }2112 }
2113 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);2113 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
2114 return gen_widen_or_shorten(g, ir_want_debug_safety(g, &instruction->base), int_type,2114 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base), int_type,
2115 instruction->base.value.type, target_val);2115 instruction->base.value.type, target_val);
2116}2116}
21172117
...@@ -2133,7 +2133,7 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,...@@ -2133,7 +2133,7 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
2133 TypeTableEntry *tag_int_type = wanted_type->data.enumeration.tag_int_type;2133 TypeTableEntry *tag_int_type = wanted_type->data.enumeration.tag_int_type;
21342134
2135 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);2135 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
2136 return gen_widen_or_shorten(g, ir_want_debug_safety(g, &instruction->base),2136 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
2137 instruction->target->value.type, tag_int_type, target_val);2137 instruction->target->value.type, tag_int_type, target_val);
2138}2138}
21392139
...@@ -2147,7 +2147,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I...@@ -2147,7 +2147,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
21472147
2148 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);2148 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
21492149
2150 if (ir_want_debug_safety(g, &instruction->base)) {2150 if (ir_want_runtime_safety(g, &instruction->base)) {
2151 LLVMValueRef zero = LLVMConstNull(actual_type->type_ref);2151 LLVMValueRef zero = LLVMConstNull(actual_type->type_ref);
2152 LLVMValueRef neq_zero_bit = LLVMBuildICmp(g->builder, LLVMIntNE, target_val, zero, "");2152 LLVMValueRef neq_zero_bit = LLVMBuildICmp(g->builder, LLVMIntNE, target_val, zero, "");
2153 LLVMValueRef ok_bit;2153 LLVMValueRef ok_bit;
...@@ -2171,7 +2171,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I...@@ -2171,7 +2171,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
2171 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);2171 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
21722172
2173 LLVMPositionBuilderAtEnd(g->builder, fail_block);2173 LLVMPositionBuilderAtEnd(g->builder, fail_block);
2174 gen_debug_safety_crash(g, PanicMsgIdInvalidErrorCode);2174 gen_safety_crash(g, PanicMsgIdInvalidErrorCode);
21752175
2176 LLVMPositionBuilderAtEnd(g->builder, ok_block);2176 LLVMPositionBuilderAtEnd(g->builder, ok_block);
2177 }2177 }
...@@ -2188,11 +2188,11 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I...@@ -2188,11 +2188,11 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I
2188 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);2188 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
21892189
2190 if (actual_type->id == TypeTableEntryIdPureError) {2190 if (actual_type->id == TypeTableEntryIdPureError) {
2191 return gen_widen_or_shorten(g, ir_want_debug_safety(g, &instruction->base),2191 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
2192 g->err_tag_type, wanted_type, target_val);2192 g->err_tag_type, wanted_type, target_val);
2193 } else if (actual_type->id == TypeTableEntryIdErrorUnion) {2193 } else if (actual_type->id == TypeTableEntryIdErrorUnion) {
2194 if (!type_has_bits(actual_type->data.error.child_type)) {2194 if (!type_has_bits(actual_type->data.error.child_type)) {
2195 return gen_widen_or_shorten(g, ir_want_debug_safety(g, &instruction->base),2195 return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
2196 g->err_tag_type, wanted_type, target_val);2196 g->err_tag_type, wanted_type, target_val);
2197 } else {2197 } else {
2198 zig_panic("TODO");2198 zig_panic("TODO");
...@@ -2205,8 +2205,8 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I...@@ -2205,8 +2205,8 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I
2205static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,2205static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
2206 IrInstructionUnreachable *unreachable_instruction)2206 IrInstructionUnreachable *unreachable_instruction)
2207{2207{
2208 if (ir_want_debug_safety(g, &unreachable_instruction->base)) {2208 if (ir_want_runtime_safety(g, &unreachable_instruction->base)) {
2209 gen_debug_safety_crash(g, PanicMsgIdUnreachable);2209 gen_safety_crash(g, PanicMsgIdUnreachable);
2210 } else {2210 } else {
2211 LLVMBuildUnreachable(g->builder);2211 LLVMBuildUnreachable(g->builder);
2212 }2212 }
...@@ -2248,7 +2248,7 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst...@@ -2248,7 +2248,7 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst
2248 } else if (expr_type->id == TypeTableEntryIdInt) {2248 } else if (expr_type->id == TypeTableEntryIdInt) {
2249 if (op_id == IrUnOpNegationWrap) {2249 if (op_id == IrUnOpNegationWrap) {
2250 return LLVMBuildNeg(g->builder, expr, "");2250 return LLVMBuildNeg(g->builder, expr, "");
2251 } else if (ir_want_debug_safety(g, &un_op_instruction->base)) {2251 } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {
2252 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(expr));2252 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(expr));
2253 return gen_overflow_op(g, expr_type, AddSubMulSub, zero, expr);2253 return gen_overflow_op(g, expr_type, AddSubMulSub, zero, expr);
2254 } else if (expr_type->data.integral.is_signed) {2254 } else if (expr_type->data.integral.is_signed) {
...@@ -2317,7 +2317,7 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,...@@ -2317,7 +2317,7 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
2317 var->align_bytes, 0, 0);2317 var->align_bytes, 0, 0);
2318 gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value));2318 gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value));
2319 } else {2319 } else {
2320 bool want_safe = ir_want_debug_safety(g, &decl_var_instruction->base);2320 bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base);
2321 if (want_safe) {2321 if (want_safe) {
2322 TypeTableEntry *usize = g->builtin_types.entry_usize;2322 TypeTableEntry *usize = g->builtin_types.entry_usize;
2323 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value->type->type_ref);2323 uint64_t size_bytes = LLVMStoreSizeOfType(g->target_data_ref, var->value->type->type_ref);
...@@ -2409,7 +2409,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI...@@ -2409,7 +2409,7 @@ static LLVMValueRef ir_render_elem_ptr(CodeGen *g, IrExecutable *executable, IrI
2409 if (!type_has_bits(array_type))2409 if (!type_has_bits(array_type))
2410 return nullptr;2410 return nullptr;
24112411
2412 bool safety_check_on = ir_want_debug_safety(g, &instruction->base) && instruction->safety_check_on;2412 bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on;
24132413
2414 if (array_type->id == TypeTableEntryIdArray) {2414 if (array_type->id == TypeTableEntryIdArray) {
2415 if (safety_check_on) {2415 if (safety_check_on) {
...@@ -2593,7 +2593,7 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab...@@ -2593,7 +2593,7 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab
2593 return bitcasted_union_field_ptr;2593 return bitcasted_union_field_ptr;
2594 }2594 }
25952595
2596 if (ir_want_debug_safety(g, &instruction->base)) {2596 if (ir_want_runtime_safety(g, &instruction->base)) {
2597 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_ptr, union_type->data.unionation.gen_tag_index, "");2597 LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_ptr, union_type->data.unionation.gen_tag_index, "");
2598 LLVMValueRef tag_value = gen_load_untyped(g, tag_field_ptr, 0, false, "");2598 LLVMValueRef tag_value = gen_load_untyped(g, tag_field_ptr, 0, false, "");
25992599
...@@ -2606,7 +2606,7 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab...@@ -2606,7 +2606,7 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab
2606 LLVMBuildCondBr(g->builder, ok_val, ok_block, bad_block);2606 LLVMBuildCondBr(g->builder, ok_val, ok_block, bad_block);
26072607
2608 LLVMPositionBuilderAtEnd(g->builder, bad_block);2608 LLVMPositionBuilderAtEnd(g->builder, bad_block);
2609 gen_debug_safety_crash(g, PanicMsgIdBadUnionField);2609 gen_safety_crash(g, PanicMsgIdBadUnionField);
26102610
2611 LLVMPositionBuilderAtEnd(g->builder, ok_block);2611 LLVMPositionBuilderAtEnd(g->builder, ok_block);
2612 }2612 }
...@@ -2776,14 +2776,14 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,...@@ -2776,14 +2776,14 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
2776 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;2776 TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
2777 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);2777 LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);
2778 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);2778 LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);
2779 if (ir_want_debug_safety(g, &instruction->base) && instruction->safety_check_on) {2779 if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on) {
2780 LLVMValueRef non_null_bit = gen_non_null_bit(g, maybe_type, maybe_handle);2780 LLVMValueRef non_null_bit = gen_non_null_bit(g, maybe_type, maybe_handle);
2781 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeOk");2781 LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeOk");
2782 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeFail");2782 LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeFail");
2783 LLVMBuildCondBr(g->builder, non_null_bit, ok_block, fail_block);2783 LLVMBuildCondBr(g->builder, non_null_bit, ok_block, fail_block);
27842784
2785 LLVMPositionBuilderAtEnd(g->builder, fail_block);2785 LLVMPositionBuilderAtEnd(g->builder, fail_block);
2786 gen_debug_safety_crash(g, PanicMsgIdUnwrapMaybeFail);2786 gen_safety_crash(g, PanicMsgIdUnwrapMaybeFail);
27872787
2788 LLVMPositionBuilderAtEnd(g->builder, ok_block);2788 LLVMPositionBuilderAtEnd(g->builder, ok_block);
2789 }2789 }
...@@ -2913,7 +2913,7 @@ static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrI...@@ -2913,7 +2913,7 @@ static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrI
2913 }2913 }
29142914
2915 LLVMValueRef err_val = ir_llvm_value(g, instruction->value);2915 LLVMValueRef err_val = ir_llvm_value(g, instruction->value);
2916 if (ir_want_debug_safety(g, &instruction->base)) {2916 if (ir_want_runtime_safety(g, &instruction->base)) {
2917 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(err_val));2917 LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(err_val));
2918 LLVMValueRef end_val = LLVMConstInt(LLVMTypeOf(err_val), g->error_decls.length, false);2918 LLVMValueRef end_val = LLVMConstInt(LLVMTypeOf(err_val), g->error_decls.length, false);
2919 add_bounds_check(g, err_val, LLVMIntNE, zero, LLVMIntULT, end_val);2919 add_bounds_check(g, err_val, LLVMIntNE, zero, LLVMIntULT, end_val);
...@@ -2935,7 +2935,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable...@@ -2935,7 +2935,7 @@ static LLVMValueRef ir_render_enum_tag_name(CodeGen *g, IrExecutable *executable
29352935
2936 TypeTableEntry *tag_int_type = enum_type->data.enumeration.tag_int_type;2936 TypeTableEntry *tag_int_type = enum_type->data.enumeration.tag_int_type;
2937 LLVMValueRef enum_tag_value = ir_llvm_value(g, instruction->target);2937 LLVMValueRef enum_tag_value = ir_llvm_value(g, instruction->target);
2938 if (ir_want_debug_safety(g, &instruction->base)) {2938 if (ir_want_runtime_safety(g, &instruction->base)) {
2939 size_t field_count = enum_type->data.enumeration.src_field_count;2939 size_t field_count = enum_type->data.enumeration.src_field_count;
29402940
2941 // if the field_count can't fit in the bits of the enum_type, then it can't possibly2941 // if the field_count can't fit in the bits of the enum_type, then it can't possibly
...@@ -2988,8 +2988,8 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I...@@ -2988,8 +2988,8 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
2988 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);2988 LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
2989 assert(target_val);2989 assert(target_val);
29902990
2991 bool want_debug_safety = ir_want_debug_safety(g, &instruction->base);2991 bool want_runtime_safety = ir_want_runtime_safety(g, &instruction->base);
2992 if (!want_debug_safety) {2992 if (!want_runtime_safety) {
2993 return target_val;2993 return target_val;
2994 }2994 }
29952995
...@@ -3038,7 +3038,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I...@@ -3038,7 +3038,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
3038 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);3038 LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
30393039
3040 LLVMPositionBuilderAtEnd(g->builder, fail_block);3040 LLVMPositionBuilderAtEnd(g->builder, fail_block);
3041 gen_debug_safety_crash(g, PanicMsgIdIncorrectAlignment);3041 gen_safety_crash(g, PanicMsgIdIncorrectAlignment);
30423042
3043 LLVMPositionBuilderAtEnd(g->builder, ok_block);3043 LLVMPositionBuilderAtEnd(g->builder, ok_block);
30443044
...@@ -3176,7 +3176,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -3176,7 +3176,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
31763176
3177 LLVMValueRef tmp_struct_ptr = instruction->tmp_ptr;3177 LLVMValueRef tmp_struct_ptr = instruction->tmp_ptr;
31783178
3179 bool want_debug_safety = instruction->safety_check_on && ir_want_debug_safety(g, &instruction->base);3179 bool want_runtime_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base);
31803180
3181 if (array_type->id == TypeTableEntryIdArray) {3181 if (array_type->id == TypeTableEntryIdArray) {
3182 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);3182 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
...@@ -3187,7 +3187,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -3187,7 +3187,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
3187 end_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, array_type->data.array.len, false);3187 end_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, array_type->data.array.len, false);
3188 }3188 }
31893189
3190 if (want_debug_safety) {3190 if (want_runtime_safety) {
3191 add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);3191 add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);
3192 if (instruction->end) {3192 if (instruction->end) {
3193 LLVMValueRef array_end = LLVMConstInt(g->builtin_types.entry_usize->type_ref,3193 LLVMValueRef array_end = LLVMConstInt(g->builtin_types.entry_usize->type_ref,
...@@ -3198,7 +3198,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -3198,7 +3198,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
3198 if (!type_has_bits(array_type)) {3198 if (!type_has_bits(array_type)) {
3199 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, slice_len_index, "");3199 LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, slice_len_index, "");
32003200
3201 // TODO if debug safety is on, store 0xaaaaaaa in ptr field3201 // TODO if runtime safety is on, store 0xaaaaaaa in ptr field
3202 LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");3202 LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");
3203 gen_store_untyped(g, len_value, len_field_ptr, 0, false);3203 gen_store_untyped(g, len_value, len_field_ptr, 0, false);
3204 return tmp_struct_ptr;3204 return tmp_struct_ptr;
...@@ -3222,7 +3222,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -3222,7 +3222,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
3222 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);3222 LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
3223 LLVMValueRef end_val = ir_llvm_value(g, instruction->end);3223 LLVMValueRef end_val = ir_llvm_value(g, instruction->end);
32243224
3225 if (want_debug_safety) {3225 if (want_runtime_safety) {
3226 add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);3226 add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);
3227 }3227 }
32283228
...@@ -3246,7 +3246,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -3246,7 +3246,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
3246 assert(len_index != SIZE_MAX);3246 assert(len_index != SIZE_MAX);
32473247
3248 LLVMValueRef prev_end = nullptr;3248 LLVMValueRef prev_end = nullptr;
3249 if (!instruction->end || want_debug_safety) {3249 if (!instruction->end || want_runtime_safety) {
3250 LLVMValueRef src_len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)len_index, "");3250 LLVMValueRef src_len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)len_index, "");
3251 prev_end = gen_load_untyped(g, src_len_ptr, 0, false, "");3251 prev_end = gen_load_untyped(g, src_len_ptr, 0, false, "");
3252 }3252 }
...@@ -3259,7 +3259,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst...@@ -3259,7 +3259,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
3259 end_val = prev_end;3259 end_val = prev_end;
3260 }3260 }
32613261
3262 if (want_debug_safety) {3262 if (want_runtime_safety) {
3263 assert(prev_end);3263 assert(prev_end);
3264 add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);3264 add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);
3265 if (instruction->end) {3265 if (instruction->end) {
...@@ -3432,7 +3432,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu...@@ -3432,7 +3432,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
3432 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);3432 LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
3433 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);3433 LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);
34343434
3435 if (ir_want_debug_safety(g, &instruction->base) && instruction->safety_check_on && g->error_decls.length > 1) {3435 if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on && g->error_decls.length > 1) {
3436 LLVMValueRef err_val;3436 LLVMValueRef err_val;
3437 if (type_has_bits(child_type)) {3437 if (type_has_bits(child_type)) {
3438 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");3438 LLVMValueRef err_val_ptr = LLVMBuildStructGEP(g->builder, err_union_handle, err_union_err_index, "");
...@@ -3447,7 +3447,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu...@@ -3447,7 +3447,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
3447 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);3447 LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);
34483448
3449 LLVMPositionBuilderAtEnd(g->builder, err_block);3449 LLVMPositionBuilderAtEnd(g->builder, err_block);
3450 gen_debug_safety_crash_for_err(g, err_val);3450 gen_safety_crash_for_err(g, err_val);
34513451
3452 LLVMPositionBuilderAtEnd(g->builder, ok_block);3452 LLVMPositionBuilderAtEnd(g->builder, ok_block);
3453 }3453 }
...@@ -3660,7 +3660,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,...@@ -3660,7 +3660,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
3660 case IrInstructionIdPtrTypeChild:3660 case IrInstructionIdPtrTypeChild:
3661 case IrInstructionIdFieldPtr:3661 case IrInstructionIdFieldPtr:
3662 case IrInstructionIdSetCold:3662 case IrInstructionIdSetCold:
3663 case IrInstructionIdSetDebugSafety:3663 case IrInstructionIdSetRuntimeSafety:
3664 case IrInstructionIdSetFloatMode:3664 case IrInstructionIdSetFloatMode:
3665 case IrInstructionIdArrayType:3665 case IrInstructionIdArrayType:
3666 case IrInstructionIdSliceType:3666 case IrInstructionIdSliceType:
...@@ -5238,7 +5238,7 @@ static void define_builtin_fns(CodeGen *g) {...@@ -5238,7 +5238,7 @@ static void define_builtin_fns(CodeGen *g) {
5238 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);5238 create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
5239 create_builtin_fn(g, BuiltinFnIdIntType, "IntType", 2); // TODO rename to Int5239 create_builtin_fn(g, BuiltinFnIdIntType, "IntType", 2); // TODO rename to Int
5240 create_builtin_fn(g, BuiltinFnIdSetCold, "setCold", 1);5240 create_builtin_fn(g, BuiltinFnIdSetCold, "setCold", 1);
5241 create_builtin_fn(g, BuiltinFnIdSetDebugSafety, "setDebugSafety", 2);5241 create_builtin_fn(g, BuiltinFnIdSetRuntimeSafety, "setRuntimeSafety", 1);
5242 create_builtin_fn(g, BuiltinFnIdSetFloatMode, "setFloatMode", 2);5242 create_builtin_fn(g, BuiltinFnIdSetFloatMode, "setFloatMode", 2);
5243 create_builtin_fn(g, BuiltinFnIdPanic, "panic", 1);5243 create_builtin_fn(g, BuiltinFnIdPanic, "panic", 1);
5244 create_builtin_fn(g, BuiltinFnIdPtrCast, "ptrCast", 2);5244 create_builtin_fn(g, BuiltinFnIdPtrCast, "ptrCast", 2);
src/ir.cpp+46-65
...@@ -276,8 +276,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSetCold *) {...@@ -276,8 +276,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSetCold *) {
276 return IrInstructionIdSetCold;276 return IrInstructionIdSetCold;
277}277}
278278
279static constexpr IrInstructionId ir_instruction_id(IrInstructionSetDebugSafety *) {279static constexpr IrInstructionId ir_instruction_id(IrInstructionSetRuntimeSafety *) {
280 return IrInstructionIdSetDebugSafety;280 return IrInstructionIdSetRuntimeSafety;
281}281}
282282
283static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFloatMode *) {283static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFloatMode *) {
...@@ -1275,15 +1275,13 @@ static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *s...@@ -1275,15 +1275,13 @@ static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *s
1275 return &instruction->base;1275 return &instruction->base;
1276}1276}
12771277
1278static IrInstruction *ir_build_set_debug_safety(IrBuilder *irb, Scope *scope, AstNode *source_node,1278static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope, AstNode *source_node,
1279 IrInstruction *scope_value, IrInstruction *debug_safety_on)1279 IrInstruction *safety_on)
1280{1280{
1281 IrInstructionSetDebugSafety *instruction = ir_build_instruction<IrInstructionSetDebugSafety>(irb, scope, source_node);1281 IrInstructionSetRuntimeSafety *instruction = ir_build_instruction<IrInstructionSetRuntimeSafety>(irb, scope, source_node);
1282 instruction->scope_value = scope_value;1282 instruction->safety_on = safety_on;
1283 instruction->debug_safety_on = debug_safety_on;
12841283
1285 ir_ref_instruction(scope_value, irb->current_basic_block);1284 ir_ref_instruction(safety_on, irb->current_basic_block);
1286 ir_ref_instruction(debug_safety_on, irb->current_basic_block);
12871285
1288 return &instruction->base;1286 return &instruction->base;
1289}1287}
...@@ -3087,19 +3085,14 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo...@@ -3087,19 +3085,14 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
30873085
3088 return ir_build_set_cold(irb, scope, node, arg0_value);3086 return ir_build_set_cold(irb, scope, node, arg0_value);
3089 }3087 }
3090 case BuiltinFnIdSetDebugSafety:3088 case BuiltinFnIdSetRuntimeSafety:
3091 {3089 {
3092 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);3090 AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
3093 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);3091 IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
3094 if (arg0_value == irb->codegen->invalid_instruction)3092 if (arg0_value == irb->codegen->invalid_instruction)
3095 return arg0_value;3093 return arg0_value;
30963094
3097 AstNode *arg1_node = node->data.fn_call_expr.params.at(1);3095 return ir_build_set_runtime_safety(irb, scope, node, arg0_value);
3098 IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
3099 if (arg1_value == irb->codegen->invalid_instruction)
3100 return arg1_value;
3101
3102 return ir_build_set_debug_safety(irb, scope, node, arg0_value, arg1_value);
3103 }3096 }
3104 case BuiltinFnIdSetFloatMode:3097 case BuiltinFnIdSetFloatMode:
3105 {3098 {
...@@ -11607,72 +11600,60 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc...@@ -11607,72 +11600,60 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc
11607 ir_build_const_from(ira, &instruction->base);11600 ir_build_const_from(ira, &instruction->base);
11608 return ira->codegen->builtin_types.entry_void;11601 return ira->codegen->builtin_types.entry_void;
11609}11602}
11610static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,11603static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
11611 IrInstructionSetDebugSafety *set_debug_safety_instruction)11604 IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)
11612{11605{
11613 IrInstruction *target_instruction = set_debug_safety_instruction->scope_value->other;
11614 TypeTableEntry *target_type = target_instruction->value.type;
11615 if (type_is_invalid(target_type))
11616 return ira->codegen->builtin_types.entry_invalid;
11617 ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);
11618 if (!target_val)
11619 return ira->codegen->builtin_types.entry_invalid;
11620
11621 if (ira->new_irb.exec->is_inline) {11606 if (ira->new_irb.exec->is_inline) {
11622 // ignore setDebugSafety when running functions at compile time11607 // ignore setRuntimeSafety when running functions at compile time
11623 ir_build_const_from(ira, &set_debug_safety_instruction->base);11608 ir_build_const_from(ira, &set_runtime_safety_instruction->base);
11624 return ira->codegen->builtin_types.entry_void;11609 return ira->codegen->builtin_types.entry_void;
11625 }11610 }
1162611611
11627 bool *safety_off_ptr;11612 bool *safety_off_ptr;
11628 AstNode **safety_set_node_ptr;11613 AstNode **safety_set_node_ptr;
11629 if (target_type->id == TypeTableEntryIdBlock) {11614
11630 ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block;11615 Scope *scope = set_runtime_safety_instruction->base.scope;
11631 safety_off_ptr = &block_scope->safety_off;11616 while (scope != nullptr) {
11632 safety_set_node_ptr = &block_scope->safety_set_node;11617 if (scope->id == ScopeIdBlock) {
11633 } else if (target_type->id == TypeTableEntryIdFn) {11618 ScopeBlock *block_scope = (ScopeBlock *)scope;
11634 FnTableEntry *target_fn = target_val->data.x_fn.fn_entry;11619 safety_off_ptr = &block_scope->safety_off;
11635 assert(target_fn->def_scope);11620 safety_set_node_ptr = &block_scope->safety_set_node;
11636 safety_off_ptr = &target_fn->def_scope->safety_off;11621 break;
11637 safety_set_node_ptr = &target_fn->def_scope->safety_set_node;11622 } else if (scope->id == ScopeIdFnDef) {
11638 } else if (target_type->id == TypeTableEntryIdMetaType) {11623 ScopeFnDef *def_scope = (ScopeFnDef *)scope;
11639 ScopeDecls *decls_scope;11624 FnTableEntry *target_fn = def_scope->fn_entry;
11640 TypeTableEntry *type_arg = target_val->data.x_type;11625 assert(target_fn->def_scope != nullptr);
11641 if (type_arg->id == TypeTableEntryIdStruct) {11626 safety_off_ptr = &target_fn->def_scope->safety_off;
11642 decls_scope = type_arg->data.structure.decls_scope;11627 safety_set_node_ptr = &target_fn->def_scope->safety_set_node;
11643 } else if (type_arg->id == TypeTableEntryIdEnum) {11628 break;
11644 decls_scope = type_arg->data.enumeration.decls_scope;11629 } else if (scope->id == ScopeIdDecls) {
11645 } else if (type_arg->id == TypeTableEntryIdUnion) {11630 ScopeDecls *decls_scope = (ScopeDecls *)scope;
11646 decls_scope = type_arg->data.unionation.decls_scope;11631 safety_off_ptr = &decls_scope->safety_off;
11632 safety_set_node_ptr = &decls_scope->safety_set_node;
11633 break;
11647 } else {11634 } else {
11648 ir_add_error_node(ira, target_instruction->source_node,11635 scope = scope->parent;
11649 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));11636 continue;
11650 return ira->codegen->builtin_types.entry_invalid;
11651 }11637 }
11652 safety_off_ptr = &decls_scope->safety_off;
11653 safety_set_node_ptr = &decls_scope->safety_set_node;
11654 } else {
11655 ir_add_error_node(ira, target_instruction->source_node,
11656 buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name)));
11657 return ira->codegen->builtin_types.entry_invalid;
11658 }11638 }
11639 assert(scope != nullptr);
1165911640
11660 IrInstruction *debug_safety_on_value = set_debug_safety_instruction->debug_safety_on->other;11641 IrInstruction *safety_on_value = set_runtime_safety_instruction->safety_on->other;
11661 bool want_debug_safety;11642 bool want_runtime_safety;
11662 if (!ir_resolve_bool(ira, debug_safety_on_value, &want_debug_safety))11643 if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety))
11663 return ira->codegen->builtin_types.entry_invalid;11644 return ira->codegen->builtin_types.entry_invalid;
1166411645
11665 AstNode *source_node = set_debug_safety_instruction->base.source_node;11646 AstNode *source_node = set_runtime_safety_instruction->base.source_node;
11666 if (*safety_set_node_ptr) {11647 if (*safety_set_node_ptr) {
11667 ErrorMsg *msg = ir_add_error_node(ira, source_node,11648 ErrorMsg *msg = ir_add_error_node(ira, source_node,
11668 buf_sprintf("debug safety set twice for same scope"));11649 buf_sprintf("runtime safety set twice for same scope"));
11669 add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));11650 add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));
11670 return ira->codegen->builtin_types.entry_invalid;11651 return ira->codegen->builtin_types.entry_invalid;
11671 }11652 }
11672 *safety_set_node_ptr = source_node;11653 *safety_set_node_ptr = source_node;
11673 *safety_off_ptr = !want_debug_safety;11654 *safety_off_ptr = !want_runtime_safety;
1167411655
11675 ir_build_const_from(ira, &set_debug_safety_instruction->base);11656 ir_build_const_from(ira, &set_runtime_safety_instruction->base);
11676 return ira->codegen->builtin_types.entry_void;11657 return ira->codegen->builtin_types.entry_void;
11677}11658}
1167811659
...@@ -15293,8 +15274,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi...@@ -15293,8 +15274,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
15293 return ir_analyze_instruction_ptr_type_child(ira, (IrInstructionPtrTypeChild *)instruction);15274 return ir_analyze_instruction_ptr_type_child(ira, (IrInstructionPtrTypeChild *)instruction);
15294 case IrInstructionIdSetCold:15275 case IrInstructionIdSetCold:
15295 return ir_analyze_instruction_set_cold(ira, (IrInstructionSetCold *)instruction);15276 return ir_analyze_instruction_set_cold(ira, (IrInstructionSetCold *)instruction);
15296 case IrInstructionIdSetDebugSafety:15277 case IrInstructionIdSetRuntimeSafety:
15297 return ir_analyze_instruction_set_debug_safety(ira, (IrInstructionSetDebugSafety *)instruction);15278 return ir_analyze_instruction_set_runtime_safety(ira, (IrInstructionSetRuntimeSafety *)instruction);
15298 case IrInstructionIdSetFloatMode:15279 case IrInstructionIdSetFloatMode:
15299 return ir_analyze_instruction_set_float_mode(ira, (IrInstructionSetFloatMode *)instruction);15280 return ir_analyze_instruction_set_float_mode(ira, (IrInstructionSetFloatMode *)instruction);
15300 case IrInstructionIdSliceType:15281 case IrInstructionIdSliceType:
...@@ -15530,7 +15511,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {...@@ -15530,7 +15511,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
15530 case IrInstructionIdReturn:15511 case IrInstructionIdReturn:
15531 case IrInstructionIdUnreachable:15512 case IrInstructionIdUnreachable:
15532 case IrInstructionIdSetCold:15513 case IrInstructionIdSetCold:
15533 case IrInstructionIdSetDebugSafety:15514 case IrInstructionIdSetRuntimeSafety:
15534 case IrInstructionIdSetFloatMode:15515 case IrInstructionIdSetFloatMode:
15535 case IrInstructionIdImport:15516 case IrInstructionIdImport:
15536 case IrInstructionIdCompileErr:15517 case IrInstructionIdCompileErr:
src/ir_print.cpp+5-7
...@@ -374,11 +374,9 @@ static void ir_print_set_cold(IrPrint *irp, IrInstructionSetCold *instruction) {...@@ -374,11 +374,9 @@ static void ir_print_set_cold(IrPrint *irp, IrInstructionSetCold *instruction) {
374 fprintf(irp->f, ")");374 fprintf(irp->f, ")");
375}375}
376376
377static void ir_print_set_debug_safety(IrPrint *irp, IrInstructionSetDebugSafety *instruction) {377static void ir_print_set_runtime_safety(IrPrint *irp, IrInstructionSetRuntimeSafety *instruction) {
378 fprintf(irp->f, "@setDebugSafety(");378 fprintf(irp->f, "@setRuntimeSafety(");
379 ir_print_other_instruction(irp, instruction->scope_value);379 ir_print_other_instruction(irp, instruction->safety_on);
380 fprintf(irp->f, ", ");
381 ir_print_other_instruction(irp, instruction->debug_safety_on);
382 fprintf(irp->f, ")");380 fprintf(irp->f, ")");
383}381}
384382
...@@ -1090,8 +1088,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {...@@ -1090,8 +1088,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
1090 case IrInstructionIdSetCold:1088 case IrInstructionIdSetCold:
1091 ir_print_set_cold(irp, (IrInstructionSetCold *)instruction);1089 ir_print_set_cold(irp, (IrInstructionSetCold *)instruction);
1092 break;1090 break;
1093 case IrInstructionIdSetDebugSafety:1091 case IrInstructionIdSetRuntimeSafety:
1094 ir_print_set_debug_safety(irp, (IrInstructionSetDebugSafety *)instruction);1092 ir_print_set_runtime_safety(irp, (IrInstructionSetRuntimeSafety *)instruction);
1095 break;1093 break;
1096 case IrInstructionIdSetFloatMode:1094 case IrInstructionIdSetFloatMode:
1097 ir_print_set_float_mode(irp, (IrInstructionSetFloatMode *)instruction);1095 ir_print_set_float_mode(irp, (IrInstructionSetFloatMode *)instruction);
std/math/index.zig+6-6
...@@ -331,7 +331,7 @@ pub fn absInt(x: var) -> %@typeOf(x) {...@@ -331,7 +331,7 @@ pub fn absInt(x: var) -> %@typeOf(x) {
331 if (x == @minValue(@typeOf(x)))331 if (x == @minValue(@typeOf(x)))
332 return error.Overflow;332 return error.Overflow;
333 {333 {
334 @setDebugSafety(this, false);334 @setRuntimeSafety(false);
335 return if (x < 0) -x else x;335 return if (x < 0) -x else x;
336 }336 }
337}337}
...@@ -350,7 +350,7 @@ pub const absFloat = @import("fabs.zig").fabs;...@@ -350,7 +350,7 @@ pub const absFloat = @import("fabs.zig").fabs;
350error DivisionByZero;350error DivisionByZero;
351error Overflow;351error Overflow;
352pub fn divTrunc(comptime T: type, numerator: T, denominator: T) -> %T {352pub fn divTrunc(comptime T: type, numerator: T, denominator: T) -> %T {
353 @setDebugSafety(this, false);353 @setRuntimeSafety(false);
354 if (denominator == 0)354 if (denominator == 0)
355 return error.DivisionByZero;355 return error.DivisionByZero;
356 if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1)356 if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1)
...@@ -375,7 +375,7 @@ fn testDivTrunc() {...@@ -375,7 +375,7 @@ fn testDivTrunc() {
375error DivisionByZero;375error DivisionByZero;
376error Overflow;376error Overflow;
377pub fn divFloor(comptime T: type, numerator: T, denominator: T) -> %T {377pub fn divFloor(comptime T: type, numerator: T, denominator: T) -> %T {
378 @setDebugSafety(this, false);378 @setRuntimeSafety(false);
379 if (denominator == 0)379 if (denominator == 0)
380 return error.DivisionByZero;380 return error.DivisionByZero;
381 if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1)381 if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1)
...@@ -401,7 +401,7 @@ error DivisionByZero;...@@ -401,7 +401,7 @@ error DivisionByZero;
401error Overflow;401error Overflow;
402error UnexpectedRemainder;402error UnexpectedRemainder;
403pub fn divExact(comptime T: type, numerator: T, denominator: T) -> %T {403pub fn divExact(comptime T: type, numerator: T, denominator: T) -> %T {
404 @setDebugSafety(this, false);404 @setRuntimeSafety(false);
405 if (denominator == 0)405 if (denominator == 0)
406 return error.DivisionByZero;406 return error.DivisionByZero;
407 if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1)407 if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1)
...@@ -431,7 +431,7 @@ fn testDivExact() {...@@ -431,7 +431,7 @@ fn testDivExact() {
431error DivisionByZero;431error DivisionByZero;
432error NegativeDenominator;432error NegativeDenominator;
433pub fn mod(comptime T: type, numerator: T, denominator: T) -> %T {433pub fn mod(comptime T: type, numerator: T, denominator: T) -> %T {
434 @setDebugSafety(this, false);434 @setRuntimeSafety(false);
435 if (denominator == 0)435 if (denominator == 0)
436 return error.DivisionByZero;436 return error.DivisionByZero;
437 if (denominator < 0)437 if (denominator < 0)
...@@ -458,7 +458,7 @@ fn testMod() {...@@ -458,7 +458,7 @@ fn testMod() {
458error DivisionByZero;458error DivisionByZero;
459error NegativeDenominator;459error NegativeDenominator;
460pub fn rem(comptime T: type, numerator: T, denominator: T) -> %T {460pub fn rem(comptime T: type, numerator: T, denominator: T) -> %T {
461 @setDebugSafety(this, false);461 @setRuntimeSafety(false);
462 if (denominator == 0)462 if (denominator == 0)
463 return error.DivisionByZero;463 return error.DivisionByZero;
464 if (denominator < 0)464 if (denominator < 0)
std/mem.zig+2-2
...@@ -156,9 +156,9 @@ pub const FixedBufferAllocator = struct {...@@ -156,9 +156,9 @@ pub const FixedBufferAllocator = struct {
156/// dest.len must be >= source.len.156/// dest.len must be >= source.len.
157pub fn copy(comptime T: type, dest: []T, source: []const T) {157pub fn copy(comptime T: type, dest: []T, source: []const T) {
158 // TODO instead of manually doing this check for the whole array158 // TODO instead of manually doing this check for the whole array
159 // and turning off debug safety, the compiler should detect loops like159 // and turning off runtime safety, the compiler should detect loops like
160 // this and automatically omit safety checks for loops160 // this and automatically omit safety checks for loops
161 @setDebugSafety(this, false);161 @setRuntimeSafety(false);
162 assert(dest.len >= source.len);162 assert(dest.len >= source.len);
163 for (source) |s, i| dest[i] = s;163 for (source) |s, i| dest[i] = s;
164}164}
std/special/builtin.zig+4-4
...@@ -3,7 +3,7 @@...@@ -3,7 +3,7 @@
33
4const builtin = @import("builtin");4const builtin = @import("builtin");
55
6// Avoid dragging in the debug safety mechanisms into this .o file,6// Avoid dragging in the runtime safety mechanisms into this .o file,
7// unless we're trying to test this file.7// unless we're trying to test this file.
8pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn {8pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn {
9 if (builtin.is_test) {9 if (builtin.is_test) {
...@@ -18,7 +18,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret...@@ -18,7 +18,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret
18// The semantics of memset is dictated by the corresponding18// The semantics of memset is dictated by the corresponding
19// LLVM intrinsics, not by the libc API.19// LLVM intrinsics, not by the libc API.
20export fn memset(dest: ?&u8, c: u8, n: usize) {20export fn memset(dest: ?&u8, c: u8, n: usize) {
21 @setDebugSafety(this, false);21 @setRuntimeSafety(false);
2222
23 var index: usize = 0;23 var index: usize = 0;
24 while (index != n) : (index += 1)24 while (index != n) : (index += 1)
...@@ -29,7 +29,7 @@ export fn memset(dest: ?&u8, c: u8, n: usize) {...@@ -29,7 +29,7 @@ export fn memset(dest: ?&u8, c: u8, n: usize) {
29// The semantics of memcpy is dictated by the corresponding29// The semantics of memcpy is dictated by the corresponding
30// LLVM intrinsics, not by the libc API.30// LLVM intrinsics, not by the libc API.
31export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {31export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
32 @setDebugSafety(this, false);32 @setRuntimeSafety(false);
3333
34 var index: usize = 0;34 var index: usize = 0;
35 while (index != n) : (index += 1)35 while (index != n) : (index += 1)
...@@ -58,7 +58,7 @@ export fn floor(x: f64) -> f64 { return math.floor(x); }...@@ -58,7 +58,7 @@ export fn floor(x: f64) -> f64 { return math.floor(x); }
58export fn ceil(x: f64) -> f64 { return math.ceil(x); }58export fn ceil(x: f64) -> f64 { return math.ceil(x); }
5959
60fn generic_fmod(comptime T: type, x: T, y: T) -> T {60fn generic_fmod(comptime T: type, x: T, y: T) -> T {
61 @setDebugSafety(this, false);61 @setRuntimeSafety(false);
6262
63 const uint = @IntType(false, T.bit_count);63 const uint = @IntType(false, T.bit_count);
64 const log2uint = math.Log2Int(uint);64 const log2uint = math.Log2Int(uint);
std/special/compiler_rt/aulldiv.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1pub nakedcc fn _aulldiv() {1pub nakedcc fn _aulldiv() {
2 @setDebugSafety(this, false);2 @setRuntimeSafety(false);
3 asm volatile (3 asm volatile (
4 \\.intel_syntax noprefix4 \\.intel_syntax noprefix
5 \\5 \\
std/special/compiler_rt/aullrem.zig+1-1
...@@ -1,5 +1,5 @@...@@ -1,5 +1,5 @@
1pub nakedcc fn _aullrem() {1pub nakedcc fn _aullrem() {
2 @setDebugSafety(this, false);2 @setRuntimeSafety(false);
3 asm volatile (3 asm volatile (
4 \\.intel_syntax noprefix4 \\.intel_syntax noprefix
5 \\5 \\
std/special/compiler_rt/comparetf2.zig+3-3
...@@ -22,7 +22,7 @@ const builtin = @import("builtin");...@@ -22,7 +22,7 @@ const builtin = @import("builtin");
22const is_test = builtin.is_test;22const is_test = builtin.is_test;
2323
24pub extern fn __letf2(a: f128, b: f128) -> c_int {24pub extern fn __letf2(a: f128, b: f128) -> c_int {
25 @setDebugSafety(this, is_test);25 @setRuntimeSafety(is_test);
2626
27 const aInt = @bitCast(rep_t, a);27 const aInt = @bitCast(rep_t, a);
28 const bInt = @bitCast(rep_t, b);28 const bInt = @bitCast(rep_t, b);
...@@ -67,7 +67,7 @@ const GE_GREATER = c_int(1);...@@ -67,7 +67,7 @@ const GE_GREATER = c_int(1);
67const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED67const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
6868
69pub extern fn __getf2(a: f128, b: f128) -> c_int {69pub extern fn __getf2(a: f128, b: f128) -> c_int {
70 @setDebugSafety(this, is_test);70 @setRuntimeSafety(is_test);
7171
72 const aInt = @bitCast(srep_t, a);72 const aInt = @bitCast(srep_t, a);
73 const bInt = @bitCast(srep_t, b);73 const bInt = @bitCast(srep_t, b);
...@@ -94,7 +94,7 @@ pub extern fn __getf2(a: f128, b: f128) -> c_int {...@@ -94,7 +94,7 @@ pub extern fn __getf2(a: f128, b: f128) -> c_int {
94}94}
9595
96pub extern fn __unordtf2(a: f128, b: f128) -> c_int {96pub extern fn __unordtf2(a: f128, b: f128) -> c_int {
97 @setDebugSafety(this, is_test);97 @setRuntimeSafety(is_test);
9898
99 const aAbs = @bitCast(rep_t, a) & absMask;99 const aAbs = @bitCast(rep_t, a) & absMask;
100 const bAbs = @bitCast(rep_t, b) & absMask;100 const bAbs = @bitCast(rep_t, b) & absMask;
std/special/compiler_rt/fixuint.zig+3-3
...@@ -2,7 +2,7 @@ const is_test = @import("builtin").is_test;...@@ -2,7 +2,7 @@ const is_test = @import("builtin").is_test;
2const Log2Int = @import("../../math/index.zig").Log2Int;2const Log2Int = @import("../../math/index.zig").Log2Int;
33
4pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) -> fixuint_t {4pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) -> fixuint_t {
5 @setDebugSafety(this, is_test);5 @setRuntimeSafety(is_test);
66
7 const rep_t = switch (fp_t) {7 const rep_t = switch (fp_t) {
8 f32 => u32,8 f32 => u32,
...@@ -48,12 +48,12 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) -> fixuin...@@ -48,12 +48,12 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) -> fixuin
48 if (exponent < significandBits) {48 if (exponent < significandBits) {
49 // TODO this is a workaround for the mysterious "integer cast truncated bits"49 // TODO this is a workaround for the mysterious "integer cast truncated bits"
50 // happening on the next line50 // happening on the next line
51 @setDebugSafety(this, false);51 @setRuntimeSafety(false);
52 return fixuint_t(significand >> Log2Int(rep_t)(significandBits - exponent));52 return fixuint_t(significand >> Log2Int(rep_t)(significandBits - exponent));
53 } else {53 } else {
54 // TODO this is a workaround for the mysterious "integer cast truncated bits"54 // TODO this is a workaround for the mysterious "integer cast truncated bits"
55 // happening on the next line55 // happening on the next line
56 @setDebugSafety(this, false);56 @setRuntimeSafety(false);
57 return fixuint_t(significand) << Log2Int(fixuint_t)(exponent - significandBits);57 return fixuint_t(significand) << Log2Int(fixuint_t)(exponent - significandBits);
58 }58 }
59}59}
std/special/compiler_rt/fixunsdfdi.zig+1-1
...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunsdfdi(a: f64) -> u64 {4pub extern fn __fixunsdfdi(a: f64) -> u64 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f64, u64, a);6 return fixuint(f64, u64, a);
7}7}
88
std/special/compiler_rt/fixunsdfsi.zig+1-1
...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunsdfsi(a: f64) -> u32 {4pub extern fn __fixunsdfsi(a: f64) -> u32 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f64, u32, a);6 return fixuint(f64, u32, a);
7}7}
88
std/special/compiler_rt/fixunsdfti.zig+1-1
...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunsdfti(a: f64) -> u128 {4pub extern fn __fixunsdfti(a: f64) -> u128 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f64, u128, a);6 return fixuint(f64, u128, a);
7}7}
88
std/special/compiler_rt/fixunssfdi.zig+1-1
...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunssfdi(a: f32) -> u64 {4pub extern fn __fixunssfdi(a: f32) -> u64 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f32, u64, a);6 return fixuint(f32, u64, a);
7}7}
88
std/special/compiler_rt/fixunssfsi.zig+1-1
...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunssfsi(a: f32) -> u32 {4pub extern fn __fixunssfsi(a: f32) -> u32 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f32, u32, a);6 return fixuint(f32, u32, a);
7}7}
88
std/special/compiler_rt/fixunssfti.zig+1-1
...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunssfti(a: f32) -> u128 {4pub extern fn __fixunssfti(a: f32) -> u128 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f32, u128, a);6 return fixuint(f32, u128, a);
7}7}
88
std/special/compiler_rt/fixunstfdi.zig+1-1
...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunstfdi(a: f128) -> u64 {4pub extern fn __fixunstfdi(a: f128) -> u64 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f128, u64, a);6 return fixuint(f128, u64, a);
7}7}
88
std/special/compiler_rt/fixunstfsi.zig+1-1
...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunstfsi(a: f128) -> u32 {4pub extern fn __fixunstfsi(a: f128) -> u32 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f128, u32, a);6 return fixuint(f128, u32, a);
7}7}
88
std/special/compiler_rt/fixunstfti.zig+1-1
...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;...@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __fixunstfti(a: f128) -> u128 {4pub extern fn __fixunstfti(a: f128) -> u128 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return fixuint(f128, u128, a);6 return fixuint(f128, u128, a);
7}7}
88
std/special/compiler_rt/index.zig+11-11
...@@ -72,7 +72,7 @@ const assert = @import("../../index.zig").debug.assert;...@@ -72,7 +72,7 @@ const assert = @import("../../index.zig").debug.assert;
7272
73const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;73const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
7474
75// Avoid dragging in the debug safety mechanisms into this .o file,75// Avoid dragging in the runtime safety mechanisms into this .o file,
76// unless we're trying to test this file.76// unless we're trying to test this file.
77pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn {77pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn {
78 @setCold(true);78 @setCold(true);
...@@ -84,12 +84,12 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret...@@ -84,12 +84,12 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret
84}84}
8585
86extern fn __udivdi3(a: u64, b: u64) -> u64 {86extern fn __udivdi3(a: u64, b: u64) -> u64 {
87 @setDebugSafety(this, is_test);87 @setRuntimeSafety(is_test);
88 return __udivmoddi4(a, b, null);88 return __udivmoddi4(a, b, null);
89}89}
9090
91extern fn __umoddi3(a: u64, b: u64) -> u64 {91extern fn __umoddi3(a: u64, b: u64) -> u64 {
92 @setDebugSafety(this, is_test);92 @setRuntimeSafety(is_test);
9393
94 var r: u64 = undefined;94 var r: u64 = undefined;
95 _ = __udivmoddi4(a, b, &r);95 _ = __udivmoddi4(a, b, &r);
...@@ -101,7 +101,7 @@ const AeabiUlDivModResult = extern struct {...@@ -101,7 +101,7 @@ const AeabiUlDivModResult = extern struct {
101 rem: u64,101 rem: u64,
102};102};
103extern fn __aeabi_uldivmod(numerator: u64, denominator: u64) -> AeabiUlDivModResult {103extern fn __aeabi_uldivmod(numerator: u64, denominator: u64) -> AeabiUlDivModResult {
104 @setDebugSafety(this, is_test);104 @setRuntimeSafety(is_test);
105 var result: AeabiUlDivModResult = undefined;105 var result: AeabiUlDivModResult = undefined;
106 result.quot = __udivmoddi4(numerator, denominator, &result.rem);106 result.quot = __udivmoddi4(numerator, denominator, &result.rem);
107 return result;107 return result;
...@@ -133,7 +133,7 @@ fn isArmArch() -> bool {...@@ -133,7 +133,7 @@ fn isArmArch() -> bool {
133}133}
134134
135nakedcc fn __aeabi_uidivmod() {135nakedcc fn __aeabi_uidivmod() {
136 @setDebugSafety(this, false);136 @setRuntimeSafety(false);
137 asm volatile (137 asm volatile (
138 \\ push { lr }138 \\ push { lr }
139 \\ sub sp, sp, #4139 \\ sub sp, sp, #4
...@@ -150,7 +150,7 @@ nakedcc fn __aeabi_uidivmod() {...@@ -150,7 +150,7 @@ nakedcc fn __aeabi_uidivmod() {
150// This routine is windows specific150// This routine is windows specific
151// http://msdn.microsoft.com/en-us/library/ms648426.aspx151// http://msdn.microsoft.com/en-us/library/ms648426.aspx
152nakedcc fn _chkstk() align(4) {152nakedcc fn _chkstk() align(4) {
153 @setDebugSafety(this, false);153 @setRuntimeSafety(false);
154154
155 asm volatile (155 asm volatile (
156 \\ push %%ecx156 \\ push %%ecx
...@@ -174,7 +174,7 @@ nakedcc fn _chkstk() align(4) {...@@ -174,7 +174,7 @@ nakedcc fn _chkstk() align(4) {
174}174}
175175
176nakedcc fn __chkstk() align(4) {176nakedcc fn __chkstk() align(4) {
177 @setDebugSafety(this, false);177 @setRuntimeSafety(false);
178178
179 asm volatile (179 asm volatile (
180 \\ push %%rcx180 \\ push %%rcx
...@@ -201,7 +201,7 @@ nakedcc fn __chkstk() align(4) {...@@ -201,7 +201,7 @@ nakedcc fn __chkstk() align(4) {
201// This routine is windows specific201// This routine is windows specific
202// http://msdn.microsoft.com/en-us/library/ms648426.aspx202// http://msdn.microsoft.com/en-us/library/ms648426.aspx
203nakedcc fn __chkstk_ms() align(4) {203nakedcc fn __chkstk_ms() align(4) {
204 @setDebugSafety(this, false);204 @setRuntimeSafety(false);
205205
206 asm volatile (206 asm volatile (
207 \\ push %%ecx207 \\ push %%ecx
...@@ -225,7 +225,7 @@ nakedcc fn __chkstk_ms() align(4) {...@@ -225,7 +225,7 @@ nakedcc fn __chkstk_ms() align(4) {
225}225}
226226
227nakedcc fn ___chkstk_ms() align(4) {227nakedcc fn ___chkstk_ms() align(4) {
228 @setDebugSafety(this, false);228 @setRuntimeSafety(false);
229229
230 asm volatile (230 asm volatile (
231 \\ push %%rcx231 \\ push %%rcx
...@@ -249,7 +249,7 @@ nakedcc fn ___chkstk_ms() align(4) {...@@ -249,7 +249,7 @@ nakedcc fn ___chkstk_ms() align(4) {
249}249}
250250
251extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 {251extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 {
252 @setDebugSafety(this, is_test);252 @setRuntimeSafety(is_test);
253253
254 const d = __udivsi3(a, b);254 const d = __udivsi3(a, b);
255 *rem = u32(i32(a) -% (i32(d) * i32(b)));255 *rem = u32(i32(a) -% (i32(d) * i32(b)));
...@@ -258,7 +258,7 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 {...@@ -258,7 +258,7 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 {
258258
259259
260extern fn __udivsi3(n: u32, d: u32) -> u32 {260extern fn __udivsi3(n: u32, d: u32) -> u32 {
261 @setDebugSafety(this, is_test);261 @setRuntimeSafety(is_test);
262262
263 const n_uword_bits: c_uint = u32.bit_count;263 const n_uword_bits: c_uint = u32.bit_count;
264 // special cases264 // special cases
std/special/compiler_rt/udivmod.zig+1-1
...@@ -5,7 +5,7 @@ const low = switch (builtin.endian) { builtin.Endian.Big => 1, builtin.Endian.Li...@@ -5,7 +5,7 @@ const low = switch (builtin.endian) { builtin.Endian.Big => 1, builtin.Endian.Li
5const high = 1 - low;5const high = 1 - low;
66
7pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) -> DoubleInt {7pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) -> DoubleInt {
8 @setDebugSafety(this, is_test);8 @setRuntimeSafety(is_test);
99
10 const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2));10 const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2));
11 const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);11 const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);
std/special/compiler_rt/udivmoddi4.zig+1-1
...@@ -2,7 +2,7 @@ const udivmod = @import("udivmod.zig").udivmod;...@@ -2,7 +2,7 @@ const udivmod = @import("udivmod.zig").udivmod;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?&u64) -> u64 {4pub extern fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?&u64) -> u64 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return udivmod(u64, a, b, maybe_rem);6 return udivmod(u64, a, b, maybe_rem);
7}7}
88
std/special/compiler_rt/udivmodti4.zig+1-1
...@@ -2,7 +2,7 @@ const udivmod = @import("udivmod.zig").udivmod;...@@ -2,7 +2,7 @@ const udivmod = @import("udivmod.zig").udivmod;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) -> u128 {4pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) -> u128 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return udivmod(u128, a, b, maybe_rem);6 return udivmod(u128, a, b, maybe_rem);
7}7}
88
std/special/compiler_rt/udivti3.zig+1-1
...@@ -2,6 +2,6 @@ const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;...@@ -2,6 +2,6 @@ const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __udivti3(a: u128, b: u128) -> u128 {4pub extern fn __udivti3(a: u128, b: u128) -> u128 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 return __udivmodti4(a, b, null);6 return __udivmodti4(a, b, null);
7}7}
std/special/compiler_rt/umodti3.zig+1-1
...@@ -2,7 +2,7 @@ const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;...@@ -2,7 +2,7 @@ const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
2const builtin = @import("builtin");2const builtin = @import("builtin");
33
4pub extern fn __umodti3(a: u128, b: u128) -> u128 {4pub extern fn __umodti3(a: u128, b: u128) -> u128 {
5 @setDebugSafety(this, builtin.is_test);5 @setRuntimeSafety(builtin.is_test);
6 var r: u128 = undefined;6 var r: u128 = undefined;
7 _ = __udivmodti4(a, b, &r);7 _ = __udivmodti4(a, b, &r);
8 return r;8 return r;
test/cases/eval.zig+4-4
...@@ -223,13 +223,13 @@ test "comptime iterate over fn ptr list" {...@@ -223,13 +223,13 @@ test "comptime iterate over fn ptr list" {
223 assert(performFn('w', 99) == 99);223 assert(performFn('w', 99) == 99);
224}224}
225225
226test "eval @setDebugSafety at compile-time" {226test "eval @setRuntimeSafety at compile-time" {
227 const result = comptime fnWithSetDebugSafety();227 const result = comptime fnWithSetRuntimeSafety();
228 assert(result == 1234);228 assert(result == 1234);
229}229}
230230
231fn fnWithSetDebugSafety() -> i32{231fn fnWithSetRuntimeSafety() -> i32{
232 @setDebugSafety(this, true);232 @setRuntimeSafety(true);
233 return 1234;233 return 1234;
234}234}
235235
test/cases/slice.zig+1-1
...@@ -17,7 +17,7 @@ test "slice child property" {...@@ -17,7 +17,7 @@ test "slice child property" {
17 assert(@typeOf(slice).Child == i32);17 assert(@typeOf(slice).Child == i32);
18}18}
1919
20test "debug safety lets us slice from len..len" {20test "runtime safety lets us slice from len..len" {
21 var an_array = []u8{1, 2, 3};21 var an_array = []u8{1, 2, 3};
22 assert(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));22 assert(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
23}23}
test/compile_errors.zig+4-4
...@@ -1867,13 +1867,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {...@@ -1867,13 +1867,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
1867 ,1867 ,
1868 ".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits");1868 ".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits");
18691869
1870 cases.add("@setDebugSafety twice for same scope",1870 cases.add("@setRuntimeSafety twice for same scope",
1871 \\export fn foo() {1871 \\export fn foo() {
1872 \\ @setDebugSafety(this, false);1872 \\ @setRuntimeSafety(false);
1873 \\ @setDebugSafety(this, false);1873 \\ @setRuntimeSafety(false);
1874 \\}1874 \\}
1875 ,1875 ,
1876 ".tmp_source.zig:3:5: error: debug safety set twice for same scope",1876 ".tmp_source.zig:3:5: error: runtime safety set twice for same scope",
1877 ".tmp_source.zig:2:5: note: first set here");1877 ".tmp_source.zig:2:5: note: first set here");
18781878
1879 cases.add("@setFloatMode twice for same scope",1879 cases.add("@setFloatMode twice for same scope",
test/debug_safety.zig deleted-286
...@@ -1,286 +0,0 @@
1const tests = @import("tests.zig");
2
3pub fn addCases(cases: &tests.CompareOutputContext) {
4 cases.addDebugSafety("calling panic",
5 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
6 \\ @import("std").os.exit(126);
7 \\}
8 \\pub fn main() -> %void {
9 \\ @panic("oh no");
10 \\}
11 );
12
13 cases.addDebugSafety("out of bounds slice access",
14 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
15 \\ @import("std").os.exit(126);
16 \\}
17 \\pub fn main() -> %void {
18 \\ const a = []i32{1, 2, 3, 4};
19 \\ baz(bar(a));
20 \\}
21 \\fn bar(a: []const i32) -> i32 {
22 \\ return a[4];
23 \\}
24 \\fn baz(a: i32) { }
25 );
26
27 cases.addDebugSafety("integer addition overflow",
28 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
29 \\ @import("std").os.exit(126);
30 \\}
31 \\error Whatever;
32 \\pub fn main() -> %void {
33 \\ const x = add(65530, 10);
34 \\ if (x == 0) return error.Whatever;
35 \\}
36 \\fn add(a: u16, b: u16) -> u16 {
37 \\ return a + b;
38 \\}
39 );
40
41 cases.addDebugSafety("integer subtraction overflow",
42 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
43 \\ @import("std").os.exit(126);
44 \\}
45 \\error Whatever;
46 \\pub fn main() -> %void {
47 \\ const x = sub(10, 20);
48 \\ if (x == 0) return error.Whatever;
49 \\}
50 \\fn sub(a: u16, b: u16) -> u16 {
51 \\ return a - b;
52 \\}
53 );
54
55 cases.addDebugSafety("integer multiplication overflow",
56 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
57 \\ @import("std").os.exit(126);
58 \\}
59 \\error Whatever;
60 \\pub fn main() -> %void {
61 \\ const x = mul(300, 6000);
62 \\ if (x == 0) return error.Whatever;
63 \\}
64 \\fn mul(a: u16, b: u16) -> u16 {
65 \\ return a * b;
66 \\}
67 );
68
69 cases.addDebugSafety("integer negation overflow",
70 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
71 \\ @import("std").os.exit(126);
72 \\}
73 \\error Whatever;
74 \\pub fn main() -> %void {
75 \\ const x = neg(-32768);
76 \\ if (x == 32767) return error.Whatever;
77 \\}
78 \\fn neg(a: i16) -> i16 {
79 \\ return -a;
80 \\}
81 );
82
83 cases.addDebugSafety("signed integer division overflow",
84 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
85 \\ @import("std").os.exit(126);
86 \\}
87 \\error Whatever;
88 \\pub fn main() -> %void {
89 \\ const x = div(-32768, -1);
90 \\ if (x == 32767) return error.Whatever;
91 \\}
92 \\fn div(a: i16, b: i16) -> i16 {
93 \\ return @divTrunc(a, b);
94 \\}
95 );
96
97 cases.addDebugSafety("signed shift left overflow",
98 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
99 \\ @import("std").os.exit(126);
100 \\}
101 \\error Whatever;
102 \\pub fn main() -> %void {
103 \\ const x = shl(-16385, 1);
104 \\ if (x == 0) return error.Whatever;
105 \\}
106 \\fn shl(a: i16, b: u4) -> i16 {
107 \\ return @shlExact(a, b);
108 \\}
109 );
110
111 cases.addDebugSafety("unsigned shift left overflow",
112 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
113 \\ @import("std").os.exit(126);
114 \\}
115 \\error Whatever;
116 \\pub fn main() -> %void {
117 \\ const x = shl(0b0010111111111111, 3);
118 \\ if (x == 0) return error.Whatever;
119 \\}
120 \\fn shl(a: u16, b: u4) -> u16 {
121 \\ return @shlExact(a, b);
122 \\}
123 );
124
125 cases.addDebugSafety("signed shift right overflow",
126 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
127 \\ @import("std").os.exit(126);
128 \\}
129 \\error Whatever;
130 \\pub fn main() -> %void {
131 \\ const x = shr(-16385, 1);
132 \\ if (x == 0) return error.Whatever;
133 \\}
134 \\fn shr(a: i16, b: u4) -> i16 {
135 \\ return @shrExact(a, b);
136 \\}
137 );
138
139 cases.addDebugSafety("unsigned shift right overflow",
140 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
141 \\ @import("std").os.exit(126);
142 \\}
143 \\error Whatever;
144 \\pub fn main() -> %void {
145 \\ const x = shr(0b0010111111111111, 3);
146 \\ if (x == 0) return error.Whatever;
147 \\}
148 \\fn shr(a: u16, b: u4) -> u16 {
149 \\ return @shrExact(a, b);
150 \\}
151 );
152
153 cases.addDebugSafety("integer division by zero",
154 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
155 \\ @import("std").os.exit(126);
156 \\}
157 \\error Whatever;
158 \\pub fn main() -> %void {
159 \\ const x = div0(999, 0);
160 \\}
161 \\fn div0(a: i32, b: i32) -> i32 {
162 \\ return @divTrunc(a, b);
163 \\}
164 );
165
166 cases.addDebugSafety("exact division failure",
167 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
168 \\ @import("std").os.exit(126);
169 \\}
170 \\error Whatever;
171 \\pub fn main() -> %void {
172 \\ const x = divExact(10, 3);
173 \\ if (x == 0) return error.Whatever;
174 \\}
175 \\fn divExact(a: i32, b: i32) -> i32 {
176 \\ return @divExact(a, b);
177 \\}
178 );
179
180 cases.addDebugSafety("cast []u8 to bigger slice of wrong size",
181 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
182 \\ @import("std").os.exit(126);
183 \\}
184 \\error Whatever;
185 \\pub fn main() -> %void {
186 \\ const x = widenSlice([]u8{1, 2, 3, 4, 5});
187 \\ if (x.len == 0) return error.Whatever;
188 \\}
189 \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 {
190 \\ return ([]align(1) const i32)(slice);
191 \\}
192 );
193
194 cases.addDebugSafety("value does not fit in shortening cast",
195 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
196 \\ @import("std").os.exit(126);
197 \\}
198 \\error Whatever;
199 \\pub fn main() -> %void {
200 \\ const x = shorten_cast(200);
201 \\ if (x == 0) return error.Whatever;
202 \\}
203 \\fn shorten_cast(x: i32) -> i8 {
204 \\ return i8(x);
205 \\}
206 );
207
208 cases.addDebugSafety("signed integer not fitting in cast to unsigned integer",
209 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
210 \\ @import("std").os.exit(126);
211 \\}
212 \\error Whatever;
213 \\pub fn main() -> %void {
214 \\ const x = unsigned_cast(-10);
215 \\ if (x == 0) return error.Whatever;
216 \\}
217 \\fn unsigned_cast(x: i32) -> u32 {
218 \\ return u32(x);
219 \\}
220 );
221
222 cases.addDebugSafety("unwrap error",
223 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
224 \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
225 \\ @import("std").os.exit(126); // good
226 \\ }
227 \\ @import("std").os.exit(0); // test failed
228 \\}
229 \\error Whatever;
230 \\pub fn main() -> %void {
231 \\ bar() catch unreachable;
232 \\}
233 \\fn bar() -> %void {
234 \\ return error.Whatever;
235 \\}
236 );
237
238 cases.addDebugSafety("cast integer to error and no code matches",
239 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
240 \\ @import("std").os.exit(126);
241 \\}
242 \\pub fn main() -> %void {
243 \\ _ = bar(9999);
244 \\}
245 \\fn bar(x: u32) -> error {
246 \\ return error(x);
247 \\}
248 );
249
250 cases.addDebugSafety("@alignCast misaligned",
251 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
252 \\ @import("std").os.exit(126);
253 \\}
254 \\error Wrong;
255 \\pub fn main() -> %void {
256 \\ var array align(4) = []u32{0x11111111, 0x11111111};
257 \\ const bytes = ([]u8)(array[0..]);
258 \\ if (foo(bytes) != 0x11111111) return error.Wrong;
259 \\}
260 \\fn foo(bytes: []u8) -> u32 {
261 \\ const slice4 = bytes[1..5];
262 \\ const int_slice = ([]u32)(@alignCast(4, slice4));
263 \\ return int_slice[0];
264 \\}
265 );
266
267 cases.addDebugSafety("bad union field access",
268 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
269 \\ @import("std").os.exit(126);
270 \\}
271 \\
272 \\const Foo = union {
273 \\ float: f32,
274 \\ int: u32,
275 \\};
276 \\
277 \\pub fn main() -> %void {
278 \\ var f = Foo { .int = 42 };
279 \\ bar(&f);
280 \\}
281 \\
282 \\fn bar(f: &Foo) {
283 \\ f.float = 12.34;
284 \\}
285 );
286}
test/runtime_safety.zig created+286
...@@ -0,0 +1,286 @@
1const tests = @import("tests.zig");
2
3pub fn addCases(cases: &tests.CompareOutputContext) {
4 cases.addRuntimeSafety("calling panic",
5 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
6 \\ @import("std").os.exit(126);
7 \\}
8 \\pub fn main() -> %void {
9 \\ @panic("oh no");
10 \\}
11 );
12
13 cases.addRuntimeSafety("out of bounds slice access",
14 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
15 \\ @import("std").os.exit(126);
16 \\}
17 \\pub fn main() -> %void {
18 \\ const a = []i32{1, 2, 3, 4};
19 \\ baz(bar(a));
20 \\}
21 \\fn bar(a: []const i32) -> i32 {
22 \\ return a[4];
23 \\}
24 \\fn baz(a: i32) { }
25 );
26
27 cases.addRuntimeSafety("integer addition overflow",
28 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
29 \\ @import("std").os.exit(126);
30 \\}
31 \\error Whatever;
32 \\pub fn main() -> %void {
33 \\ const x = add(65530, 10);
34 \\ if (x == 0) return error.Whatever;
35 \\}
36 \\fn add(a: u16, b: u16) -> u16 {
37 \\ return a + b;
38 \\}
39 );
40
41 cases.addRuntimeSafety("integer subtraction overflow",
42 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
43 \\ @import("std").os.exit(126);
44 \\}
45 \\error Whatever;
46 \\pub fn main() -> %void {
47 \\ const x = sub(10, 20);
48 \\ if (x == 0) return error.Whatever;
49 \\}
50 \\fn sub(a: u16, b: u16) -> u16 {
51 \\ return a - b;
52 \\}
53 );
54
55 cases.addRuntimeSafety("integer multiplication overflow",
56 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
57 \\ @import("std").os.exit(126);
58 \\}
59 \\error Whatever;
60 \\pub fn main() -> %void {
61 \\ const x = mul(300, 6000);
62 \\ if (x == 0) return error.Whatever;
63 \\}
64 \\fn mul(a: u16, b: u16) -> u16 {
65 \\ return a * b;
66 \\}
67 );
68
69 cases.addRuntimeSafety("integer negation overflow",
70 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
71 \\ @import("std").os.exit(126);
72 \\}
73 \\error Whatever;
74 \\pub fn main() -> %void {
75 \\ const x = neg(-32768);
76 \\ if (x == 32767) return error.Whatever;
77 \\}
78 \\fn neg(a: i16) -> i16 {
79 \\ return -a;
80 \\}
81 );
82
83 cases.addRuntimeSafety("signed integer division overflow",
84 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
85 \\ @import("std").os.exit(126);
86 \\}
87 \\error Whatever;
88 \\pub fn main() -> %void {
89 \\ const x = div(-32768, -1);
90 \\ if (x == 32767) return error.Whatever;
91 \\}
92 \\fn div(a: i16, b: i16) -> i16 {
93 \\ return @divTrunc(a, b);
94 \\}
95 );
96
97 cases.addRuntimeSafety("signed shift left overflow",
98 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
99 \\ @import("std").os.exit(126);
100 \\}
101 \\error Whatever;
102 \\pub fn main() -> %void {
103 \\ const x = shl(-16385, 1);
104 \\ if (x == 0) return error.Whatever;
105 \\}
106 \\fn shl(a: i16, b: u4) -> i16 {
107 \\ return @shlExact(a, b);
108 \\}
109 );
110
111 cases.addRuntimeSafety("unsigned shift left overflow",
112 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
113 \\ @import("std").os.exit(126);
114 \\}
115 \\error Whatever;
116 \\pub fn main() -> %void {
117 \\ const x = shl(0b0010111111111111, 3);
118 \\ if (x == 0) return error.Whatever;
119 \\}
120 \\fn shl(a: u16, b: u4) -> u16 {
121 \\ return @shlExact(a, b);
122 \\}
123 );
124
125 cases.addRuntimeSafety("signed shift right overflow",
126 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
127 \\ @import("std").os.exit(126);
128 \\}
129 \\error Whatever;
130 \\pub fn main() -> %void {
131 \\ const x = shr(-16385, 1);
132 \\ if (x == 0) return error.Whatever;
133 \\}
134 \\fn shr(a: i16, b: u4) -> i16 {
135 \\ return @shrExact(a, b);
136 \\}
137 );
138
139 cases.addRuntimeSafety("unsigned shift right overflow",
140 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
141 \\ @import("std").os.exit(126);
142 \\}
143 \\error Whatever;
144 \\pub fn main() -> %void {
145 \\ const x = shr(0b0010111111111111, 3);
146 \\ if (x == 0) return error.Whatever;
147 \\}
148 \\fn shr(a: u16, b: u4) -> u16 {
149 \\ return @shrExact(a, b);
150 \\}
151 );
152
153 cases.addRuntimeSafety("integer division by zero",
154 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
155 \\ @import("std").os.exit(126);
156 \\}
157 \\error Whatever;
158 \\pub fn main() -> %void {
159 \\ const x = div0(999, 0);
160 \\}
161 \\fn div0(a: i32, b: i32) -> i32 {
162 \\ return @divTrunc(a, b);
163 \\}
164 );
165
166 cases.addRuntimeSafety("exact division failure",
167 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
168 \\ @import("std").os.exit(126);
169 \\}
170 \\error Whatever;
171 \\pub fn main() -> %void {
172 \\ const x = divExact(10, 3);
173 \\ if (x == 0) return error.Whatever;
174 \\}
175 \\fn divExact(a: i32, b: i32) -> i32 {
176 \\ return @divExact(a, b);
177 \\}
178 );
179
180 cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size",
181 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
182 \\ @import("std").os.exit(126);
183 \\}
184 \\error Whatever;
185 \\pub fn main() -> %void {
186 \\ const x = widenSlice([]u8{1, 2, 3, 4, 5});
187 \\ if (x.len == 0) return error.Whatever;
188 \\}
189 \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 {
190 \\ return ([]align(1) const i32)(slice);
191 \\}
192 );
193
194 cases.addRuntimeSafety("value does not fit in shortening cast",
195 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
196 \\ @import("std").os.exit(126);
197 \\}
198 \\error Whatever;
199 \\pub fn main() -> %void {
200 \\ const x = shorten_cast(200);
201 \\ if (x == 0) return error.Whatever;
202 \\}
203 \\fn shorten_cast(x: i32) -> i8 {
204 \\ return i8(x);
205 \\}
206 );
207
208 cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",
209 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
210 \\ @import("std").os.exit(126);
211 \\}
212 \\error Whatever;
213 \\pub fn main() -> %void {
214 \\ const x = unsigned_cast(-10);
215 \\ if (x == 0) return error.Whatever;
216 \\}
217 \\fn unsigned_cast(x: i32) -> u32 {
218 \\ return u32(x);
219 \\}
220 );
221
222 cases.addRuntimeSafety("unwrap error",
223 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
224 \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
225 \\ @import("std").os.exit(126); // good
226 \\ }
227 \\ @import("std").os.exit(0); // test failed
228 \\}
229 \\error Whatever;
230 \\pub fn main() -> %void {
231 \\ bar() catch unreachable;
232 \\}
233 \\fn bar() -> %void {
234 \\ return error.Whatever;
235 \\}
236 );
237
238 cases.addRuntimeSafety("cast integer to error and no code matches",
239 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
240 \\ @import("std").os.exit(126);
241 \\}
242 \\pub fn main() -> %void {
243 \\ _ = bar(9999);
244 \\}
245 \\fn bar(x: u32) -> error {
246 \\ return error(x);
247 \\}
248 );
249
250 cases.addRuntimeSafety("@alignCast misaligned",
251 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
252 \\ @import("std").os.exit(126);
253 \\}
254 \\error Wrong;
255 \\pub fn main() -> %void {
256 \\ var array align(4) = []u32{0x11111111, 0x11111111};
257 \\ const bytes = ([]u8)(array[0..]);
258 \\ if (foo(bytes) != 0x11111111) return error.Wrong;
259 \\}
260 \\fn foo(bytes: []u8) -> u32 {
261 \\ const slice4 = bytes[1..5];
262 \\ const int_slice = ([]u32)(@alignCast(4, slice4));
263 \\ return int_slice[0];
264 \\}
265 );
266
267 cases.addRuntimeSafety("bad union field access",
268 \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
269 \\ @import("std").os.exit(126);
270 \\}
271 \\
272 \\const Foo = union {
273 \\ float: f32,
274 \\ int: u32,
275 \\};
276 \\
277 \\pub fn main() -> %void {
278 \\ var f = Foo { .int = 42 };
279 \\ bar(&f);
280 \\}
281 \\
282 \\fn bar(f: &Foo) {
283 \\ f.float = 12.34;
284 \\}
285 );
286}
test/tests.zig+15-15
...@@ -17,7 +17,7 @@ const compare_output = @import("compare_output.zig");...@@ -17,7 +17,7 @@ const compare_output = @import("compare_output.zig");
17const build_examples = @import("build_examples.zig");17const build_examples = @import("build_examples.zig");
18const compile_errors = @import("compile_errors.zig");18const compile_errors = @import("compile_errors.zig");
19const assemble_and_link = @import("assemble_and_link.zig");19const assemble_and_link = @import("assemble_and_link.zig");
20const debug_safety = @import("debug_safety.zig");20const runtime_safety = @import("runtime_safety.zig");
21const translate_c = @import("translate_c.zig");21const translate_c = @import("translate_c.zig");
22const gen_h = @import("gen_h.zig");22const gen_h = @import("gen_h.zig");
2323
...@@ -64,16 +64,16 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu...@@ -64,16 +64,16 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu
64 return cases.step;64 return cases.step;
65}65}
6666
67pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {67pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
68 const cases = b.allocator.create(CompareOutputContext) catch unreachable;68 const cases = b.allocator.create(CompareOutputContext) catch unreachable;
69 *cases = CompareOutputContext {69 *cases = CompareOutputContext {
70 .b = b,70 .b = b,
71 .step = b.step("test-debug-safety", "Run the debug safety tests"),71 .step = b.step("test-runtime-safety", "Run the runtime safety tests"),
72 .test_index = 0,72 .test_index = 0,
73 .test_filter = test_filter,73 .test_filter = test_filter,
74 };74 };
7575
76 debug_safety.addCases(cases);76 runtime_safety.addCases(cases);
7777
78 return cases.step;78 return cases.step;
79}79}
...@@ -192,7 +192,7 @@ pub const CompareOutputContext = struct {...@@ -192,7 +192,7 @@ pub const CompareOutputContext = struct {
192 const Special = enum {192 const Special = enum {
193 None,193 None,
194 Asm,194 Asm,
195 DebugSafety,195 RuntimeSafety,
196 };196 };
197197
198 const TestCase = struct {198 const TestCase = struct {
...@@ -314,7 +314,7 @@ pub const CompareOutputContext = struct {...@@ -314,7 +314,7 @@ pub const CompareOutputContext = struct {
314 }314 }
315 };315 };
316316
317 const DebugSafetyRunStep = struct {317 const RuntimeSafetyRunStep = struct {
318 step: build.Step,318 step: build.Step,
319 context: &CompareOutputContext,319 context: &CompareOutputContext,
320 exe_path: []const u8,320 exe_path: []const u8,
...@@ -322,23 +322,23 @@ pub const CompareOutputContext = struct {...@@ -322,23 +322,23 @@ pub const CompareOutputContext = struct {
322 test_index: usize,322 test_index: usize,
323323
324 pub fn create(context: &CompareOutputContext, exe_path: []const u8,324 pub fn create(context: &CompareOutputContext, exe_path: []const u8,
325 name: []const u8) -> &DebugSafetyRunStep325 name: []const u8) -> &RuntimeSafetyRunStep
326 {326 {
327 const allocator = context.b.allocator;327 const allocator = context.b.allocator;
328 const ptr = allocator.create(DebugSafetyRunStep) catch unreachable;328 const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;
329 *ptr = DebugSafetyRunStep {329 *ptr = RuntimeSafetyRunStep {
330 .context = context,330 .context = context,
331 .exe_path = exe_path,331 .exe_path = exe_path,
332 .name = name,332 .name = name,
333 .test_index = context.test_index,333 .test_index = context.test_index,
334 .step = build.Step.init("DebugSafetyRun", allocator, make),334 .step = build.Step.init("RuntimeSafetyRun", allocator, make),
335 };335 };
336 context.test_index += 1;336 context.test_index += 1;
337 return ptr;337 return ptr;
338 }338 }
339339
340 fn make(step: &build.Step) -> %void {340 fn make(step: &build.Step) -> %void {
341 const self = @fieldParentPtr(DebugSafetyRunStep, "step", step);341 const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step);
342 const b = self.context.b;342 const b = self.context.b;
343343
344 const full_exe_path = b.pathFromRoot(self.exe_path);344 const full_exe_path = b.pathFromRoot(self.exe_path);
...@@ -420,8 +420,8 @@ pub const CompareOutputContext = struct {...@@ -420,8 +420,8 @@ pub const CompareOutputContext = struct {
420 self.addCase(tc);420 self.addCase(tc);
421 }421 }
422422
423 pub fn addDebugSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) {423 pub fn addRuntimeSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) {
424 const tc = self.createExtra(name, source, undefined, Special.DebugSafety);424 const tc = self.createExtra(name, source, undefined, Special.RuntimeSafety);
425 self.addCase(tc);425 self.addCase(tc);
426 }426 }
427427
...@@ -481,7 +481,7 @@ pub const CompareOutputContext = struct {...@@ -481,7 +481,7 @@ pub const CompareOutputContext = struct {
481 self.step.dependOn(&run_and_cmp_output.step);481 self.step.dependOn(&run_and_cmp_output.step);
482 }482 }
483 },483 },
484 Special.DebugSafety => {484 Special.RuntimeSafety => {
485 const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable;485 const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable;
486 if (self.test_filter) |filter| {486 if (self.test_filter) |filter| {
487 if (mem.indexOf(u8, annotated_case_name, filter) == null)487 if (mem.indexOf(u8, annotated_case_name, filter) == null)
...@@ -499,7 +499,7 @@ pub const CompareOutputContext = struct {...@@ -499,7 +499,7 @@ pub const CompareOutputContext = struct {
499 exe.step.dependOn(&write_src.step);499 exe.step.dependOn(&write_src.step);
500 }500 }
501501
502 const run_and_cmp_output = DebugSafetyRunStep.create(self, exe.getOutputPath(), annotated_case_name);502 const run_and_cmp_output = RuntimeSafetyRunStep.create(self, exe.getOutputPath(), annotated_case_name);
503 run_and_cmp_output.step.dependOn(&exe.step);503 run_and_cmp_output.step.dependOn(&exe.step);
504504
505 self.step.dependOn(&run_and_cmp_output.step);505 self.step.dependOn(&run_and_cmp_output.step);