Skip to content

Commit

Permalink
fix boundscheck value propagation codegen bug (JuliaLang#23595)
Browse files Browse the repository at this point in the history
  • Loading branch information
jrevels committed Sep 6, 2017
1 parent 7bb0d53 commit 508c9f5
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,8 @@ static bool bounds_check_enabled(jl_codectx_t &ctx, jl_value_t *inbounds) {
static Value *emit_bounds_check(jl_codectx_t &ctx, const jl_cgval_t &ainfo, jl_value_t *ty, Value *i, Value *len, jl_value_t *boundscheck)
{
Value *im1 = ctx.builder.CreateSub(i, ConstantInt::get(T_size, 1));
jl_cgval_t ib = emit_expr(ctx, boundscheck);
#if CHECK_BOUNDS==1
if (bounds_check_enabled(ctx, ib.constant)) {
if (bounds_check_enabled(ctx, boundscheck)) {
Value *ok = ctx.builder.CreateICmpULT(im1, len);
BasicBlock *failBB = BasicBlock::Create(jl_LLVMContext, "fail", ctx.f);
BasicBlock *passBB = BasicBlock::Create(jl_LLVMContext, "pass");
Expand Down Expand Up @@ -1630,9 +1629,8 @@ static Value *emit_array_nd_index(
Value *a = boxed(ctx, ainfo);
Value *i = ConstantInt::get(T_size, 0);
Value *stride = ConstantInt::get(T_size, 1);
jl_cgval_t ib = emit_expr(ctx, inbounds);
#if CHECK_BOUNDS==1
bool bc = bounds_check_enabled(ctx, ib.constant);
bool bc = bounds_check_enabled(ctx, inbounds);
BasicBlock *failBB = NULL, *endBB = NULL;
if (bc) {
failBB = BasicBlock::Create(jl_LLVMContext, "oob");
Expand Down
5 changes: 5 additions & 0 deletions test/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -245,3 +245,8 @@ let c = [1,2,3]
len2 = issue22582!(c, true)
@test len1 == len2
end

# PR #23595
@generated f23595(g, args...) = Expr(:call, :g, Expr(:(...), :args))
x23595 = rand(1)
@test f23595(Core.arrayref, true, x23595, 1) == x23595[]

0 comments on commit 508c9f5

Please sign in to comment.