From cf39819478e237255109d0343e642db70e88071b Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Mon, 22 Jan 2018 22:24:07 -0500
Subject: add new kind of test: generating .h files. and more
* docgen supports obj_err code kind for demonstrating
errors without explicit test cases
* add documentation for `extern enum`. See #367
* remove coldcc keyword and add @setIsCold. See #661
* add compile errors for non-extern struct, enum, unions
in function signatures
* add .h file generation for extern struct, enum, unions
---
src/codegen.cpp | 186 ++++++++++++++++++++++++++++++++++++++++++++++++++++----
1 file changed, 175 insertions(+), 11 deletions(-)
(limited to 'src/codegen.cpp')
diff --git a/src/codegen.cpp b/src/codegen.cpp
index 15423d6315..c79da04b05 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -485,11 +485,14 @@ static LLVMValueRef fn_llvm_value(CodeGen *g, FnTableEntry *fn_table_entry) {
addLLVMFnAttr(fn_table_entry->llvm_value, "naked");
} else {
LLVMSetFunctionCallConv(fn_table_entry->llvm_value, get_llvm_cc(g, fn_type->data.fn.fn_type_id.cc));
- if (fn_type->data.fn.fn_type_id.cc == CallingConventionCold) {
- ZigLLVMAddFunctionAttrCold(fn_table_entry->llvm_value);
- }
}
+ bool want_cold = fn_table_entry->is_cold || fn_type->data.fn.fn_type_id.cc == CallingConventionCold;
+ if (want_cold) {
+ ZigLLVMAddFunctionAttrCold(fn_table_entry->llvm_value);
+ }
+
+
LLVMSetLinkage(fn_table_entry->llvm_value, to_llvm_linkage(linkage));
if (linkage == GlobalLinkageIdInternal) {
@@ -3656,6 +3659,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
case IrInstructionIdToPtrType:
case IrInstructionIdPtrTypeChild:
case IrInstructionIdFieldPtr:
+ case IrInstructionIdSetCold:
case IrInstructionIdSetDebugSafety:
case IrInstructionIdSetFloatMode:
case IrInstructionIdArrayType:
@@ -5233,6 +5237,7 @@ static void define_builtin_fns(CodeGen *g) {
create_builtin_fn(g, BuiltinFnIdCompileErr, "compileError", 1);
create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
create_builtin_fn(g, BuiltinFnIdIntType, "IntType", 2); // TODO rename to Int
+ create_builtin_fn(g, BuiltinFnIdSetCold, "setCold", 1);
create_builtin_fn(g, BuiltinFnIdSetDebugSafety, "setDebugSafety", 2);
create_builtin_fn(g, BuiltinFnIdSetFloatMode, "setFloatMode", 2);
create_builtin_fn(g, BuiltinFnIdPanic, "panic", 1);
@@ -5788,7 +5793,76 @@ static const char *c_int_type_names[] = {
"unsigned long long",
};
-static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
+struct GenH {
+ ZigList types_to_declare;
+};
+
+static void prepend_c_type_to_decl_list(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry) {
+ if (type_entry->gen_h_loop_flag)
+ return;
+ type_entry->gen_h_loop_flag = true;
+
+ switch (type_entry->id) {
+ case TypeTableEntryIdInvalid:
+ case TypeTableEntryIdVar:
+ case TypeTableEntryIdMetaType:
+ case TypeTableEntryIdNumLitFloat:
+ case TypeTableEntryIdNumLitInt:
+ case TypeTableEntryIdUndefLit:
+ case TypeTableEntryIdNullLit:
+ case TypeTableEntryIdNamespace:
+ case TypeTableEntryIdBlock:
+ case TypeTableEntryIdBoundFn:
+ case TypeTableEntryIdArgTuple:
+ case TypeTableEntryIdErrorUnion:
+ case TypeTableEntryIdPureError:
+ zig_unreachable();
+ case TypeTableEntryIdVoid:
+ case TypeTableEntryIdUnreachable:
+ case TypeTableEntryIdBool:
+ case TypeTableEntryIdInt:
+ case TypeTableEntryIdFloat:
+ return;
+ case TypeTableEntryIdOpaque:
+ gen_h->types_to_declare.append(type_entry);
+ return;
+ case TypeTableEntryIdStruct:
+ for (uint32_t i = 0; i < type_entry->data.structure.src_field_count; i += 1) {
+ TypeStructField *field = &type_entry->data.structure.fields[i];
+ prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
+ }
+ gen_h->types_to_declare.append(type_entry);
+ return;
+ case TypeTableEntryIdUnion:
+ for (uint32_t i = 0; i < type_entry->data.unionation.src_field_count; i += 1) {
+ TypeUnionField *field = &type_entry->data.unionation.fields[i];
+ prepend_c_type_to_decl_list(g, gen_h, field->type_entry);
+ }
+ gen_h->types_to_declare.append(type_entry);
+ return;
+ case TypeTableEntryIdEnum:
+ prepend_c_type_to_decl_list(g, gen_h, type_entry->data.enumeration.tag_int_type);
+ gen_h->types_to_declare.append(type_entry);
+ return;
+ case TypeTableEntryIdPointer:
+ prepend_c_type_to_decl_list(g, gen_h, type_entry->data.pointer.child_type);
+ return;
+ case TypeTableEntryIdArray:
+ prepend_c_type_to_decl_list(g, gen_h, type_entry->data.array.child_type);
+ return;
+ case TypeTableEntryIdMaybe:
+ prepend_c_type_to_decl_list(g, gen_h, type_entry->data.maybe.child_type);
+ return;
+ case TypeTableEntryIdFn:
+ for (size_t i = 0; i < type_entry->data.fn.fn_type_id.param_count; i += 1) {
+ prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.param_info[i].type);
+ }
+ prepend_c_type_to_decl_list(g, gen_h, type_entry->data.fn.fn_type_id.return_type);
+ return;
+ }
+}
+
+static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf *out_buf) {
assert(type_entry);
for (size_t i = 0; i < array_length(c_int_type_names); i += 1) {
@@ -5816,6 +5890,8 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
return;
}
+ prepend_c_type_to_decl_list(g, gen_h, type_entry);
+
switch (type_entry->id) {
case TypeTableEntryIdVoid:
buf_init_from_str(out_buf, "void");
@@ -5856,7 +5932,7 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
{
Buf child_buf = BUF_INIT;
TypeTableEntry *child_type = type_entry->data.pointer.child_type;
- get_c_type(g, child_type, &child_buf);
+ get_c_type(g, gen_h, child_type, &child_buf);
const char *const_str = type_entry->data.pointer.is_const ? "const " : "";
buf_resize(out_buf, 0);
@@ -5872,23 +5948,37 @@ static void get_c_type(CodeGen *g, TypeTableEntry *type_entry, Buf *out_buf) {
} else if (child_type->id == TypeTableEntryIdPointer ||
child_type->id == TypeTableEntryIdFn)
{
- return get_c_type(g, child_type, out_buf);
+ return get_c_type(g, gen_h, child_type, out_buf);
} else {
zig_unreachable();
}
}
case TypeTableEntryIdStruct:
+ {
+ buf_init_from_str(out_buf, "struct ");
+ buf_append_buf(out_buf, &type_entry->name);
+ return;
+ }
+ case TypeTableEntryIdUnion:
+ {
+ buf_init_from_str(out_buf, "union ");
+ buf_append_buf(out_buf, &type_entry->name);
+ return;
+ }
+ case TypeTableEntryIdEnum:
+ {
+ buf_init_from_str(out_buf, "enum ");
+ buf_append_buf(out_buf, &type_entry->name);
+ return;
+ }
case TypeTableEntryIdOpaque:
{
- // TODO add to table of structs we need to declare
buf_init_from_buf(out_buf, &type_entry->name);
return;
}
case TypeTableEntryIdArray:
case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdPureError:
- case TypeTableEntryIdEnum:
- case TypeTableEntryIdUnion:
case TypeTableEntryIdFn:
zig_panic("TODO implement get_c_type for more types");
case TypeTableEntryIdInvalid:
@@ -5942,6 +6032,9 @@ static void gen_h_file(CodeGen *g) {
if (!g->want_h_file)
return;
+ GenH gen_h_data = {0};
+ GenH *gen_h = &gen_h_data;
+
codegen_add_time_event(g, "Generate .h");
assert(!g->is_test_build);
@@ -5971,7 +6064,7 @@ static void gen_h_file(CodeGen *g) {
FnTypeId *fn_type_id = &fn_table_entry->type_entry->data.fn.fn_type_id;
Buf return_type_c = BUF_INIT;
- get_c_type(g, fn_type_id->return_type, &return_type_c);
+ get_c_type(g, gen_h, fn_type_id->return_type, &return_type_c);
buf_appendf(&h_buf, "%s %s %s(",
buf_ptr(export_macro),
@@ -5987,7 +6080,7 @@ static void gen_h_file(CodeGen *g) {
const char *comma_str = (param_i == 0) ? "" : ", ";
const char *restrict_str = param_info->is_noalias ? "restrict" : "";
- get_c_type(g, param_info->type, ¶m_type_c);
+ get_c_type(g, gen_h, param_info->type, ¶m_type_c);
buf_appendf(&h_buf, "%s%s%s %s", comma_str, buf_ptr(¶m_type_c),
restrict_str, buf_ptr(param_name));
}
@@ -6027,6 +6120,77 @@ static void gen_h_file(CodeGen *g) {
fprintf(out_h, "#endif\n");
fprintf(out_h, "\n");
+ for (size_t type_i = 0; type_i < gen_h->types_to_declare.length; type_i += 1) {
+ TypeTableEntry *type_entry = gen_h->types_to_declare.at(type_i);
+ switch (type_entry->id) {
+ case TypeTableEntryIdInvalid:
+ case TypeTableEntryIdVar:
+ case TypeTableEntryIdMetaType:
+ case TypeTableEntryIdVoid:
+ case TypeTableEntryIdBool:
+ case TypeTableEntryIdUnreachable:
+ case TypeTableEntryIdInt:
+ case TypeTableEntryIdFloat:
+ case TypeTableEntryIdPointer:
+ case TypeTableEntryIdNumLitFloat:
+ case TypeTableEntryIdNumLitInt:
+ case TypeTableEntryIdArray:
+ case TypeTableEntryIdUndefLit:
+ case TypeTableEntryIdNullLit:
+ case TypeTableEntryIdErrorUnion:
+ case TypeTableEntryIdPureError:
+ case TypeTableEntryIdNamespace:
+ case TypeTableEntryIdBlock:
+ case TypeTableEntryIdBoundFn:
+ case TypeTableEntryIdArgTuple:
+ case TypeTableEntryIdMaybe:
+ case TypeTableEntryIdFn:
+ zig_unreachable();
+ case TypeTableEntryIdEnum:
+ assert(type_entry->data.enumeration.layout == ContainerLayoutExtern);
+ fprintf(out_h, "enum %s {\n", buf_ptr(&type_entry->name));
+ for (uint32_t field_i = 0; field_i < type_entry->data.enumeration.src_field_count; field_i += 1) {
+ TypeEnumField *enum_field = &type_entry->data.enumeration.fields[field_i];
+ Buf *value_buf = buf_alloc();
+ bigint_append_buf(value_buf, &enum_field->value, 10);
+ fprintf(out_h, " %s = %s", buf_ptr(enum_field->name), buf_ptr(value_buf));
+ if (field_i != type_entry->data.enumeration.src_field_count - 1) {
+ fprintf(out_h, ",");
+ }
+ fprintf(out_h, "\n");
+ }
+ fprintf(out_h, "};\n\n");
+ break;
+ case TypeTableEntryIdStruct:
+ assert(type_entry->data.structure.layout == ContainerLayoutExtern);
+ fprintf(out_h, "struct %s {\n", buf_ptr(&type_entry->name));
+ for (uint32_t field_i = 0; field_i < type_entry->data.structure.src_field_count; field_i += 1) {
+ TypeStructField *struct_field = &type_entry->data.structure.fields[field_i];
+
+ Buf *type_name_buf = buf_alloc();
+ get_c_type(g, gen_h, struct_field->type_entry, type_name_buf);
+ fprintf(out_h, " %s %s;\n", buf_ptr(type_name_buf), buf_ptr(struct_field->name));
+ }
+ fprintf(out_h, "};\n\n");
+ break;
+ case TypeTableEntryIdUnion:
+ assert(type_entry->data.unionation.layout == ContainerLayoutExtern);
+ fprintf(out_h, "union %s {\n", buf_ptr(&type_entry->name));
+ for (uint32_t field_i = 0; field_i < type_entry->data.unionation.src_field_count; field_i += 1) {
+ TypeUnionField *union_field = &type_entry->data.unionation.fields[field_i];
+
+ Buf *type_name_buf = buf_alloc();
+ get_c_type(g, gen_h, union_field->type_entry, type_name_buf);
+ fprintf(out_h, " %s %s;\n", buf_ptr(type_name_buf), buf_ptr(union_field->name));
+ }
+ fprintf(out_h, "};\n\n");
+ break;
+ case TypeTableEntryIdOpaque:
+ fprintf(out_h, "struct %s;\n\n", buf_ptr(&type_entry->name));
+ break;
+ }
+ }
+
fprintf(out_h, "%s", buf_ptr(&h_buf));
fprintf(out_h, "\n#endif\n");
--
cgit v1.2.3
From 470ec911640880872491d4f40b182be91fad5075 Mon Sep 17 00:00:00 2001
From: Marc Tiehuis
Date: Tue, 23 Jan 2018 23:38:20 +1300
Subject: Add array type handling for gen_h
---
src/codegen.cpp | 31 ++++++++++++++++++++++++++++---
test/gen_h.zig | 16 ++++++++++++++++
2 files changed, 44 insertions(+), 3 deletions(-)
(limited to 'src/codegen.cpp')
diff --git a/src/codegen.cpp b/src/codegen.cpp
index c79da04b05..ecbc49da5b 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -5977,6 +5977,16 @@ static void get_c_type(CodeGen *g, GenH *gen_h, TypeTableEntry *type_entry, Buf
return;
}
case TypeTableEntryIdArray:
+ {
+ TypeTableEntryArray *array_data = &type_entry->data.array;
+
+ Buf *child_buf = buf_alloc();
+ get_c_type(g, gen_h, array_data->child_type, child_buf);
+
+ buf_resize(out_buf, 0);
+ buf_appendf(out_buf, "%s", buf_ptr(child_buf));
+ return;
+ }
case TypeTableEntryIdErrorUnion:
case TypeTableEntryIdPureError:
case TypeTableEntryIdFn:
@@ -6081,8 +6091,15 @@ static void gen_h_file(CodeGen *g) {
const char *comma_str = (param_i == 0) ? "" : ", ";
const char *restrict_str = param_info->is_noalias ? "restrict" : "";
get_c_type(g, gen_h, param_info->type, ¶m_type_c);
- buf_appendf(&h_buf, "%s%s%s %s", comma_str, buf_ptr(¶m_type_c),
- restrict_str, buf_ptr(param_name));
+
+ if (param_info->type->id == TypeTableEntryIdArray) {
+ // Arrays decay to pointers
+ buf_appendf(&h_buf, "%s%s%s %s[]", comma_str, buf_ptr(¶m_type_c),
+ restrict_str, buf_ptr(param_name));
+ } else {
+ buf_appendf(&h_buf, "%s%s%s %s", comma_str, buf_ptr(¶m_type_c),
+ restrict_str, buf_ptr(param_name));
+ }
}
buf_appendf(&h_buf, ")");
} else {
@@ -6169,7 +6186,15 @@ static void gen_h_file(CodeGen *g) {
Buf *type_name_buf = buf_alloc();
get_c_type(g, gen_h, struct_field->type_entry, type_name_buf);
- fprintf(out_h, " %s %s;\n", buf_ptr(type_name_buf), buf_ptr(struct_field->name));
+
+ if (struct_field->type_entry->id == TypeTableEntryIdArray) {
+ fprintf(out_h, " %s %s[%d];\n", buf_ptr(type_name_buf),
+ buf_ptr(struct_field->name),
+ struct_field->type_entry->data.array.len);
+ } else {
+ fprintf(out_h, " %s %s;\n", buf_ptr(type_name_buf), buf_ptr(struct_field->name));
+ }
+
}
fprintf(out_h, "};\n\n");
break;
diff --git a/test/gen_h.zig b/test/gen_h.zig
index 7ecafbe876..82120d820e 100644
--- a/test/gen_h.zig
+++ b/test/gen_h.zig
@@ -50,4 +50,20 @@ pub fn addCases(cases: &tests.GenHContext) {
\\TEST_EXPORT void entry(union Foo foo);
\\
);
+
+ cases.add("array field-type",
+ \\const Foo = extern struct {
+ \\ A: [2]i32,
+ \\ B: [4]&u32,
+ \\};
+ \\export fn entry(foo: Foo, bar: [3]u8) { }
+ ,
+ \\struct Foo {
+ \\ int32_t A[2];
+ \\ uint32_t * B[4];
+ \\};
+ \\
+ \\TEST_EXPORT void entry(struct Foo foo, uint8_t bar[]);
+ \\
+ );
}
--
cgit v1.2.3
From c2838f24429d00debf43493c48caf739f57db023 Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Tue, 23 Jan 2018 11:40:22 -0500
Subject: fix printf format specifier
---
src/codegen.cpp | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
(limited to 'src/codegen.cpp')
diff --git a/src/codegen.cpp b/src/codegen.cpp
index ecbc49da5b..a53190f6b0 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -6188,7 +6188,7 @@ static void gen_h_file(CodeGen *g) {
get_c_type(g, gen_h, struct_field->type_entry, type_name_buf);
if (struct_field->type_entry->id == TypeTableEntryIdArray) {
- fprintf(out_h, " %s %s[%d];\n", buf_ptr(type_name_buf),
+ fprintf(out_h, " %s %s[%" ZIG_PRI_u64 "];\n", buf_ptr(type_name_buf),
buf_ptr(struct_field->name),
struct_field->type_entry->data.array.len);
} else {
--
cgit v1.2.3
From e5bc5873d74713bedbc32817ed31370c3256418d Mon Sep 17 00:00:00 2001
From: Andrew Kelley
Date: Thu, 25 Jan 2018 01:46:12 -0500
Subject: rename "debug safety" to "runtime safety"
closes #437
---
build.zig | 2 +-
doc/docgen.zig | 2 +-
doc/langref.html.in | 12 +-
src-self-hosted/ir.zig | 2 +-
src/all_types.hpp | 9 +-
src/codegen.cpp | 136 ++++++++--------
src/ir.cpp | 111 ++++++-------
src/ir_print.cpp | 12 +-
std/math/index.zig | 12 +-
std/mem.zig | 4 +-
std/special/builtin.zig | 8 +-
std/special/compiler_rt/aulldiv.zig | 2 +-
std/special/compiler_rt/aullrem.zig | 2 +-
std/special/compiler_rt/comparetf2.zig | 6 +-
std/special/compiler_rt/fixuint.zig | 6 +-
std/special/compiler_rt/fixunsdfdi.zig | 2 +-
std/special/compiler_rt/fixunsdfsi.zig | 2 +-
std/special/compiler_rt/fixunsdfti.zig | 2 +-
std/special/compiler_rt/fixunssfdi.zig | 2 +-
std/special/compiler_rt/fixunssfsi.zig | 2 +-
std/special/compiler_rt/fixunssfti.zig | 2 +-
std/special/compiler_rt/fixunstfdi.zig | 2 +-
std/special/compiler_rt/fixunstfsi.zig | 2 +-
std/special/compiler_rt/fixunstfti.zig | 2 +-
std/special/compiler_rt/index.zig | 22 +--
std/special/compiler_rt/udivmod.zig | 2 +-
std/special/compiler_rt/udivmoddi4.zig | 2 +-
std/special/compiler_rt/udivmodti4.zig | 2 +-
std/special/compiler_rt/udivti3.zig | 2 +-
std/special/compiler_rt/umodti3.zig | 2 +-
test/cases/eval.zig | 8 +-
test/cases/slice.zig | 2 +-
test/compile_errors.zig | 8 +-
test/debug_safety.zig | 286 ---------------------------------
test/runtime_safety.zig | 286 +++++++++++++++++++++++++++++++++
test/tests.zig | 30 ++--
36 files changed, 487 insertions(+), 509 deletions(-)
delete mode 100644 test/debug_safety.zig
create mode 100644 test/runtime_safety.zig
(limited to 'src/codegen.cpp')
diff --git a/build.zig b/build.zig
index d48c58bbff..b3a3248612 100644
--- a/build.zig
+++ b/build.zig
@@ -116,7 +116,7 @@ pub fn build(b: &Builder) -> %void {
test_step.dependOn(tests.addBuildExampleTests(b, test_filter));
test_step.dependOn(tests.addCompileErrorTests(b, test_filter));
test_step.dependOn(tests.addAssembleAndLinkTests(b, test_filter));
- test_step.dependOn(tests.addDebugSafetyTests(b, test_filter));
+ test_step.dependOn(tests.addRuntimeSafetyTests(b, test_filter));
test_step.dependOn(tests.addTranslateCTests(b, test_filter));
test_step.dependOn(tests.addGenHTests(b, test_filter));
}
diff --git a/doc/docgen.zig b/doc/docgen.zig
index 4007fa099c..811dad6df8 100644
--- a/doc/docgen.zig
+++ b/doc/docgen.zig
@@ -896,7 +896,7 @@ fn genHtml(allocator: &mem.Allocator, tokenizer: &Tokenizer, toc: &Toc, out: &io
}
if (mem.indexOf(u8, result.stderr, error_match) == null) {
warn("{}\nExpected to find '{}' in stderr", result.stderr, error_match);
- return parseError(tokenizer, code.source_token, "example did not have expected debug safety error message");
+ return parseError(tokenizer, code.source_token, "example did not have expected runtime safety error message");
}
const escaped_stderr = try escapeHtml(allocator, result.stderr);
const colored_stderr = try termColor(allocator, escaped_stderr);
diff --git a/doc/langref.html.in b/doc/langref.html.in
index de029fd236..09a0f48c40 100644
--- a/doc/langref.html.in
+++ b/doc/langref.html.in
@@ -3090,7 +3090,7 @@ fn doAThing(nullable_foo: ?&Foo) {
{#header_open|this#}
TODO: example of this referring to Self struct
TODO: example of this referring to recursion function
- TODO: example of this referring to basic block for @setDebugSafety
+ TODO: example of this referring to basic block for @setRuntimeSafety
{#header_close#}
{#header_open|comptime#}
@@ -4325,10 +4325,10 @@ test "call foo" {
Tells the optimizer that a function is rarely called.
{#header_close#}
- {#header_open|@setDebugSafety#}
- @setDebugSafety(scope, safety_on: bool)
+ {#header_open|@setRuntimeSafety#}
+ @setRuntimeSafety(safety_on: bool)
- Sets whether debug safety checks are on for a given scope.
+ Sets whether runtime safety checks are on for the scope that contains the function call.
{#header_close#}
@@ -4595,7 +4595,7 @@ pub fn build(b: &Builder) -> %void {
detected at compile-time, Zig emits an error. Most undefined behavior that
cannot be detected at compile-time can be detected at runtime. In these cases,
Zig has safety checks. Safety checks can be disabled on a per-block basis
- with @setDebugSafety. The {#link|ReleaseFast#}
+ with @setRuntimeSafety. The {#link|ReleaseFast#}
build mode disables all safety checks in order to facilitate optimizations.
@@ -5765,7 +5765,7 @@ hljs.registerLanguage("zig", function(t) {
a = t.IR + "\\s*\\(",
c = {
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",
- 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",
+ 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",
literal: "true false null undefined"
},
n = [e, t.CLCM, t.CBCM, s, r];
diff --git a/src-self-hosted/ir.zig b/src-self-hosted/ir.zig
index b25bb183c5..b66a0abdee 100644
--- a/src-self-hosted/ir.zig
+++ b/src-self-hosted/ir.zig
@@ -33,7 +33,7 @@ pub const Instruction = struct {
TypeOf,
ToPtrType,
PtrTypeChild,
- SetDebugSafety,
+ SetRuntimeSafety,
SetFloatMode,
ArrayType,
SliceType,
diff --git a/src/all_types.hpp b/src/all_types.hpp
index e6cf9bd701..d3dbdec06b 100644
--- a/src/all_types.hpp
+++ b/src/all_types.hpp
@@ -1255,7 +1255,7 @@ enum BuiltinFnId {
BuiltinFnIdTruncate,
BuiltinFnIdIntType,
BuiltinFnIdSetCold,
- BuiltinFnIdSetDebugSafety,
+ BuiltinFnIdSetRuntimeSafety,
BuiltinFnIdSetFloatMode,
BuiltinFnIdTypeName,
BuiltinFnIdCanImplicitCast,
@@ -1836,7 +1836,7 @@ enum IrInstructionId {
IrInstructionIdToPtrType,
IrInstructionIdPtrTypeChild,
IrInstructionIdSetCold,
- IrInstructionIdSetDebugSafety,
+ IrInstructionIdSetRuntimeSafety,
IrInstructionIdSetFloatMode,
IrInstructionIdArrayType,
IrInstructionIdSliceType,
@@ -2214,11 +2214,10 @@ struct IrInstructionSetCold {
IrInstruction *is_cold;
};
-struct IrInstructionSetDebugSafety {
+struct IrInstructionSetRuntimeSafety {
IrInstruction base;
- IrInstruction *scope_value;
- IrInstruction *debug_safety_on;
+ IrInstruction *safety_on;
};
struct IrInstructionSetFloatMode {
diff --git a/src/codegen.cpp b/src/codegen.cpp
index a53190f6b0..b1412b2b59 100644
--- a/src/codegen.cpp
+++ b/src/codegen.cpp
@@ -806,7 +806,7 @@ static bool ir_want_fast_math(CodeGen *g, IrInstruction *instruction) {
return true;
}
-static bool ir_want_debug_safety(CodeGen *g, IrInstruction *instruction) {
+static bool ir_want_runtime_safety(CodeGen *g, IrInstruction *instruction) {
if (g->build_mode == BuildModeFastRelease)
return false;
@@ -901,7 +901,7 @@ static void gen_panic(CodeGen *g, LLVMValueRef msg_arg, LLVMValueRef stack_trace
LLVMBuildUnreachable(g->builder);
}
-static void gen_debug_safety_crash(CodeGen *g, PanicMsgId msg_id) {
+static void gen_safety_crash(CodeGen *g, PanicMsgId msg_id) {
gen_panic(g, get_panic_msg_ptr_val(g, msg_id), nullptr);
}
@@ -1140,7 +1140,7 @@ static LLVMValueRef get_safety_crash_err_fn(CodeGen *g) {
return fn_val;
}
-static void gen_debug_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val) {
+static void gen_safety_crash_for_err(CodeGen *g, LLVMValueRef err_val) {
LLVMValueRef safety_crash_err_fn = get_safety_crash_err_fn(g);
LLVMValueRef err_ret_trace_val = g->cur_err_ret_trace_val;
if (err_ret_trace_val == nullptr) {
@@ -1179,7 +1179,7 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,
LLVMBuildCondBr(g->builder, lower_ok_val, lower_ok_block, bounds_check_fail_block);
LLVMPositionBuilderAtEnd(g->builder, bounds_check_fail_block);
- gen_debug_safety_crash(g, PanicMsgIdBoundsCheckFailure);
+ gen_safety_crash(g, PanicMsgIdBoundsCheckFailure);
if (upper_value) {
LLVMPositionBuilderAtEnd(g->builder, lower_ok_block);
@@ -1190,7 +1190,7 @@ static void add_bounds_check(CodeGen *g, LLVMValueRef target_val,
LLVMPositionBuilderAtEnd(g->builder, ok_block);
}
-static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, TypeTableEntry *actual_type,
+static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_runtime_safety, TypeTableEntry *actual_type,
TypeTableEntry *wanted_type, LLVMValueRef expr_val)
{
assert(actual_type->id == wanted_type->id);
@@ -1209,7 +1209,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ
if (actual_bits >= wanted_bits && actual_type->id == TypeTableEntryIdInt &&
!wanted_type->data.integral.is_signed && actual_type->data.integral.is_signed &&
- want_debug_safety)
+ want_runtime_safety)
{
LLVMValueRef zero = LLVMConstNull(actual_type->type_ref);
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
LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdCastNegativeToUnsigned);
+ gen_safety_crash(g, PanicMsgIdCastNegativeToUnsigned);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
}
@@ -1243,7 +1243,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ
return LLVMBuildFPTrunc(g->builder, expr_val, wanted_type->type_ref, "");
} else if (actual_type->id == TypeTableEntryIdInt) {
LLVMValueRef trunc_val = LLVMBuildTrunc(g->builder, expr_val, wanted_type->type_ref, "");
- if (!want_debug_safety) {
+ if (!want_runtime_safety) {
return trunc_val;
}
LLVMValueRef orig_val;
@@ -1258,7 +1258,7 @@ static LLVMValueRef gen_widen_or_shorten(CodeGen *g, bool want_debug_safety, Typ
LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdCastTruncatedData);
+ gen_safety_crash(g, PanicMsgIdCastTruncatedData);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
return trunc_val;
@@ -1286,7 +1286,7 @@ static LLVMValueRef gen_overflow_op(CodeGen *g, TypeTableEntry *type_entry, AddS
LLVMBuildCondBr(g->builder, overflow_bit, fail_block, ok_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdIntegerOverflow);
+ gen_safety_crash(g, PanicMsgIdIntegerOverflow);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
return result;
@@ -1494,7 +1494,7 @@ static LLVMValueRef gen_overflow_shl_op(CodeGen *g, TypeTableEntry *type_entry,
LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdShlOverflowedBits);
+ gen_safety_crash(g, PanicMsgIdShlOverflowedBits);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
return result;
@@ -1519,7 +1519,7 @@ static LLVMValueRef gen_overflow_shr_op(CodeGen *g, TypeTableEntry *type_entry,
LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdShrOverflowedBits);
+ gen_safety_crash(g, PanicMsgIdShrOverflowedBits);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
return result;
@@ -1565,14 +1565,14 @@ static LLVMValueRef bigint_to_llvm_const(LLVMTypeRef type_ref, BigInt *bigint) {
}
}
-static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_math,
+static LLVMValueRef gen_div(CodeGen *g, bool want_runtime_safety, bool want_fast_math,
LLVMValueRef val1, LLVMValueRef val2,
TypeTableEntry *type_entry, DivKind div_kind)
{
ZigLLVMSetFastMath(g->builder, want_fast_math);
LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
- if (want_debug_safety && (want_fast_math || type_entry->id != TypeTableEntryIdFloat)) {
+ if (want_runtime_safety && (want_fast_math || type_entry->id != TypeTableEntryIdFloat)) {
LLVMValueRef is_zero_bit;
if (type_entry->id == TypeTableEntryIdInt) {
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
LLVMBuildCondBr(g->builder, is_zero_bit, div_zero_fail_block, div_zero_ok_block);
LLVMPositionBuilderAtEnd(g->builder, div_zero_fail_block);
- gen_debug_safety_crash(g, PanicMsgIdDivisionByZero);
+ gen_safety_crash(g, PanicMsgIdDivisionByZero);
LLVMPositionBuilderAtEnd(g->builder, div_zero_ok_block);
@@ -1603,7 +1603,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m
LLVMBuildCondBr(g->builder, overflow_fail_bit, overflow_fail_block, overflow_ok_block);
LLVMPositionBuilderAtEnd(g->builder, overflow_fail_block);
- gen_debug_safety_crash(g, PanicMsgIdIntegerOverflow);
+ gen_safety_crash(g, PanicMsgIdIntegerOverflow);
LLVMPositionBuilderAtEnd(g->builder, overflow_ok_block);
}
@@ -1615,7 +1615,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m
case DivKindFloat:
return result;
case DivKindExact:
- if (want_debug_safety) {
+ if (want_runtime_safety) {
LLVMValueRef floored = gen_floor(g, result, type_entry);
LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "DivExactOk");
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
LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdExactDivisionRemainder);
+ gen_safety_crash(g, PanicMsgIdExactDivisionRemainder);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
}
@@ -1672,7 +1672,7 @@ static LLVMValueRef gen_div(CodeGen *g, bool want_debug_safety, bool want_fast_m
return LLVMBuildUDiv(g->builder, val1, val2, "");
}
case DivKindExact:
- if (want_debug_safety) {
+ if (want_runtime_safety) {
LLVMValueRef remainder_val;
if (type_entry->data.integral.is_signed) {
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
LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdExactDivisionRemainder);
+ gen_safety_crash(g, PanicMsgIdExactDivisionRemainder);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
}
@@ -1724,14 +1724,14 @@ enum RemKind {
RemKindMod,
};
-static LLVMValueRef gen_rem(CodeGen *g, bool want_debug_safety, bool want_fast_math,
+static LLVMValueRef gen_rem(CodeGen *g, bool want_runtime_safety, bool want_fast_math,
LLVMValueRef val1, LLVMValueRef val2,
TypeTableEntry *type_entry, RemKind rem_kind)
{
ZigLLVMSetFastMath(g->builder, want_fast_math);
LLVMValueRef zero = LLVMConstNull(type_entry->type_ref);
- if (want_debug_safety) {
+ if (want_runtime_safety) {
LLVMValueRef is_zero_bit;
if (type_entry->id == TypeTableEntryIdInt) {
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
LLVMBuildCondBr(g->builder, is_zero_bit, rem_zero_fail_block, rem_zero_ok_block);
LLVMPositionBuilderAtEnd(g->builder, rem_zero_fail_block);
- gen_debug_safety_crash(g, PanicMsgIdRemainderDivisionByZero);
+ gen_safety_crash(g, PanicMsgIdRemainderDivisionByZero);
LLVMPositionBuilderAtEnd(g->builder, rem_zero_ok_block);
}
@@ -1792,8 +1792,8 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
op_id == IrBinOpBitShiftRightExact);
TypeTableEntry *type_entry = op1->value.type;
- bool want_debug_safety = bin_op_instruction->safety_check_on &&
- ir_want_debug_safety(g, &bin_op_instruction->base);
+ bool want_runtime_safety = bin_op_instruction->safety_check_on &&
+ ir_want_runtime_safety(g, &bin_op_instruction->base);
LLVMValueRef op1_value = ir_llvm_value(g, op1);
LLVMValueRef op2_value = ir_llvm_value(g, op2);
@@ -1841,7 +1841,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
bool is_wrapping = (op_id == IrBinOpAddWrap);
if (is_wrapping) {
return LLVMBuildAdd(g->builder, op1_value, op2_value, "");
- } else if (want_debug_safety) {
+ } else if (want_runtime_safety) {
return gen_overflow_op(g, type_entry, AddSubMulAdd, op1_value, op2_value);
} else if (type_entry->data.integral.is_signed) {
return LLVMBuildNSWAdd(g->builder, op1_value, op2_value, "");
@@ -1866,7 +1866,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
bool is_sloppy = (op_id == IrBinOpBitShiftLeftLossy);
if (is_sloppy) {
return LLVMBuildShl(g->builder, op1_value, op2_casted, "");
- } else if (want_debug_safety) {
+ } else if (want_runtime_safety) {
return gen_overflow_shl_op(g, type_entry, op1_value, op2_casted);
} else if (type_entry->data.integral.is_signed) {
return ZigLLVMBuildNSWShl(g->builder, op1_value, op2_casted, "");
@@ -1887,7 +1887,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
} else {
return LLVMBuildLShr(g->builder, op1_value, op2_casted, "");
}
- } else if (want_debug_safety) {
+ } else if (want_runtime_safety) {
return gen_overflow_shr_op(g, type_entry, op1_value, op2_casted);
} else if (type_entry->data.integral.is_signed) {
return ZigLLVMBuildAShrExact(g->builder, op1_value, op2_casted, "");
@@ -1904,7 +1904,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
bool is_wrapping = (op_id == IrBinOpSubWrap);
if (is_wrapping) {
return LLVMBuildSub(g->builder, op1_value, op2_value, "");
- } else if (want_debug_safety) {
+ } else if (want_runtime_safety) {
return gen_overflow_op(g, type_entry, AddSubMulSub, op1_value, op2_value);
} else if (type_entry->data.integral.is_signed) {
return LLVMBuildNSWSub(g->builder, op1_value, op2_value, "");
@@ -1923,7 +1923,7 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
bool is_wrapping = (op_id == IrBinOpMultWrap);
if (is_wrapping) {
return LLVMBuildMul(g->builder, op1_value, op2_value, "");
- } else if (want_debug_safety) {
+ } else if (want_runtime_safety) {
return gen_overflow_op(g, type_entry, AddSubMulMul, op1_value, op2_value);
} else if (type_entry->data.integral.is_signed) {
return LLVMBuildNSWMul(g->builder, op1_value, op2_value, "");
@@ -1934,22 +1934,22 @@ static LLVMValueRef ir_render_bin_op(CodeGen *g, IrExecutable *executable,
zig_unreachable();
}
case IrBinOpDivUnspecified:
- return gen_div(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),
+ return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
op1_value, op2_value, type_entry, DivKindFloat);
case IrBinOpDivExact:
- return gen_div(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),
+ return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
op1_value, op2_value, type_entry, DivKindExact);
case IrBinOpDivTrunc:
- return gen_div(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),
+ return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
op1_value, op2_value, type_entry, DivKindTrunc);
case IrBinOpDivFloor:
- return gen_div(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),
+ return gen_div(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
op1_value, op2_value, type_entry, DivKindFloor);
case IrBinOpRemRem:
- return gen_rem(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),
+ return gen_rem(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
op1_value, op2_value, type_entry, RemKindRem);
case IrBinOpRemMod:
- return gen_rem(g, want_debug_safety, ir_want_fast_math(g, &bin_op_instruction->base),
+ return gen_rem(g, want_runtime_safety, ir_want_fast_math(g, &bin_op_instruction->base),
op1_value, op2_value, type_entry, RemKindMod);
}
zig_unreachable();
@@ -2007,7 +2007,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
new_len = LLVMBuildMul(g->builder, src_len, src_size_val, "");
} else if (src_size == 1) {
LLVMValueRef dest_size_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, dest_size, false);
- if (ir_want_debug_safety(g, &cast_instruction->base)) {
+ if (ir_want_runtime_safety(g, &cast_instruction->base)) {
LLVMValueRef remainder_val = LLVMBuildURem(g->builder, src_len, dest_size_val, "");
LLVMValueRef zero = LLVMConstNull(g->builtin_types.entry_usize->type_ref);
LLVMValueRef ok_bit = LLVMBuildICmp(g->builder, LLVMIntEQ, remainder_val, zero, "");
@@ -2016,7 +2016,7 @@ static LLVMValueRef ir_render_cast(CodeGen *g, IrExecutable *executable,
LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdSliceWidenRemainder);
+ gen_safety_crash(g, PanicMsgIdSliceWidenRemainder);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
}
@@ -2111,7 +2111,7 @@ static LLVMValueRef ir_render_widen_or_shorten(CodeGen *g, IrExecutable *executa
int_type = actual_type;
}
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
- return gen_widen_or_shorten(g, ir_want_debug_safety(g, &instruction->base), int_type,
+ return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base), int_type,
instruction->base.value.type, target_val);
}
@@ -2133,7 +2133,7 @@ static LLVMValueRef ir_render_int_to_enum(CodeGen *g, IrExecutable *executable,
TypeTableEntry *tag_int_type = wanted_type->data.enumeration.tag_int_type;
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
- return gen_widen_or_shorten(g, ir_want_debug_safety(g, &instruction->base),
+ return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
instruction->target->value.type, tag_int_type, target_val);
}
@@ -2147,7 +2147,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
- if (ir_want_debug_safety(g, &instruction->base)) {
+ if (ir_want_runtime_safety(g, &instruction->base)) {
LLVMValueRef zero = LLVMConstNull(actual_type->type_ref);
LLVMValueRef neq_zero_bit = LLVMBuildICmp(g->builder, LLVMIntNE, target_val, zero, "");
LLVMValueRef ok_bit;
@@ -2171,7 +2171,7 @@ static LLVMValueRef ir_render_int_to_err(CodeGen *g, IrExecutable *executable, I
LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdInvalidErrorCode);
+ gen_safety_crash(g, PanicMsgIdInvalidErrorCode);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
}
@@ -2188,11 +2188,11 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
if (actual_type->id == TypeTableEntryIdPureError) {
- return gen_widen_or_shorten(g, ir_want_debug_safety(g, &instruction->base),
+ return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
g->err_tag_type, wanted_type, target_val);
} else if (actual_type->id == TypeTableEntryIdErrorUnion) {
if (!type_has_bits(actual_type->data.error.child_type)) {
- return gen_widen_or_shorten(g, ir_want_debug_safety(g, &instruction->base),
+ return gen_widen_or_shorten(g, ir_want_runtime_safety(g, &instruction->base),
g->err_tag_type, wanted_type, target_val);
} else {
zig_panic("TODO");
@@ -2205,8 +2205,8 @@ static LLVMValueRef ir_render_err_to_int(CodeGen *g, IrExecutable *executable, I
static LLVMValueRef ir_render_unreachable(CodeGen *g, IrExecutable *executable,
IrInstructionUnreachable *unreachable_instruction)
{
- if (ir_want_debug_safety(g, &unreachable_instruction->base)) {
- gen_debug_safety_crash(g, PanicMsgIdUnreachable);
+ if (ir_want_runtime_safety(g, &unreachable_instruction->base)) {
+ gen_safety_crash(g, PanicMsgIdUnreachable);
} else {
LLVMBuildUnreachable(g->builder);
}
@@ -2248,7 +2248,7 @@ static LLVMValueRef ir_render_un_op(CodeGen *g, IrExecutable *executable, IrInst
} else if (expr_type->id == TypeTableEntryIdInt) {
if (op_id == IrUnOpNegationWrap) {
return LLVMBuildNeg(g->builder, expr, "");
- } else if (ir_want_debug_safety(g, &un_op_instruction->base)) {
+ } else if (ir_want_runtime_safety(g, &un_op_instruction->base)) {
LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(expr));
return gen_overflow_op(g, expr_type, AddSubMulSub, zero, expr);
} else if (expr_type->data.integral.is_signed) {
@@ -2317,7 +2317,7 @@ static LLVMValueRef ir_render_decl_var(CodeGen *g, IrExecutable *executable,
var->align_bytes, 0, 0);
gen_assign_raw(g, var->value_ref, var_ptr_type, ir_llvm_value(g, init_value));
} else {
- bool want_safe = ir_want_debug_safety(g, &decl_var_instruction->base);
+ bool want_safe = ir_want_runtime_safety(g, &decl_var_instruction->base);
if (want_safe) {
TypeTableEntry *usize = g->builtin_types.entry_usize;
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
if (!type_has_bits(array_type))
return nullptr;
- bool safety_check_on = ir_want_debug_safety(g, &instruction->base) && instruction->safety_check_on;
+ bool safety_check_on = ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on;
if (array_type->id == TypeTableEntryIdArray) {
if (safety_check_on) {
@@ -2593,7 +2593,7 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab
return bitcasted_union_field_ptr;
}
- if (ir_want_debug_safety(g, &instruction->base)) {
+ if (ir_want_runtime_safety(g, &instruction->base)) {
LLVMValueRef tag_field_ptr = LLVMBuildStructGEP(g->builder, union_ptr, union_type->data.unionation.gen_tag_index, "");
LLVMValueRef tag_value = gen_load_untyped(g, tag_field_ptr, 0, false, "");
@@ -2606,7 +2606,7 @@ static LLVMValueRef ir_render_union_field_ptr(CodeGen *g, IrExecutable *executab
LLVMBuildCondBr(g->builder, ok_val, ok_block, bad_block);
LLVMPositionBuilderAtEnd(g->builder, bad_block);
- gen_debug_safety_crash(g, PanicMsgIdBadUnionField);
+ gen_safety_crash(g, PanicMsgIdBadUnionField);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
}
@@ -2776,14 +2776,14 @@ static LLVMValueRef ir_render_unwrap_maybe(CodeGen *g, IrExecutable *executable,
TypeTableEntry *child_type = maybe_type->data.maybe.child_type;
LLVMValueRef maybe_ptr = ir_llvm_value(g, instruction->value);
LLVMValueRef maybe_handle = get_handle_value(g, maybe_ptr, maybe_type, ptr_type);
- if (ir_want_debug_safety(g, &instruction->base) && instruction->safety_check_on) {
+ if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on) {
LLVMValueRef non_null_bit = gen_non_null_bit(g, maybe_type, maybe_handle);
LLVMBasicBlockRef ok_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeOk");
LLVMBasicBlockRef fail_block = LLVMAppendBasicBlock(g->cur_fn_val, "UnwrapMaybeFail");
LLVMBuildCondBr(g->builder, non_null_bit, ok_block, fail_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdUnwrapMaybeFail);
+ gen_safety_crash(g, PanicMsgIdUnwrapMaybeFail);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
}
@@ -2913,7 +2913,7 @@ static LLVMValueRef ir_render_err_name(CodeGen *g, IrExecutable *executable, IrI
}
LLVMValueRef err_val = ir_llvm_value(g, instruction->value);
- if (ir_want_debug_safety(g, &instruction->base)) {
+ if (ir_want_runtime_safety(g, &instruction->base)) {
LLVMValueRef zero = LLVMConstNull(LLVMTypeOf(err_val));
LLVMValueRef end_val = LLVMConstInt(LLVMTypeOf(err_val), g->error_decls.length, false);
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
TypeTableEntry *tag_int_type = enum_type->data.enumeration.tag_int_type;
LLVMValueRef enum_tag_value = ir_llvm_value(g, instruction->target);
- if (ir_want_debug_safety(g, &instruction->base)) {
+ if (ir_want_runtime_safety(g, &instruction->base)) {
size_t field_count = enum_type->data.enumeration.src_field_count;
// 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
LLVMValueRef target_val = ir_llvm_value(g, instruction->target);
assert(target_val);
- bool want_debug_safety = ir_want_debug_safety(g, &instruction->base);
- if (!want_debug_safety) {
+ bool want_runtime_safety = ir_want_runtime_safety(g, &instruction->base);
+ if (!want_runtime_safety) {
return target_val;
}
@@ -3038,7 +3038,7 @@ static LLVMValueRef ir_render_align_cast(CodeGen *g, IrExecutable *executable, I
LLVMBuildCondBr(g->builder, ok_bit, ok_block, fail_block);
LLVMPositionBuilderAtEnd(g->builder, fail_block);
- gen_debug_safety_crash(g, PanicMsgIdIncorrectAlignment);
+ gen_safety_crash(g, PanicMsgIdIncorrectAlignment);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
@@ -3176,7 +3176,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
LLVMValueRef tmp_struct_ptr = instruction->tmp_ptr;
- bool want_debug_safety = instruction->safety_check_on && ir_want_debug_safety(g, &instruction->base);
+ bool want_runtime_safety = instruction->safety_check_on && ir_want_runtime_safety(g, &instruction->base);
if (array_type->id == TypeTableEntryIdArray) {
LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
@@ -3187,7 +3187,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
end_val = LLVMConstInt(g->builtin_types.entry_usize->type_ref, array_type->data.array.len, false);
}
- if (want_debug_safety) {
+ if (want_runtime_safety) {
add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);
if (instruction->end) {
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
if (!type_has_bits(array_type)) {
LLVMValueRef len_field_ptr = LLVMBuildStructGEP(g->builder, tmp_struct_ptr, slice_len_index, "");
- // TODO if debug safety is on, store 0xaaaaaaa in ptr field
+ // TODO if runtime safety is on, store 0xaaaaaaa in ptr field
LLVMValueRef len_value = LLVMBuildNSWSub(g->builder, end_val, start_val, "");
gen_store_untyped(g, len_value, len_field_ptr, 0, false);
return tmp_struct_ptr;
@@ -3222,7 +3222,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
LLVMValueRef start_val = ir_llvm_value(g, instruction->start);
LLVMValueRef end_val = ir_llvm_value(g, instruction->end);
- if (want_debug_safety) {
+ if (want_runtime_safety) {
add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);
}
@@ -3246,7 +3246,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
assert(len_index != SIZE_MAX);
LLVMValueRef prev_end = nullptr;
- if (!instruction->end || want_debug_safety) {
+ if (!instruction->end || want_runtime_safety) {
LLVMValueRef src_len_ptr = LLVMBuildStructGEP(g->builder, array_ptr, (unsigned)len_index, "");
prev_end = gen_load_untyped(g, src_len_ptr, 0, false, "");
}
@@ -3259,7 +3259,7 @@ static LLVMValueRef ir_render_slice(CodeGen *g, IrExecutable *executable, IrInst
end_val = prev_end;
}
- if (want_debug_safety) {
+ if (want_runtime_safety) {
assert(prev_end);
add_bounds_check(g, start_val, LLVMIntEQ, nullptr, LLVMIntULE, end_val);
if (instruction->end) {
@@ -3432,7 +3432,7 @@ static LLVMValueRef ir_render_unwrap_err_payload(CodeGen *g, IrExecutable *execu
LLVMValueRef err_union_ptr = ir_llvm_value(g, instruction->value);
LLVMValueRef err_union_handle = get_handle_value(g, err_union_ptr, err_union_type, ptr_type);
- if (ir_want_debug_safety(g, &instruction->base) && instruction->safety_check_on && g->error_decls.length > 1) {
+ if (ir_want_runtime_safety(g, &instruction->base) && instruction->safety_check_on && g->error_decls.length > 1) {
LLVMValueRef err_val;
if (type_has_bits(child_type)) {
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
LLVMBuildCondBr(g->builder, cond_val, ok_block, err_block);
LLVMPositionBuilderAtEnd(g->builder, err_block);
- gen_debug_safety_crash_for_err(g, err_val);
+ gen_safety_crash_for_err(g, err_val);
LLVMPositionBuilderAtEnd(g->builder, ok_block);
}
@@ -3660,7 +3660,7 @@ static LLVMValueRef ir_render_instruction(CodeGen *g, IrExecutable *executable,
case IrInstructionIdPtrTypeChild:
case IrInstructionIdFieldPtr:
case IrInstructionIdSetCold:
- case IrInstructionIdSetDebugSafety:
+ case IrInstructionIdSetRuntimeSafety:
case IrInstructionIdSetFloatMode:
case IrInstructionIdArrayType:
case IrInstructionIdSliceType:
@@ -5238,7 +5238,7 @@ static void define_builtin_fns(CodeGen *g) {
create_builtin_fn(g, BuiltinFnIdCompileLog, "compileLog", SIZE_MAX);
create_builtin_fn(g, BuiltinFnIdIntType, "IntType", 2); // TODO rename to Int
create_builtin_fn(g, BuiltinFnIdSetCold, "setCold", 1);
- create_builtin_fn(g, BuiltinFnIdSetDebugSafety, "setDebugSafety", 2);
+ create_builtin_fn(g, BuiltinFnIdSetRuntimeSafety, "setRuntimeSafety", 1);
create_builtin_fn(g, BuiltinFnIdSetFloatMode, "setFloatMode", 2);
create_builtin_fn(g, BuiltinFnIdPanic, "panic", 1);
create_builtin_fn(g, BuiltinFnIdPtrCast, "ptrCast", 2);
diff --git a/src/ir.cpp b/src/ir.cpp
index 66d579239a..c8afd27945 100644
--- a/src/ir.cpp
+++ b/src/ir.cpp
@@ -276,8 +276,8 @@ static constexpr IrInstructionId ir_instruction_id(IrInstructionSetCold *) {
return IrInstructionIdSetCold;
}
-static constexpr IrInstructionId ir_instruction_id(IrInstructionSetDebugSafety *) {
- return IrInstructionIdSetDebugSafety;
+static constexpr IrInstructionId ir_instruction_id(IrInstructionSetRuntimeSafety *) {
+ return IrInstructionIdSetRuntimeSafety;
}
static constexpr IrInstructionId ir_instruction_id(IrInstructionSetFloatMode *) {
@@ -1275,15 +1275,13 @@ static IrInstruction *ir_build_set_cold(IrBuilder *irb, Scope *scope, AstNode *s
return &instruction->base;
}
-static IrInstruction *ir_build_set_debug_safety(IrBuilder *irb, Scope *scope, AstNode *source_node,
- IrInstruction *scope_value, IrInstruction *debug_safety_on)
+static IrInstruction *ir_build_set_runtime_safety(IrBuilder *irb, Scope *scope, AstNode *source_node,
+ IrInstruction *safety_on)
{
- IrInstructionSetDebugSafety *instruction = ir_build_instruction(irb, scope, source_node);
- instruction->scope_value = scope_value;
- instruction->debug_safety_on = debug_safety_on;
+ IrInstructionSetRuntimeSafety *instruction = ir_build_instruction(irb, scope, source_node);
+ instruction->safety_on = safety_on;
- ir_ref_instruction(scope_value, irb->current_basic_block);
- ir_ref_instruction(debug_safety_on, irb->current_basic_block);
+ ir_ref_instruction(safety_on, irb->current_basic_block);
return &instruction->base;
}
@@ -3087,19 +3085,14 @@ static IrInstruction *ir_gen_builtin_fn_call(IrBuilder *irb, Scope *scope, AstNo
return ir_build_set_cold(irb, scope, node, arg0_value);
}
- case BuiltinFnIdSetDebugSafety:
+ case BuiltinFnIdSetRuntimeSafety:
{
AstNode *arg0_node = node->data.fn_call_expr.params.at(0);
IrInstruction *arg0_value = ir_gen_node(irb, arg0_node, scope);
if (arg0_value == irb->codegen->invalid_instruction)
return arg0_value;
- AstNode *arg1_node = node->data.fn_call_expr.params.at(1);
- IrInstruction *arg1_value = ir_gen_node(irb, arg1_node, scope);
- if (arg1_value == irb->codegen->invalid_instruction)
- return arg1_value;
-
- return ir_build_set_debug_safety(irb, scope, node, arg0_value, arg1_value);
+ return ir_build_set_runtime_safety(irb, scope, node, arg0_value);
}
case BuiltinFnIdSetFloatMode:
{
@@ -11607,72 +11600,60 @@ static TypeTableEntry *ir_analyze_instruction_set_cold(IrAnalyze *ira, IrInstruc
ir_build_const_from(ira, &instruction->base);
return ira->codegen->builtin_types.entry_void;
}
-static TypeTableEntry *ir_analyze_instruction_set_debug_safety(IrAnalyze *ira,
- IrInstructionSetDebugSafety *set_debug_safety_instruction)
+static TypeTableEntry *ir_analyze_instruction_set_runtime_safety(IrAnalyze *ira,
+ IrInstructionSetRuntimeSafety *set_runtime_safety_instruction)
{
- IrInstruction *target_instruction = set_debug_safety_instruction->scope_value->other;
- TypeTableEntry *target_type = target_instruction->value.type;
- if (type_is_invalid(target_type))
- return ira->codegen->builtin_types.entry_invalid;
- ConstExprValue *target_val = ir_resolve_const(ira, target_instruction, UndefBad);
- if (!target_val)
- return ira->codegen->builtin_types.entry_invalid;
-
if (ira->new_irb.exec->is_inline) {
- // ignore setDebugSafety when running functions at compile time
- ir_build_const_from(ira, &set_debug_safety_instruction->base);
+ // ignore setRuntimeSafety when running functions at compile time
+ ir_build_const_from(ira, &set_runtime_safety_instruction->base);
return ira->codegen->builtin_types.entry_void;
}
bool *safety_off_ptr;
AstNode **safety_set_node_ptr;
- if (target_type->id == TypeTableEntryIdBlock) {
- ScopeBlock *block_scope = (ScopeBlock *)target_val->data.x_block;
- safety_off_ptr = &block_scope->safety_off;
- safety_set_node_ptr = &block_scope->safety_set_node;
- } else if (target_type->id == TypeTableEntryIdFn) {
- FnTableEntry *target_fn = target_val->data.x_fn.fn_entry;
- assert(target_fn->def_scope);
- safety_off_ptr = &target_fn->def_scope->safety_off;
- safety_set_node_ptr = &target_fn->def_scope->safety_set_node;
- } else if (target_type->id == TypeTableEntryIdMetaType) {
- ScopeDecls *decls_scope;
- TypeTableEntry *type_arg = target_val->data.x_type;
- if (type_arg->id == TypeTableEntryIdStruct) {
- decls_scope = type_arg->data.structure.decls_scope;
- } else if (type_arg->id == TypeTableEntryIdEnum) {
- decls_scope = type_arg->data.enumeration.decls_scope;
- } else if (type_arg->id == TypeTableEntryIdUnion) {
- decls_scope = type_arg->data.unionation.decls_scope;
+
+ Scope *scope = set_runtime_safety_instruction->base.scope;
+ while (scope != nullptr) {
+ if (scope->id == ScopeIdBlock) {
+ ScopeBlock *block_scope = (ScopeBlock *)scope;
+ safety_off_ptr = &block_scope->safety_off;
+ safety_set_node_ptr = &block_scope->safety_set_node;
+ break;
+ } else if (scope->id == ScopeIdFnDef) {
+ ScopeFnDef *def_scope = (ScopeFnDef *)scope;
+ FnTableEntry *target_fn = def_scope->fn_entry;
+ assert(target_fn->def_scope != nullptr);
+ safety_off_ptr = &target_fn->def_scope->safety_off;
+ safety_set_node_ptr = &target_fn->def_scope->safety_set_node;
+ break;
+ } else if (scope->id == ScopeIdDecls) {
+ ScopeDecls *decls_scope = (ScopeDecls *)scope;
+ safety_off_ptr = &decls_scope->safety_off;
+ safety_set_node_ptr = &decls_scope->safety_set_node;
+ break;
} else {
- ir_add_error_node(ira, target_instruction->source_node,
- buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&type_arg->name)));
- return ira->codegen->builtin_types.entry_invalid;
+ scope = scope->parent;
+ continue;
}
- safety_off_ptr = &decls_scope->safety_off;
- safety_set_node_ptr = &decls_scope->safety_set_node;
- } else {
- ir_add_error_node(ira, target_instruction->source_node,
- buf_sprintf("expected scope reference, found type '%s'", buf_ptr(&target_type->name)));
- return ira->codegen->builtin_types.entry_invalid;
}
+ assert(scope != nullptr);
- IrInstruction *debug_safety_on_value = set_debug_safety_instruction->debug_safety_on->other;
- bool want_debug_safety;
- if (!ir_resolve_bool(ira, debug_safety_on_value, &want_debug_safety))
+ IrInstruction *safety_on_value = set_runtime_safety_instruction->safety_on->other;
+ bool want_runtime_safety;
+ if (!ir_resolve_bool(ira, safety_on_value, &want_runtime_safety))
return ira->codegen->builtin_types.entry_invalid;
- AstNode *source_node = set_debug_safety_instruction->base.source_node;
+ AstNode *source_node = set_runtime_safety_instruction->base.source_node;
if (*safety_set_node_ptr) {
ErrorMsg *msg = ir_add_error_node(ira, source_node,
- buf_sprintf("debug safety set twice for same scope"));
+ buf_sprintf("runtime safety set twice for same scope"));
add_error_note(ira->codegen, msg, *safety_set_node_ptr, buf_sprintf("first set here"));
return ira->codegen->builtin_types.entry_invalid;
}
*safety_set_node_ptr = source_node;
- *safety_off_ptr = !want_debug_safety;
+ *safety_off_ptr = !want_runtime_safety;
- ir_build_const_from(ira, &set_debug_safety_instruction->base);
+ ir_build_const_from(ira, &set_runtime_safety_instruction->base);
return ira->codegen->builtin_types.entry_void;
}
@@ -15293,8 +15274,8 @@ static TypeTableEntry *ir_analyze_instruction_nocast(IrAnalyze *ira, IrInstructi
return ir_analyze_instruction_ptr_type_child(ira, (IrInstructionPtrTypeChild *)instruction);
case IrInstructionIdSetCold:
return ir_analyze_instruction_set_cold(ira, (IrInstructionSetCold *)instruction);
- case IrInstructionIdSetDebugSafety:
- return ir_analyze_instruction_set_debug_safety(ira, (IrInstructionSetDebugSafety *)instruction);
+ case IrInstructionIdSetRuntimeSafety:
+ return ir_analyze_instruction_set_runtime_safety(ira, (IrInstructionSetRuntimeSafety *)instruction);
case IrInstructionIdSetFloatMode:
return ir_analyze_instruction_set_float_mode(ira, (IrInstructionSetFloatMode *)instruction);
case IrInstructionIdSliceType:
@@ -15530,7 +15511,7 @@ bool ir_has_side_effects(IrInstruction *instruction) {
case IrInstructionIdReturn:
case IrInstructionIdUnreachable:
case IrInstructionIdSetCold:
- case IrInstructionIdSetDebugSafety:
+ case IrInstructionIdSetRuntimeSafety:
case IrInstructionIdSetFloatMode:
case IrInstructionIdImport:
case IrInstructionIdCompileErr:
diff --git a/src/ir_print.cpp b/src/ir_print.cpp
index 4a5604da5a..8332212d34 100644
--- a/src/ir_print.cpp
+++ b/src/ir_print.cpp
@@ -374,11 +374,9 @@ static void ir_print_set_cold(IrPrint *irp, IrInstructionSetCold *instruction) {
fprintf(irp->f, ")");
}
-static void ir_print_set_debug_safety(IrPrint *irp, IrInstructionSetDebugSafety *instruction) {
- fprintf(irp->f, "@setDebugSafety(");
- ir_print_other_instruction(irp, instruction->scope_value);
- fprintf(irp->f, ", ");
- ir_print_other_instruction(irp, instruction->debug_safety_on);
+static void ir_print_set_runtime_safety(IrPrint *irp, IrInstructionSetRuntimeSafety *instruction) {
+ fprintf(irp->f, "@setRuntimeSafety(");
+ ir_print_other_instruction(irp, instruction->safety_on);
fprintf(irp->f, ")");
}
@@ -1090,8 +1088,8 @@ static void ir_print_instruction(IrPrint *irp, IrInstruction *instruction) {
case IrInstructionIdSetCold:
ir_print_set_cold(irp, (IrInstructionSetCold *)instruction);
break;
- case IrInstructionIdSetDebugSafety:
- ir_print_set_debug_safety(irp, (IrInstructionSetDebugSafety *)instruction);
+ case IrInstructionIdSetRuntimeSafety:
+ ir_print_set_runtime_safety(irp, (IrInstructionSetRuntimeSafety *)instruction);
break;
case IrInstructionIdSetFloatMode:
ir_print_set_float_mode(irp, (IrInstructionSetFloatMode *)instruction);
diff --git a/std/math/index.zig b/std/math/index.zig
index 07a4d9a731..e9023f68a9 100644
--- a/std/math/index.zig
+++ b/std/math/index.zig
@@ -331,7 +331,7 @@ pub fn absInt(x: var) -> %@typeOf(x) {
if (x == @minValue(@typeOf(x)))
return error.Overflow;
{
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
return if (x < 0) -x else x;
}
}
@@ -350,7 +350,7 @@ pub const absFloat = @import("fabs.zig").fabs;
error DivisionByZero;
error Overflow;
pub fn divTrunc(comptime T: type, numerator: T, denominator: T) -> %T {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
if (denominator == 0)
return error.DivisionByZero;
if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1)
@@ -375,7 +375,7 @@ fn testDivTrunc() {
error DivisionByZero;
error Overflow;
pub fn divFloor(comptime T: type, numerator: T, denominator: T) -> %T {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
if (denominator == 0)
return error.DivisionByZero;
if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1)
@@ -401,7 +401,7 @@ error DivisionByZero;
error Overflow;
error UnexpectedRemainder;
pub fn divExact(comptime T: type, numerator: T, denominator: T) -> %T {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
if (denominator == 0)
return error.DivisionByZero;
if (@typeId(T) == builtin.TypeId.Int and T.is_signed and numerator == @minValue(T) and denominator == -1)
@@ -431,7 +431,7 @@ fn testDivExact() {
error DivisionByZero;
error NegativeDenominator;
pub fn mod(comptime T: type, numerator: T, denominator: T) -> %T {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
if (denominator == 0)
return error.DivisionByZero;
if (denominator < 0)
@@ -458,7 +458,7 @@ fn testMod() {
error DivisionByZero;
error NegativeDenominator;
pub fn rem(comptime T: type, numerator: T, denominator: T) -> %T {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
if (denominator == 0)
return error.DivisionByZero;
if (denominator < 0)
diff --git a/std/mem.zig b/std/mem.zig
index cee49fead7..a4ce3843b3 100644
--- a/std/mem.zig
+++ b/std/mem.zig
@@ -156,9 +156,9 @@ pub const FixedBufferAllocator = struct {
/// dest.len must be >= source.len.
pub fn copy(comptime T: type, dest: []T, source: []const T) {
// TODO instead of manually doing this check for the whole array
- // and turning off debug safety, the compiler should detect loops like
+ // and turning off runtime safety, the compiler should detect loops like
// this and automatically omit safety checks for loops
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
assert(dest.len >= source.len);
for (source) |s, i| dest[i] = s;
}
diff --git a/std/special/builtin.zig b/std/special/builtin.zig
index 7d648ff95a..41d58adb01 100644
--- a/std/special/builtin.zig
+++ b/std/special/builtin.zig
@@ -3,7 +3,7 @@
const builtin = @import("builtin");
-// Avoid dragging in the debug safety mechanisms into this .o file,
+// Avoid dragging in the runtime safety mechanisms into this .o file,
// unless we're trying to test this file.
pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn {
if (builtin.is_test) {
@@ -18,7 +18,7 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret
// The semantics of memset is dictated by the corresponding
// LLVM intrinsics, not by the libc API.
export fn memset(dest: ?&u8, c: u8, n: usize) {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
var index: usize = 0;
while (index != n) : (index += 1)
@@ -29,7 +29,7 @@ export fn memset(dest: ?&u8, c: u8, n: usize) {
// The semantics of memcpy is dictated by the corresponding
// LLVM intrinsics, not by the libc API.
export fn memcpy(noalias dest: ?&u8, noalias src: ?&const u8, n: usize) {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
var index: usize = 0;
while (index != n) : (index += 1)
@@ -58,7 +58,7 @@ export fn floor(x: f64) -> f64 { return math.floor(x); }
export fn ceil(x: f64) -> f64 { return math.ceil(x); }
fn generic_fmod(comptime T: type, x: T, y: T) -> T {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
const uint = @IntType(false, T.bit_count);
const log2uint = math.Log2Int(uint);
diff --git a/std/special/compiler_rt/aulldiv.zig b/std/special/compiler_rt/aulldiv.zig
index 9d4faf95b9..96a7f6c624 100644
--- a/std/special/compiler_rt/aulldiv.zig
+++ b/std/special/compiler_rt/aulldiv.zig
@@ -1,5 +1,5 @@
pub nakedcc fn _aulldiv() {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
asm volatile (
\\.intel_syntax noprefix
\\
diff --git a/std/special/compiler_rt/aullrem.zig b/std/special/compiler_rt/aullrem.zig
index b6c54d33ae..2fdfc63008 100644
--- a/std/special/compiler_rt/aullrem.zig
+++ b/std/special/compiler_rt/aullrem.zig
@@ -1,5 +1,5 @@
pub nakedcc fn _aullrem() {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
asm volatile (
\\.intel_syntax noprefix
\\
diff --git a/std/special/compiler_rt/comparetf2.zig b/std/special/compiler_rt/comparetf2.zig
index b88c35019b..e0fcca8718 100644
--- a/std/special/compiler_rt/comparetf2.zig
+++ b/std/special/compiler_rt/comparetf2.zig
@@ -22,7 +22,7 @@ const builtin = @import("builtin");
const is_test = builtin.is_test;
pub extern fn __letf2(a: f128, b: f128) -> c_int {
- @setDebugSafety(this, is_test);
+ @setRuntimeSafety(is_test);
const aInt = @bitCast(rep_t, a);
const bInt = @bitCast(rep_t, b);
@@ -67,7 +67,7 @@ const GE_GREATER = c_int(1);
const GE_UNORDERED = c_int(-1); // Note: different from LE_UNORDERED
pub extern fn __getf2(a: f128, b: f128) -> c_int {
- @setDebugSafety(this, is_test);
+ @setRuntimeSafety(is_test);
const aInt = @bitCast(srep_t, a);
const bInt = @bitCast(srep_t, b);
@@ -94,7 +94,7 @@ pub extern fn __getf2(a: f128, b: f128) -> c_int {
}
pub extern fn __unordtf2(a: f128, b: f128) -> c_int {
- @setDebugSafety(this, is_test);
+ @setRuntimeSafety(is_test);
const aAbs = @bitCast(rep_t, a) & absMask;
const bAbs = @bitCast(rep_t, b) & absMask;
diff --git a/std/special/compiler_rt/fixuint.zig b/std/special/compiler_rt/fixuint.zig
index 3b3565ce15..7ac54c30db 100644
--- a/std/special/compiler_rt/fixuint.zig
+++ b/std/special/compiler_rt/fixuint.zig
@@ -2,7 +2,7 @@ const is_test = @import("builtin").is_test;
const Log2Int = @import("../../math/index.zig").Log2Int;
pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) -> fixuint_t {
- @setDebugSafety(this, is_test);
+ @setRuntimeSafety(is_test);
const rep_t = switch (fp_t) {
f32 => u32,
@@ -48,12 +48,12 @@ pub fn fixuint(comptime fp_t: type, comptime fixuint_t: type, a: fp_t) -> fixuin
if (exponent < significandBits) {
// TODO this is a workaround for the mysterious "integer cast truncated bits"
// happening on the next line
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
return fixuint_t(significand >> Log2Int(rep_t)(significandBits - exponent));
} else {
// TODO this is a workaround for the mysterious "integer cast truncated bits"
// happening on the next line
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
return fixuint_t(significand) << Log2Int(fixuint_t)(exponent - significandBits);
}
}
diff --git a/std/special/compiler_rt/fixunsdfdi.zig b/std/special/compiler_rt/fixunsdfdi.zig
index 7e33987997..376043c2e7 100644
--- a/std/special/compiler_rt/fixunsdfdi.zig
+++ b/std/special/compiler_rt/fixunsdfdi.zig
@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
pub extern fn __fixunsdfdi(a: f64) -> u64 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return fixuint(f64, u64, a);
}
diff --git a/std/special/compiler_rt/fixunsdfsi.zig b/std/special/compiler_rt/fixunsdfsi.zig
index e710e1852b..a0b52bcc88 100644
--- a/std/special/compiler_rt/fixunsdfsi.zig
+++ b/std/special/compiler_rt/fixunsdfsi.zig
@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
pub extern fn __fixunsdfsi(a: f64) -> u32 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return fixuint(f64, u32, a);
}
diff --git a/std/special/compiler_rt/fixunsdfti.zig b/std/special/compiler_rt/fixunsdfti.zig
index 79d924f0a8..6f2ef417c9 100644
--- a/std/special/compiler_rt/fixunsdfti.zig
+++ b/std/special/compiler_rt/fixunsdfti.zig
@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
pub extern fn __fixunsdfti(a: f64) -> u128 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return fixuint(f64, u128, a);
}
diff --git a/std/special/compiler_rt/fixunssfdi.zig b/std/special/compiler_rt/fixunssfdi.zig
index f72f62d68c..e8811c0c93 100644
--- a/std/special/compiler_rt/fixunssfdi.zig
+++ b/std/special/compiler_rt/fixunssfdi.zig
@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
pub extern fn __fixunssfdi(a: f32) -> u64 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return fixuint(f32, u64, a);
}
diff --git a/std/special/compiler_rt/fixunssfsi.zig b/std/special/compiler_rt/fixunssfsi.zig
index 4c9a5001ab..20d659696a 100644
--- a/std/special/compiler_rt/fixunssfsi.zig
+++ b/std/special/compiler_rt/fixunssfsi.zig
@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
pub extern fn __fixunssfsi(a: f32) -> u32 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return fixuint(f32, u32, a);
}
diff --git a/std/special/compiler_rt/fixunssfti.zig b/std/special/compiler_rt/fixunssfti.zig
index 59b94cfc51..0ad5b85475 100644
--- a/std/special/compiler_rt/fixunssfti.zig
+++ b/std/special/compiler_rt/fixunssfti.zig
@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
pub extern fn __fixunssfti(a: f32) -> u128 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return fixuint(f32, u128, a);
}
diff --git a/std/special/compiler_rt/fixunstfdi.zig b/std/special/compiler_rt/fixunstfdi.zig
index 06b117a414..5d95771761 100644
--- a/std/special/compiler_rt/fixunstfdi.zig
+++ b/std/special/compiler_rt/fixunstfdi.zig
@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
pub extern fn __fixunstfdi(a: f128) -> u64 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return fixuint(f128, u64, a);
}
diff --git a/std/special/compiler_rt/fixunstfsi.zig b/std/special/compiler_rt/fixunstfsi.zig
index 8a5efe711d..f0fbf71fdf 100644
--- a/std/special/compiler_rt/fixunstfsi.zig
+++ b/std/special/compiler_rt/fixunstfsi.zig
@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
pub extern fn __fixunstfsi(a: f128) -> u32 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return fixuint(f128, u32, a);
}
diff --git a/std/special/compiler_rt/fixunstfti.zig b/std/special/compiler_rt/fixunstfti.zig
index d8b654d3a3..9e4c5f1829 100644
--- a/std/special/compiler_rt/fixunstfti.zig
+++ b/std/special/compiler_rt/fixunstfti.zig
@@ -2,7 +2,7 @@ const fixuint = @import("fixuint.zig").fixuint;
const builtin = @import("builtin");
pub extern fn __fixunstfti(a: f128) -> u128 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return fixuint(f128, u128, a);
}
diff --git a/std/special/compiler_rt/index.zig b/std/special/compiler_rt/index.zig
index 32659f1bdd..97b78e3606 100644
--- a/std/special/compiler_rt/index.zig
+++ b/std/special/compiler_rt/index.zig
@@ -72,7 +72,7 @@ const assert = @import("../../index.zig").debug.assert;
const __udivmoddi4 = @import("udivmoddi4.zig").__udivmoddi4;
-// Avoid dragging in the debug safety mechanisms into this .o file,
+// Avoid dragging in the runtime safety mechanisms into this .o file,
// unless we're trying to test this file.
pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noreturn {
@setCold(true);
@@ -84,12 +84,12 @@ pub fn panic(msg: []const u8, error_return_trace: ?&builtin.StackTrace) -> noret
}
extern fn __udivdi3(a: u64, b: u64) -> u64 {
- @setDebugSafety(this, is_test);
+ @setRuntimeSafety(is_test);
return __udivmoddi4(a, b, null);
}
extern fn __umoddi3(a: u64, b: u64) -> u64 {
- @setDebugSafety(this, is_test);
+ @setRuntimeSafety(is_test);
var r: u64 = undefined;
_ = __udivmoddi4(a, b, &r);
@@ -101,7 +101,7 @@ const AeabiUlDivModResult = extern struct {
rem: u64,
};
extern fn __aeabi_uldivmod(numerator: u64, denominator: u64) -> AeabiUlDivModResult {
- @setDebugSafety(this, is_test);
+ @setRuntimeSafety(is_test);
var result: AeabiUlDivModResult = undefined;
result.quot = __udivmoddi4(numerator, denominator, &result.rem);
return result;
@@ -133,7 +133,7 @@ fn isArmArch() -> bool {
}
nakedcc fn __aeabi_uidivmod() {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
asm volatile (
\\ push { lr }
\\ sub sp, sp, #4
@@ -150,7 +150,7 @@ nakedcc fn __aeabi_uidivmod() {
// This routine is windows specific
// http://msdn.microsoft.com/en-us/library/ms648426.aspx
nakedcc fn _chkstk() align(4) {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
asm volatile (
\\ push %%ecx
@@ -174,7 +174,7 @@ nakedcc fn _chkstk() align(4) {
}
nakedcc fn __chkstk() align(4) {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
asm volatile (
\\ push %%rcx
@@ -201,7 +201,7 @@ nakedcc fn __chkstk() align(4) {
// This routine is windows specific
// http://msdn.microsoft.com/en-us/library/ms648426.aspx
nakedcc fn __chkstk_ms() align(4) {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
asm volatile (
\\ push %%ecx
@@ -225,7 +225,7 @@ nakedcc fn __chkstk_ms() align(4) {
}
nakedcc fn ___chkstk_ms() align(4) {
- @setDebugSafety(this, false);
+ @setRuntimeSafety(false);
asm volatile (
\\ push %%rcx
@@ -249,7 +249,7 @@ nakedcc fn ___chkstk_ms() align(4) {
}
extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 {
- @setDebugSafety(this, is_test);
+ @setRuntimeSafety(is_test);
const d = __udivsi3(a, b);
*rem = u32(i32(a) -% (i32(d) * i32(b)));
@@ -258,7 +258,7 @@ extern fn __udivmodsi4(a: u32, b: u32, rem: &u32) -> u32 {
extern fn __udivsi3(n: u32, d: u32) -> u32 {
- @setDebugSafety(this, is_test);
+ @setRuntimeSafety(is_test);
const n_uword_bits: c_uint = u32.bit_count;
// special cases
diff --git a/std/special/compiler_rt/udivmod.zig b/std/special/compiler_rt/udivmod.zig
index 7e09c3d4d7..c215830ba1 100644
--- a/std/special/compiler_rt/udivmod.zig
+++ b/std/special/compiler_rt/udivmod.zig
@@ -5,7 +5,7 @@ const low = switch (builtin.endian) { builtin.Endian.Big => 1, builtin.Endian.Li
const high = 1 - low;
pub fn udivmod(comptime DoubleInt: type, a: DoubleInt, b: DoubleInt, maybe_rem: ?&DoubleInt) -> DoubleInt {
- @setDebugSafety(this, is_test);
+ @setRuntimeSafety(is_test);
const SingleInt = @IntType(false, @divExact(DoubleInt.bit_count, 2));
const SignedDoubleInt = @IntType(true, DoubleInt.bit_count);
diff --git a/std/special/compiler_rt/udivmoddi4.zig b/std/special/compiler_rt/udivmoddi4.zig
index 4e2117cfa5..9387c176c4 100644
--- a/std/special/compiler_rt/udivmoddi4.zig
+++ b/std/special/compiler_rt/udivmoddi4.zig
@@ -2,7 +2,7 @@ const udivmod = @import("udivmod.zig").udivmod;
const builtin = @import("builtin");
pub extern fn __udivmoddi4(a: u64, b: u64, maybe_rem: ?&u64) -> u64 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return udivmod(u64, a, b, maybe_rem);
}
diff --git a/std/special/compiler_rt/udivmodti4.zig b/std/special/compiler_rt/udivmodti4.zig
index c56a958f27..2119e1a879 100644
--- a/std/special/compiler_rt/udivmodti4.zig
+++ b/std/special/compiler_rt/udivmodti4.zig
@@ -2,7 +2,7 @@ const udivmod = @import("udivmod.zig").udivmod;
const builtin = @import("builtin");
pub extern fn __udivmodti4(a: u128, b: u128, maybe_rem: ?&u128) -> u128 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return udivmod(u128, a, b, maybe_rem);
}
diff --git a/std/special/compiler_rt/udivti3.zig b/std/special/compiler_rt/udivti3.zig
index 115c748cfb..b19f62ffbc 100644
--- a/std/special/compiler_rt/udivti3.zig
+++ b/std/special/compiler_rt/udivti3.zig
@@ -2,6 +2,6 @@ const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
const builtin = @import("builtin");
pub extern fn __udivti3(a: u128, b: u128) -> u128 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
return __udivmodti4(a, b, null);
}
diff --git a/std/special/compiler_rt/umodti3.zig b/std/special/compiler_rt/umodti3.zig
index 9f680369eb..51cf172261 100644
--- a/std/special/compiler_rt/umodti3.zig
+++ b/std/special/compiler_rt/umodti3.zig
@@ -2,7 +2,7 @@ const __udivmodti4 = @import("udivmodti4.zig").__udivmodti4;
const builtin = @import("builtin");
pub extern fn __umodti3(a: u128, b: u128) -> u128 {
- @setDebugSafety(this, builtin.is_test);
+ @setRuntimeSafety(builtin.is_test);
var r: u128 = undefined;
_ = __udivmodti4(a, b, &r);
return r;
diff --git a/test/cases/eval.zig b/test/cases/eval.zig
index 2349aa75f7..484e1885fe 100644
--- a/test/cases/eval.zig
+++ b/test/cases/eval.zig
@@ -223,13 +223,13 @@ test "comptime iterate over fn ptr list" {
assert(performFn('w', 99) == 99);
}
-test "eval @setDebugSafety at compile-time" {
- const result = comptime fnWithSetDebugSafety();
+test "eval @setRuntimeSafety at compile-time" {
+ const result = comptime fnWithSetRuntimeSafety();
assert(result == 1234);
}
-fn fnWithSetDebugSafety() -> i32{
- @setDebugSafety(this, true);
+fn fnWithSetRuntimeSafety() -> i32{
+ @setRuntimeSafety(true);
return 1234;
}
diff --git a/test/cases/slice.zig b/test/cases/slice.zig
index c47de5b09e..379526d5d5 100644
--- a/test/cases/slice.zig
+++ b/test/cases/slice.zig
@@ -17,7 +17,7 @@ test "slice child property" {
assert(@typeOf(slice).Child == i32);
}
-test "debug safety lets us slice from len..len" {
+test "runtime safety lets us slice from len..len" {
var an_array = []u8{1, 2, 3};
assert(mem.eql(u8, sliceFromLenToLen(an_array[0..], 3, 3), ""));
}
diff --git a/test/compile_errors.zig b/test/compile_errors.zig
index ed3ddb67e2..b98b88468c 100644
--- a/test/compile_errors.zig
+++ b/test/compile_errors.zig
@@ -1867,13 +1867,13 @@ pub fn addCases(cases: &tests.CompileErrorContext) {
,
".tmp_source.zig:3:20: error: cast from 'u16' to 'u8' truncates bits");
- cases.add("@setDebugSafety twice for same scope",
+ cases.add("@setRuntimeSafety twice for same scope",
\\export fn foo() {
- \\ @setDebugSafety(this, false);
- \\ @setDebugSafety(this, false);
+ \\ @setRuntimeSafety(false);
+ \\ @setRuntimeSafety(false);
\\}
,
- ".tmp_source.zig:3:5: error: debug safety set twice for same scope",
+ ".tmp_source.zig:3:5: error: runtime safety set twice for same scope",
".tmp_source.zig:2:5: note: first set here");
cases.add("@setFloatMode twice for same scope",
diff --git a/test/debug_safety.zig b/test/debug_safety.zig
deleted file mode 100644
index b32ffb34f0..0000000000
--- a/test/debug_safety.zig
+++ /dev/null
@@ -1,286 +0,0 @@
-const tests = @import("tests.zig");
-
-pub fn addCases(cases: &tests.CompareOutputContext) {
- cases.addDebugSafety("calling panic",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\pub fn main() -> %void {
- \\ @panic("oh no");
- \\}
- );
-
- cases.addDebugSafety("out of bounds slice access",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\pub fn main() -> %void {
- \\ const a = []i32{1, 2, 3, 4};
- \\ baz(bar(a));
- \\}
- \\fn bar(a: []const i32) -> i32 {
- \\ return a[4];
- \\}
- \\fn baz(a: i32) { }
- );
-
- cases.addDebugSafety("integer addition overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = add(65530, 10);
- \\ if (x == 0) return error.Whatever;
- \\}
- \\fn add(a: u16, b: u16) -> u16 {
- \\ return a + b;
- \\}
- );
-
- cases.addDebugSafety("integer subtraction overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = sub(10, 20);
- \\ if (x == 0) return error.Whatever;
- \\}
- \\fn sub(a: u16, b: u16) -> u16 {
- \\ return a - b;
- \\}
- );
-
- cases.addDebugSafety("integer multiplication overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = mul(300, 6000);
- \\ if (x == 0) return error.Whatever;
- \\}
- \\fn mul(a: u16, b: u16) -> u16 {
- \\ return a * b;
- \\}
- );
-
- cases.addDebugSafety("integer negation overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = neg(-32768);
- \\ if (x == 32767) return error.Whatever;
- \\}
- \\fn neg(a: i16) -> i16 {
- \\ return -a;
- \\}
- );
-
- cases.addDebugSafety("signed integer division overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = div(-32768, -1);
- \\ if (x == 32767) return error.Whatever;
- \\}
- \\fn div(a: i16, b: i16) -> i16 {
- \\ return @divTrunc(a, b);
- \\}
- );
-
- cases.addDebugSafety("signed shift left overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = shl(-16385, 1);
- \\ if (x == 0) return error.Whatever;
- \\}
- \\fn shl(a: i16, b: u4) -> i16 {
- \\ return @shlExact(a, b);
- \\}
- );
-
- cases.addDebugSafety("unsigned shift left overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = shl(0b0010111111111111, 3);
- \\ if (x == 0) return error.Whatever;
- \\}
- \\fn shl(a: u16, b: u4) -> u16 {
- \\ return @shlExact(a, b);
- \\}
- );
-
- cases.addDebugSafety("signed shift right overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = shr(-16385, 1);
- \\ if (x == 0) return error.Whatever;
- \\}
- \\fn shr(a: i16, b: u4) -> i16 {
- \\ return @shrExact(a, b);
- \\}
- );
-
- cases.addDebugSafety("unsigned shift right overflow",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = shr(0b0010111111111111, 3);
- \\ if (x == 0) return error.Whatever;
- \\}
- \\fn shr(a: u16, b: u4) -> u16 {
- \\ return @shrExact(a, b);
- \\}
- );
-
- cases.addDebugSafety("integer division by zero",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = div0(999, 0);
- \\}
- \\fn div0(a: i32, b: i32) -> i32 {
- \\ return @divTrunc(a, b);
- \\}
- );
-
- cases.addDebugSafety("exact division failure",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = divExact(10, 3);
- \\ if (x == 0) return error.Whatever;
- \\}
- \\fn divExact(a: i32, b: i32) -> i32 {
- \\ return @divExact(a, b);
- \\}
- );
-
- cases.addDebugSafety("cast []u8 to bigger slice of wrong size",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = widenSlice([]u8{1, 2, 3, 4, 5});
- \\ if (x.len == 0) return error.Whatever;
- \\}
- \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 {
- \\ return ([]align(1) const i32)(slice);
- \\}
- );
-
- cases.addDebugSafety("value does not fit in shortening cast",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = shorten_cast(200);
- \\ if (x == 0) return error.Whatever;
- \\}
- \\fn shorten_cast(x: i32) -> i8 {
- \\ return i8(x);
- \\}
- );
-
- cases.addDebugSafety("signed integer not fitting in cast to unsigned integer",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ const x = unsigned_cast(-10);
- \\ if (x == 0) return error.Whatever;
- \\}
- \\fn unsigned_cast(x: i32) -> u32 {
- \\ return u32(x);
- \\}
- );
-
- cases.addDebugSafety("unwrap error",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
- \\ @import("std").os.exit(126); // good
- \\ }
- \\ @import("std").os.exit(0); // test failed
- \\}
- \\error Whatever;
- \\pub fn main() -> %void {
- \\ bar() catch unreachable;
- \\}
- \\fn bar() -> %void {
- \\ return error.Whatever;
- \\}
- );
-
- cases.addDebugSafety("cast integer to error and no code matches",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\pub fn main() -> %void {
- \\ _ = bar(9999);
- \\}
- \\fn bar(x: u32) -> error {
- \\ return error(x);
- \\}
- );
-
- cases.addDebugSafety("@alignCast misaligned",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\error Wrong;
- \\pub fn main() -> %void {
- \\ var array align(4) = []u32{0x11111111, 0x11111111};
- \\ const bytes = ([]u8)(array[0..]);
- \\ if (foo(bytes) != 0x11111111) return error.Wrong;
- \\}
- \\fn foo(bytes: []u8) -> u32 {
- \\ const slice4 = bytes[1..5];
- \\ const int_slice = ([]u32)(@alignCast(4, slice4));
- \\ return int_slice[0];
- \\}
- );
-
- cases.addDebugSafety("bad union field access",
- \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
- \\ @import("std").os.exit(126);
- \\}
- \\
- \\const Foo = union {
- \\ float: f32,
- \\ int: u32,
- \\};
- \\
- \\pub fn main() -> %void {
- \\ var f = Foo { .int = 42 };
- \\ bar(&f);
- \\}
- \\
- \\fn bar(f: &Foo) {
- \\ f.float = 12.34;
- \\}
- );
-}
diff --git a/test/runtime_safety.zig b/test/runtime_safety.zig
new file mode 100644
index 0000000000..25d6aa3577
--- /dev/null
+++ b/test/runtime_safety.zig
@@ -0,0 +1,286 @@
+const tests = @import("tests.zig");
+
+pub fn addCases(cases: &tests.CompareOutputContext) {
+ cases.addRuntimeSafety("calling panic",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\pub fn main() -> %void {
+ \\ @panic("oh no");
+ \\}
+ );
+
+ cases.addRuntimeSafety("out of bounds slice access",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\pub fn main() -> %void {
+ \\ const a = []i32{1, 2, 3, 4};
+ \\ baz(bar(a));
+ \\}
+ \\fn bar(a: []const i32) -> i32 {
+ \\ return a[4];
+ \\}
+ \\fn baz(a: i32) { }
+ );
+
+ cases.addRuntimeSafety("integer addition overflow",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = add(65530, 10);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn add(a: u16, b: u16) -> u16 {
+ \\ return a + b;
+ \\}
+ );
+
+ cases.addRuntimeSafety("integer subtraction overflow",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = sub(10, 20);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn sub(a: u16, b: u16) -> u16 {
+ \\ return a - b;
+ \\}
+ );
+
+ cases.addRuntimeSafety("integer multiplication overflow",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = mul(300, 6000);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn mul(a: u16, b: u16) -> u16 {
+ \\ return a * b;
+ \\}
+ );
+
+ cases.addRuntimeSafety("integer negation overflow",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = neg(-32768);
+ \\ if (x == 32767) return error.Whatever;
+ \\}
+ \\fn neg(a: i16) -> i16 {
+ \\ return -a;
+ \\}
+ );
+
+ cases.addRuntimeSafety("signed integer division overflow",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = div(-32768, -1);
+ \\ if (x == 32767) return error.Whatever;
+ \\}
+ \\fn div(a: i16, b: i16) -> i16 {
+ \\ return @divTrunc(a, b);
+ \\}
+ );
+
+ cases.addRuntimeSafety("signed shift left overflow",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = shl(-16385, 1);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn shl(a: i16, b: u4) -> i16 {
+ \\ return @shlExact(a, b);
+ \\}
+ );
+
+ cases.addRuntimeSafety("unsigned shift left overflow",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = shl(0b0010111111111111, 3);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn shl(a: u16, b: u4) -> u16 {
+ \\ return @shlExact(a, b);
+ \\}
+ );
+
+ cases.addRuntimeSafety("signed shift right overflow",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = shr(-16385, 1);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn shr(a: i16, b: u4) -> i16 {
+ \\ return @shrExact(a, b);
+ \\}
+ );
+
+ cases.addRuntimeSafety("unsigned shift right overflow",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = shr(0b0010111111111111, 3);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn shr(a: u16, b: u4) -> u16 {
+ \\ return @shrExact(a, b);
+ \\}
+ );
+
+ cases.addRuntimeSafety("integer division by zero",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = div0(999, 0);
+ \\}
+ \\fn div0(a: i32, b: i32) -> i32 {
+ \\ return @divTrunc(a, b);
+ \\}
+ );
+
+ cases.addRuntimeSafety("exact division failure",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = divExact(10, 3);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn divExact(a: i32, b: i32) -> i32 {
+ \\ return @divExact(a, b);
+ \\}
+ );
+
+ cases.addRuntimeSafety("cast []u8 to bigger slice of wrong size",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = widenSlice([]u8{1, 2, 3, 4, 5});
+ \\ if (x.len == 0) return error.Whatever;
+ \\}
+ \\fn widenSlice(slice: []align(1) const u8) -> []align(1) const i32 {
+ \\ return ([]align(1) const i32)(slice);
+ \\}
+ );
+
+ cases.addRuntimeSafety("value does not fit in shortening cast",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = shorten_cast(200);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn shorten_cast(x: i32) -> i8 {
+ \\ return i8(x);
+ \\}
+ );
+
+ cases.addRuntimeSafety("signed integer not fitting in cast to unsigned integer",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ const x = unsigned_cast(-10);
+ \\ if (x == 0) return error.Whatever;
+ \\}
+ \\fn unsigned_cast(x: i32) -> u32 {
+ \\ return u32(x);
+ \\}
+ );
+
+ cases.addRuntimeSafety("unwrap error",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ if (@import("std").mem.eql(u8, message, "attempt to unwrap error: Whatever")) {
+ \\ @import("std").os.exit(126); // good
+ \\ }
+ \\ @import("std").os.exit(0); // test failed
+ \\}
+ \\error Whatever;
+ \\pub fn main() -> %void {
+ \\ bar() catch unreachable;
+ \\}
+ \\fn bar() -> %void {
+ \\ return error.Whatever;
+ \\}
+ );
+
+ cases.addRuntimeSafety("cast integer to error and no code matches",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\pub fn main() -> %void {
+ \\ _ = bar(9999);
+ \\}
+ \\fn bar(x: u32) -> error {
+ \\ return error(x);
+ \\}
+ );
+
+ cases.addRuntimeSafety("@alignCast misaligned",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\error Wrong;
+ \\pub fn main() -> %void {
+ \\ var array align(4) = []u32{0x11111111, 0x11111111};
+ \\ const bytes = ([]u8)(array[0..]);
+ \\ if (foo(bytes) != 0x11111111) return error.Wrong;
+ \\}
+ \\fn foo(bytes: []u8) -> u32 {
+ \\ const slice4 = bytes[1..5];
+ \\ const int_slice = ([]u32)(@alignCast(4, slice4));
+ \\ return int_slice[0];
+ \\}
+ );
+
+ cases.addRuntimeSafety("bad union field access",
+ \\pub fn panic(message: []const u8, stack_trace: ?&@import("builtin").StackTrace) -> noreturn {
+ \\ @import("std").os.exit(126);
+ \\}
+ \\
+ \\const Foo = union {
+ \\ float: f32,
+ \\ int: u32,
+ \\};
+ \\
+ \\pub fn main() -> %void {
+ \\ var f = Foo { .int = 42 };
+ \\ bar(&f);
+ \\}
+ \\
+ \\fn bar(f: &Foo) {
+ \\ f.float = 12.34;
+ \\}
+ );
+}
diff --git a/test/tests.zig b/test/tests.zig
index 84b01be11e..f86f222bf4 100644
--- a/test/tests.zig
+++ b/test/tests.zig
@@ -17,7 +17,7 @@ const compare_output = @import("compare_output.zig");
const build_examples = @import("build_examples.zig");
const compile_errors = @import("compile_errors.zig");
const assemble_and_link = @import("assemble_and_link.zig");
-const debug_safety = @import("debug_safety.zig");
+const runtime_safety = @import("runtime_safety.zig");
const translate_c = @import("translate_c.zig");
const gen_h = @import("gen_h.zig");
@@ -64,16 +64,16 @@ pub fn addCompareOutputTests(b: &build.Builder, test_filter: ?[]const u8) -> &bu
return cases.step;
}
-pub fn addDebugSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
+pub fn addRuntimeSafetyTests(b: &build.Builder, test_filter: ?[]const u8) -> &build.Step {
const cases = b.allocator.create(CompareOutputContext) catch unreachable;
*cases = CompareOutputContext {
.b = b,
- .step = b.step("test-debug-safety", "Run the debug safety tests"),
+ .step = b.step("test-runtime-safety", "Run the runtime safety tests"),
.test_index = 0,
.test_filter = test_filter,
};
- debug_safety.addCases(cases);
+ runtime_safety.addCases(cases);
return cases.step;
}
@@ -192,7 +192,7 @@ pub const CompareOutputContext = struct {
const Special = enum {
None,
Asm,
- DebugSafety,
+ RuntimeSafety,
};
const TestCase = struct {
@@ -314,7 +314,7 @@ pub const CompareOutputContext = struct {
}
};
- const DebugSafetyRunStep = struct {
+ const RuntimeSafetyRunStep = struct {
step: build.Step,
context: &CompareOutputContext,
exe_path: []const u8,
@@ -322,23 +322,23 @@ pub const CompareOutputContext = struct {
test_index: usize,
pub fn create(context: &CompareOutputContext, exe_path: []const u8,
- name: []const u8) -> &DebugSafetyRunStep
+ name: []const u8) -> &RuntimeSafetyRunStep
{
const allocator = context.b.allocator;
- const ptr = allocator.create(DebugSafetyRunStep) catch unreachable;
- *ptr = DebugSafetyRunStep {
+ const ptr = allocator.create(RuntimeSafetyRunStep) catch unreachable;
+ *ptr = RuntimeSafetyRunStep {
.context = context,
.exe_path = exe_path,
.name = name,
.test_index = context.test_index,
- .step = build.Step.init("DebugSafetyRun", allocator, make),
+ .step = build.Step.init("RuntimeSafetyRun", allocator, make),
};
context.test_index += 1;
return ptr;
}
fn make(step: &build.Step) -> %void {
- const self = @fieldParentPtr(DebugSafetyRunStep, "step", step);
+ const self = @fieldParentPtr(RuntimeSafetyRunStep, "step", step);
const b = self.context.b;
const full_exe_path = b.pathFromRoot(self.exe_path);
@@ -420,8 +420,8 @@ pub const CompareOutputContext = struct {
self.addCase(tc);
}
- pub fn addDebugSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) {
- const tc = self.createExtra(name, source, undefined, Special.DebugSafety);
+ pub fn addRuntimeSafety(self: &CompareOutputContext, name: []const u8, source: []const u8) {
+ const tc = self.createExtra(name, source, undefined, Special.RuntimeSafety);
self.addCase(tc);
}
@@ -481,7 +481,7 @@ pub const CompareOutputContext = struct {
self.step.dependOn(&run_and_cmp_output.step);
}
},
- Special.DebugSafety => {
+ Special.RuntimeSafety => {
const annotated_case_name = fmt.allocPrint(self.b.allocator, "safety {}", case.name) catch unreachable;
if (self.test_filter) |filter| {
if (mem.indexOf(u8, annotated_case_name, filter) == null)
@@ -499,7 +499,7 @@ pub const CompareOutputContext = struct {
exe.step.dependOn(&write_src.step);
}
- const run_and_cmp_output = DebugSafetyRunStep.create(self, exe.getOutputPath(), annotated_case_name);
+ const run_and_cmp_output = RuntimeSafetyRunStep.create(self, exe.getOutputPath(), annotated_case_name);
run_and_cmp_output.step.dependOn(&exe.step);
self.step.dependOn(&run_and_cmp_output.step);
--
cgit v1.2.3