Skip to content

Commit

Permalink
add --bounds-check=yes|no compiler option
Browse files Browse the repository at this point in the history
this overrides any declarations
  • Loading branch information
JeffBezanson committed Mar 13, 2014
1 parent 6f48dec commit 2e28eca
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 7 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ New language features

* Multi-line comments ([#69], [#6128]): `#= .... =#`

* --bounds-check=yes|no compiler option

Library improvements
--------------------

Expand Down
3 changes: 2 additions & 1 deletion doc/manual/getting-started.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ those available for the ``perl`` and ``ruby`` programs::

julia [options] [program] [args...]
-v --version Display version information
-h --help Print this message
-q --quiet Quiet startup without banner
-H --home=<dir> Load files relative to <dir>
-T --tab=<size> Set REPL tab width to <size>
Expand All @@ -116,7 +117,7 @@ those available for the ``perl`` and ``ruby`` programs::
-F Load ~/.juliarc.jl, then handle remaining inputs
--color=yes|no Enable or disable color text

-h --help Print this message
--check-bounds=yes|no Emit bounds checks always or never (ignoring declarations)

Resources
---------
Expand Down
8 changes: 6 additions & 2 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,7 +767,9 @@ static Value *emit_bounds_check(Value *i, Value *len, jl_codectx_t *ctx)
{
Value *im1 = builder.CreateSub(i, ConstantInt::get(T_size, 1));
#if CHECK_BOUNDS==1
if (ctx->boundsCheck.empty() || ctx->boundsCheck.back()==true) {
if (((ctx->boundsCheck.empty() || ctx->boundsCheck.back()==true) &&
jl_compileropts.check_bounds != JL_COMPILEROPT_CHECK_BOUNDS_OFF) ||
jl_compileropts.check_bounds == JL_COMPILEROPT_CHECK_BOUNDS_ON) {
Value *ok = builder.CreateICmpULT(im1, len);
raise_exception_unless(ok, prepare_global(jlboundserr_var), ctx);
}
Expand Down Expand Up @@ -1296,8 +1298,10 @@ static Value *emit_array_nd_index(Value *a, jl_value_t *ex, size_t nd, jl_value_
{
Value *i = ConstantInt::get(T_size, 0);
Value *stride = ConstantInt::get(T_size, 1);
bool bc = ctx->boundsCheck.empty() || ctx->boundsCheck.back()==true;
#if CHECK_BOUNDS==1
bool bc = ((ctx->boundsCheck.empty() || ctx->boundsCheck.back()==true) &&
jl_compileropts.check_bounds != JL_COMPILEROPT_CHECK_BOUNDS_OFF) ||
jl_compileropts.check_bounds == JL_COMPILEROPT_CHECK_BOUNDS_ON;
BasicBlock *failBB=NULL, *endBB=NULL;
if (bc) {
failBB = BasicBlock::Create(getGlobalContext(), "oob");
Expand Down
3 changes: 2 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2585,7 +2585,8 @@ static Value *emit_expr(jl_value_t *expr, jl_codectx_t *ctx, bool isboxed,
builder.SetInsertPoint(tryblk);
}
else if (head == boundscheck_sym) {
if (jl_array_len(ex->args) > 0) {
if (jl_array_len(ex->args) > 0 &&
jl_compileropts.check_bounds == JL_COMPILEROPT_CHECK_BOUNDS_DEFAULT) {
jl_value_t *arg = args[0];
if (arg == jl_true) {
ctx->boundsCheck.push_back(true);
Expand Down
3 changes: 2 additions & 1 deletion src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ extern BOOL (WINAPI *hSymRefreshModuleList)(HANDLE);

char *julia_home = NULL;
jl_compileropts_t jl_compileropts = { NULL, // build_path
0 // code_coverage
0, // code_coverage
JL_COMPILEROPT_CHECK_BOUNDS_DEFAULT
};

int jl_boot_file_loaded = 0;
Expand Down
7 changes: 6 additions & 1 deletion src/julia.h
Original file line number Diff line number Diff line change
Expand Up @@ -1294,11 +1294,16 @@ void jl_print_gc_stats(JL_STREAM *s);

typedef struct {
char *build_path;
int code_coverage;
int8_t code_coverage;
int8_t check_bounds;
} jl_compileropts_t;

extern DLLEXPORT jl_compileropts_t jl_compileropts;

#define JL_COMPILEROPT_CHECK_BOUNDS_DEFAULT 0
#define JL_COMPILEROPT_CHECK_BOUNDS_ON 1
#define JL_COMPILEROPT_CHECK_BOUNDS_OFF 2

#ifdef __cplusplus
}
#endif
Expand Down
10 changes: 9 additions & 1 deletion ui/repl.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ static const char *opts =
" -F Load ~/.juliarc.jl, then handle remaining inputs\n"
" --color=yes|no Enable or disable color text\n\n"

" --code-coverage Count executions of source lines\n";
" --code-coverage Count executions of source lines\n"
" --check-bounds=yes|no Emit bounds checks always or never (ignoring declarations)\n";

void parse_opts(int *argcp, char ***argvp)
{
Expand All @@ -55,6 +56,7 @@ void parse_opts(int *argcp, char ***argvp)
{ "help", no_argument, 0, 'h' },
{ "sysimage", required_argument, 0, 'J' },
{ "code-coverage", no_argument, &codecov, 1 },
{ "check-bounds", required_argument, 0, 300 },
{ 0, 0, 0, 0 }
};
int c;
Expand Down Expand Up @@ -90,6 +92,12 @@ void parse_opts(int *argcp, char ***argvp)
case 'h':
printf("%s%s", usage, opts);
exit(0);
case 300:
if (!strcmp(optarg,"yes"))
jl_compileropts.check_bounds = JL_COMPILEROPT_CHECK_BOUNDS_ON;
else if (!strcmp(optarg,"no"))
jl_compileropts.check_bounds = JL_COMPILEROPT_CHECK_BOUNDS_OFF;
break;
default:
ios_printf(ios_stderr, "julia: unhandled option -- %c\n", c);
ios_printf(ios_stderr, "This is a bug, please report it.\n");
Expand Down

0 comments on commit 2e28eca

Please sign in to comment.