Skip to content

Commit 2eacc6f

Browse files
committed
pref,parser: implement support for -force-bounds-checking to enable easier testing of functions tagged with @[direct_array_access] (essentially turning off that flag)
1 parent da00a46 commit 2eacc6f

2 files changed

Lines changed: 13 additions & 2 deletions

File tree

vlib/v/parser/fn.v

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ fn (mut p Parser) fn_decl() ast.FnDecl {
217217
is_deprecated = true
218218
}
219219
'direct_array_access' {
220-
is_direct_arr = true
220+
if !p.pref.force_bounds_checking {
221+
is_direct_arr = true
222+
}
221223
}
222224
'keep_args_alive' {
223225
is_keep_alive = true

vlib/v/pref/pref.v

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,8 @@ pub mut:
171171
cppcompiler string // the name of the CPP compiler used
172172
third_party_option string
173173
building_v bool
174-
no_bounds_checking bool // `-no-bounds-checking` turns off *all* bounds checks for all functions at runtime, as if they all had been tagged with `[direct_array_access]`
174+
no_bounds_checking bool // `-no-bounds-checking` turns off *all* bounds checks for all functions at runtime, as if they all had been tagged with `@[direct_array_access]`
175+
force_bounds_checking bool // `-force-bounds-checking` turns ON *all* bounds checks, even for functions that *were* tagged with `@[direct_array_access]`
175176
autofree bool // `v -manualfree` => false, `v -autofree` => true; false by default for now.
176177
print_autofree_vars bool // print vars that are not freed by autofree
177178
print_autofree_vars_in_fn string // same as above, but only for a single fn
@@ -640,6 +641,9 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
640641
res.compile_defines_all << 'no_bounds_checking'
641642
res.build_options << arg
642643
}
644+
'-force-bounds-checking' {
645+
res.force_bounds_checking = true
646+
}
643647
'-no-builtin' {
644648
res.no_builtin = true
645649
res.build_options << arg
@@ -1036,6 +1040,11 @@ pub fn parse_args_and_show_errors(known_external_commands []string, args []strin
10361040
}
10371041
}
10381042
}
1043+
if res.force_bounds_checking {
1044+
res.no_bounds_checking = false
1045+
res.compile_defines = res.compile_defines.filter(it == 'no_bounds_checking')
1046+
res.compile_defines_all = res.compile_defines_all.filter(it == 'no_bounds_checking')
1047+
}
10391048
if res.trace_calls {
10401049
if res.trace_fns.len == 0 {
10411050
res.trace_fns << '*'

0 commit comments

Comments
 (0)