mirror of
https://github.com/odin-lang/Odin.git
synced 2026-04-18 20:40:28 +00:00
-no-bounds-check
This commit is contained in:
@@ -691,13 +691,6 @@ __dynamic_array_expr_error :: proc "contextless" (file: string, line, column: in
|
||||
__debug_trap();
|
||||
}
|
||||
|
||||
|
||||
__substring_expr_error :: proc "contextless" (file: string, line, column: int, low, high: int) {
|
||||
if 0 <= low && low <= high do return;
|
||||
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid substring indices: %d..%d\n",
|
||||
file, line, column, low, high);
|
||||
__debug_trap();
|
||||
}
|
||||
__type_assertion_check :: proc "contextless" (ok: bool, file: string, line, column: int, from, to: ^Type_Info) {
|
||||
if ok do return;
|
||||
fmt.fprintf(os.stderr, "%s(%d:%d) Invalid type_assertion from %T to %T\n",
|
||||
@@ -715,9 +708,6 @@ __bounds_check_error_loc :: inline proc "contextless" (using loc := #caller_loca
|
||||
__slice_expr_error_loc :: inline proc "contextless" (using loc := #caller_location, low, high: int) {
|
||||
__slice_expr_error(file_path, int(line), int(column), low, high);
|
||||
}
|
||||
__substring_expr_error_loc :: inline proc "contextless" (using loc := #caller_location, low, high: int) {
|
||||
__substring_expr_error(file_path, int(line), int(column), low, high);
|
||||
}
|
||||
|
||||
__mem_set :: proc "contextless" (data: rawptr, value: i32, len: int) -> rawptr {
|
||||
if data == nil do return nil;
|
||||
|
||||
@@ -19,6 +19,7 @@ when ODIN_OS == "windows" {
|
||||
import win32 "core:sys/windows.odin"
|
||||
}
|
||||
|
||||
@(link_name="general_stuff")
|
||||
general_stuff :: proc() {
|
||||
fmt.println("# general_stuff");
|
||||
{ // `do` for inline statmes rather than block
|
||||
@@ -367,11 +368,7 @@ parametric_polymorphism :: proc() {
|
||||
}
|
||||
|
||||
copy_slice :: proc(dst, src: []$T) -> int {
|
||||
n := min(len(dst), len(src));
|
||||
if n > 0 {
|
||||
mem.copy(&dst[0], &src[0], n*size_of(T));
|
||||
}
|
||||
return n;
|
||||
return mem.copy(&dst[0], &src[0], n*size_of(T));
|
||||
}
|
||||
|
||||
double_params :: proc(a: $A, b: $B) -> A {
|
||||
@@ -662,21 +659,21 @@ named_proc_parameters :: proc() {
|
||||
b = 567;
|
||||
return b, a;
|
||||
}
|
||||
fmt.println("foo0 =", foo0());
|
||||
fmt.println("foo1 =", foo1());
|
||||
fmt.println("foo2 =", foo2());
|
||||
fmt.println("foo0 =", foo0()); // 123
|
||||
fmt.println("foo1 =", foo1()); // 123
|
||||
fmt.println("foo2 =", foo2()); // 567 321
|
||||
}
|
||||
|
||||
main :: proc() {
|
||||
when false {
|
||||
general_stuff();
|
||||
default_struct_values();
|
||||
when false {
|
||||
union_type();
|
||||
parametric_polymorphism();
|
||||
threading_example();
|
||||
array_programming();
|
||||
}
|
||||
using_in();
|
||||
named_proc_parameters();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -23,6 +23,7 @@ struct BuildContext {
|
||||
bool show_timings;
|
||||
bool keep_temp_files;
|
||||
bool debug;
|
||||
bool no_bounds_check;
|
||||
|
||||
gbAffinity affinity;
|
||||
isize thread_count;
|
||||
|
||||
12
src/ir.cpp
12
src/ir.cpp
@@ -3585,6 +3585,9 @@ irValue *ir_emit_logical_binary_expr(irProcedure *proc, AstNode *expr) {
|
||||
|
||||
|
||||
void ir_emit_bounds_check(irProcedure *proc, Token token, irValue *index, irValue *len) {
|
||||
if (build_context.no_bounds_check) {
|
||||
return;
|
||||
}
|
||||
if ((proc->module->stmt_state_flags & StmtStateFlag_no_bounds_check) != 0) {
|
||||
return;
|
||||
}
|
||||
@@ -3610,6 +3613,9 @@ void ir_emit_bounds_check(irProcedure *proc, Token token, irValue *index, irValu
|
||||
}
|
||||
|
||||
void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, irValue *high, bool is_substring) {
|
||||
if (build_context.no_bounds_check) {
|
||||
return;
|
||||
}
|
||||
if ((proc->module->stmt_state_flags & StmtStateFlag_no_bounds_check) != 0) {
|
||||
return;
|
||||
}
|
||||
@@ -3628,11 +3634,13 @@ void ir_emit_slice_bounds_check(irProcedure *proc, Token token, irValue *low, ir
|
||||
args[3] = low;
|
||||
args[4] = high;
|
||||
|
||||
char const *func = is_substring ? "__substring_expr_error" : "__slice_expr_error";
|
||||
ir_emit_global_call(proc, func, args, 5);
|
||||
ir_emit_global_call(proc, "__slice_expr_error", args, 5);
|
||||
}
|
||||
|
||||
void ir_emit_dynamic_array_bounds_check(irProcedure *proc, Token token, irValue *low, irValue *high, irValue *max) {
|
||||
if (build_context.no_bounds_check) {
|
||||
return;
|
||||
}
|
||||
if ((proc->module->stmt_state_flags & StmtStateFlag_no_bounds_check) != 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -212,6 +212,7 @@ enum BuildFlagKind {
|
||||
BuildFlag_Debug,
|
||||
BuildFlag_CrossCompile,
|
||||
BuildFlag_CrossLibDir,
|
||||
BuildFlag_NoBoundsCheck,
|
||||
|
||||
BuildFlag_COUNT,
|
||||
};
|
||||
@@ -250,6 +251,7 @@ bool parse_build_flags(Array<String> args) {
|
||||
add_flag(&build_flags, BuildFlag_Debug, str_lit("debug"), BuildFlagParam_None);
|
||||
add_flag(&build_flags, BuildFlag_CrossCompile, str_lit("cross-compile"), BuildFlagParam_String);
|
||||
add_flag(&build_flags, BuildFlag_CrossLibDir, str_lit("cross-lib-dir"), BuildFlagParam_String);
|
||||
add_flag(&build_flags, BuildFlag_NoBoundsCheck, str_lit("no-bounds-check"), BuildFlagParam_None);
|
||||
|
||||
|
||||
GB_ASSERT(args.count >= 3);
|
||||
@@ -505,6 +507,10 @@ bool parse_build_flags(Array<String> args) {
|
||||
case BuildFlag_Debug:
|
||||
build_context.debug = true;
|
||||
break;
|
||||
|
||||
case BuildFlag_NoBoundsCheck:
|
||||
build_context.no_bounds_check = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user