@@ -371,8 +371,10 @@ static Value *emit_bounds_check(Value *i, Value *len, jl_codectx_t *ctx)
371371{
372372 Value *im1 = builder.CreateSub (i, ConstantInt::get (T_size, 1 ));
373373#if CHECK_BOUNDS==1
374- Value *ok = builder.CreateICmpULT (im1, len);
375- raise_exception_unless (ok, jlboundserr_var, ctx);
374+ if (ctx->boundsCheck .empty () || ctx->boundsCheck .back ()==true ) {
375+ Value *ok = builder.CreateICmpULT (im1, len);
376+ raise_exception_unless (ok, jlboundserr_var, ctx);
377+ }
376378#endif
377379 return im1;
378380}
@@ -681,9 +683,13 @@ static Value *emit_array_nd_index(Value *a, jl_value_t *ex, size_t nd, jl_value_
681683{
682684 Value *i = ConstantInt::get (T_size, 0 );
683685 Value *stride = ConstantInt::get (T_size, 1 );
686+ bool bc = ctx->boundsCheck .empty () || ctx->boundsCheck .back ()==true ;
684687#if CHECK_BOUNDS==1
685- BasicBlock *failBB = BasicBlock::Create (getGlobalContext (), " oob" );
686- BasicBlock *endBB = BasicBlock::Create (getGlobalContext (), " idxend" );
688+ BasicBlock *failBB=NULL , *endBB=NULL ;
689+ if (bc) {
690+ failBB = BasicBlock::Create (getGlobalContext (), " oob" );
691+ endBB = BasicBlock::Create (getGlobalContext (), " idxend" );
692+ }
687693#endif
688694 for (size_t k=0 ; k < nidxs; k++) {
689695 Value *ii = emit_unbox (T_size, T_psize, emit_unboxed (args[k], ctx));
@@ -693,28 +699,32 @@ static Value *emit_array_nd_index(Value *a, jl_value_t *ex, size_t nd, jl_value_
693699 Value *d =
694700 k >= nd ? ConstantInt::get (T_size, 1 ) : emit_arraysize (a, ex, k+1 , ctx);
695701#if CHECK_BOUNDS==1
696- BasicBlock *okBB = BasicBlock::Create (getGlobalContext (), " ib" );
697- // if !(i < d) goto error
698- builder.CreateCondBr (builder.CreateICmpULT (ii, d), okBB, failBB);
699- ctx->f ->getBasicBlockList ().push_back (okBB);
700- builder.SetInsertPoint (okBB);
702+ if (bc) {
703+ BasicBlock *okBB = BasicBlock::Create (getGlobalContext (), " ib" );
704+ // if !(i < d) goto error
705+ builder.CreateCondBr (builder.CreateICmpULT (ii, d), okBB, failBB);
706+ ctx->f ->getBasicBlockList ().push_back (okBB);
707+ builder.SetInsertPoint (okBB);
708+ }
701709#endif
702710 stride = builder.CreateMul (stride, d);
703711 }
704712 }
705713#if CHECK_BOUNDS==1
706- Value *alen = emit_arraylen (a, ex, ctx);
707- // if !(i < alen) goto error
708- builder.CreateCondBr (builder.CreateICmpULT (i, alen), endBB, failBB);
709-
710- ctx->f ->getBasicBlockList ().push_back (failBB);
711- builder.SetInsertPoint (failBB);
712- builder.CreateCall2 (jlthrow_line_func, builder.CreateLoad (jlboundserr_var),
713- ConstantInt::get (T_int32, ctx->lineno ));
714- builder.CreateUnreachable ();
715-
716- ctx->f ->getBasicBlockList ().push_back (endBB);
717- builder.SetInsertPoint (endBB);
714+ if (bc) {
715+ Value *alen = emit_arraylen (a, ex, ctx);
716+ // if !(i < alen) goto error
717+ builder.CreateCondBr (builder.CreateICmpULT (i, alen), endBB, failBB);
718+
719+ ctx->f ->getBasicBlockList ().push_back (failBB);
720+ builder.SetInsertPoint (failBB);
721+ builder.CreateCall2 (jlthrow_line_func, builder.CreateLoad (jlboundserr_var),
722+ ConstantInt::get (T_int32, ctx->lineno ));
723+ builder.CreateUnreachable ();
724+
725+ ctx->f ->getBasicBlockList ().push_back (endBB);
726+ builder.SetInsertPoint (endBB);
727+ }
718728#endif
719729
720730 return i;
0 commit comments