Skip to content

Commit 7d0f769

Browse files
add default "auto" as option to --check-bounds (#41551)
* add default "auto" as option to --check-bounds * add to NEWS
1 parent d732903 commit 7d0f769

File tree

7 files changed

+13
-7
lines changed

7 files changed

+13
-7
lines changed

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ New language features
77

88
* `Module(:name, false, false)` can be used to create a `module` that does not import `Core`. ([#40110])
99
* `@inline` and `@noinline` annotations may now be used in function bodies. ([#41312])
10+
* The default behavior of observing `@inbounds` declarations is now an option via `auto` in `--check-bounds=yes|no|auto` ([#41551])
1011

1112
Language changes
1213
----------------

base/util.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ function julia_cmd(julia=joinpath(Sys.BINDIR::String, julia_exename()))
174174
elseif opts.check_bounds == 2
175175
"no" # off
176176
else
177-
"" # "default"
177+
"" # default = "auto"
178178
end
179179
isempty(check_bounds) || push!(addflags, "--check-bounds=$check_bounds")
180180
end

doc/man/julia.1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -162,8 +162,8 @@ Set the level of debug info generation to <n>
162162
Control whether inlining is permitted (overrides functions declared as @inline)
163163

164164
.TP
165-
--check-bounds={yes|no}
166-
Emit bounds checks always or never (ignoring declarations)
165+
--check-bounds={yes|no|auto}
166+
Emit bounds checks always, never, or respect @inbounds declarations
167167

168168
.TP
169169
--math-mode={ieee|user}

doc/src/devdocs/boundscheck.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,4 +92,4 @@ the last argument).
9292

9393
## Emit bounds checks
9494

95-
Julia can be launched with `--check-bounds={yes|no}` to emit bounds checks always or never (ignoring declarations).
95+
Julia can be launched with `--check-bounds={yes|no|auto}` to emit bounds checks always, never, or respect @inbounds declarations.

doc/src/manual/command-line-options.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ The following is a complete list of command-line switches available when launchi
3131
|`--min-optlevel={0,1,2,3}` |Set the lower bound on per-module optimization (default is 0)|
3232
|`-g`, `-g <level>` |Enable / Set the level of debug info generation (default level is 1 if unspecified or 2 if used without a level)|
3333
|`--inline={yes\|no}` |Control whether inlining is permitted, including overriding `@inline` declarations|
34-
|`--check-bounds={yes\|no}` |Emit bounds checks always or never (ignoring declarations)|
34+
|`--check-bounds={yes\|no\|auto}` |Emit bounds checks always, never, or respect @inbounds declarations|
3535
|`--math-mode={ieee,fast}` |Disallow or enable unsafe floating point optimizations (overrides @fastmath declaration)|
3636
|`--code-coverage={none\|user\|all}` |Count executions of source lines|
3737
|`--code-coverage` |equivalent to `--code-coverage=user`|

src/jloptions.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,8 @@ static const char opts[] =
131131
" (default level is 1 if unspecified or 2 if used without a level)\n"
132132
#endif
133133
" --inline={yes|no} Control whether inlining is permitted, including overriding @inline declarations\n"
134-
" --check-bounds={yes|no} Emit bounds checks always or never (ignoring @inbounds declarations)\n"
134+
" --check-bounds={yes|no|auto}\n"
135+
" Emit bounds checks always, never, or respect @inbounds declarations\n"
135136
#ifdef USE_POLLY
136137
" --polly={yes|no} Enable or disable the polyhedral optimizer Polly (overrides @polly declaration)\n"
137138
#endif
@@ -565,8 +566,10 @@ JL_DLLEXPORT void jl_parse_opts(int *argcp, char ***argvp)
565566
jl_options.check_bounds = JL_OPTIONS_CHECK_BOUNDS_ON;
566567
else if (!strcmp(optarg,"no"))
567568
jl_options.check_bounds = JL_OPTIONS_CHECK_BOUNDS_OFF;
569+
else if (!strcmp(optarg,"auto"))
570+
jl_options.check_bounds = JL_OPTIONS_CHECK_BOUNDS_DEFAULT;
568571
else
569-
jl_errorf("julia: invalid argument to --check-bounds={yes|no} (%s)", optarg);
572+
jl_errorf("julia: invalid argument to --check-bounds={yes|no|auto} (%s)", optarg);
570573
break;
571574
case opt_output_bc:
572575
jl_options.outputbc = optarg;

test/cmdlineargs.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,8 @@ let exename = `$(Base.julia_cmd()) --startup-file=no --color=no`
396396
filter!(a -> !startswith(a, "--check-bounds="), exename_default_checkbounds.exec)
397397
@test parse(Int, readchomp(`$exename_default_checkbounds -E "Int(Base.JLOptions().check_bounds)"`)) ==
398398
JL_OPTIONS_CHECK_BOUNDS_DEFAULT
399+
@test parse(Int, readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)"
400+
--check-bounds=auto`)) == JL_OPTIONS_CHECK_BOUNDS_DEFAULT
399401
@test parse(Int, readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)"
400402
--check-bounds=yes`)) == JL_OPTIONS_CHECK_BOUNDS_ON
401403
@test parse(Int, readchomp(`$exename -E "Int(Base.JLOptions().check_bounds)"

0 commit comments

Comments
 (0)