Skip to content

Commit

Permalink
Missing boundscheck in meta_elim_pass!
Browse files Browse the repository at this point in the history
Fix #18412
  • Loading branch information
yuyichao committed Sep 8, 2016
1 parent 5c1bcb9 commit 8cfe93a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
11 changes: 7 additions & 4 deletions base/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3279,17 +3279,17 @@ function meta_elim_pass!(linfo::LambdaInfo, code::Array{Any,1})
# The clearing needs to be propagated up during pop
# This is not pushed to if the push is already eliminated
# Also shared for `Expr(:boundscheck)` and `Expr(:inbounds)`
bounds_push_pos_stack = [0]
bounds_push_pos_stack = [0] # always non-empty
# Number of boundscheck pushes in a eliminated boundscheck block
void_boundscheck_depth = 0
is_inbounds = check_bounds == 2
enabled = true

# Position of the last line number node without any non-meta expressions
# in between.
prev_dbg_stack = [0]
prev_dbg_stack = [0] # always non-empty
# Whether there's any non-meta exprs after the enclosing `push_loc`
push_loc_pos_stack = [0]
push_loc_pos_stack = [0] # always non-empty

for i in 1:length(code)
ex = code[i]
Expand Down Expand Up @@ -3330,6 +3330,7 @@ function meta_elim_pass!(linfo::LambdaInfo, code::Array{Any,1})
if !(args[1] === :pop)
void_boundscheck_depth += 1
elseif void_boundscheck_depth == 0
# There must have been a push
pop!(bounds_elim_stack)
enabled = true
else
Expand Down Expand Up @@ -3379,7 +3380,7 @@ function meta_elim_pass!(linfo::LambdaInfo, code::Array{Any,1})
end
arg1 = args[1]
if arg1 === true
if inbounds_stack[end]
if !isempty(inbounds_stack) && inbounds_stack[end]
code[i] = nothing
push!(bounds_elim_stack, true)
else
Expand All @@ -3390,6 +3391,8 @@ function meta_elim_pass!(linfo::LambdaInfo, code::Array{Any,1})
push!(inbounds_stack, true)
elseif arg1 === false
if is_inbounds
# There must have been a `true` on the stack so
# `inbounds_stack` must not be empty
if !inbounds_stack[end]
is_inbounds = false
end
Expand Down
6 changes: 6 additions & 0 deletions test/core.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4555,6 +4555,12 @@ end
# variable name in the error is tested above in `TestSSA16244`
@test_throws UndefVarError f18386(1, 2, true)

Base.@propagate_inbounds function f18412(a)
@inbounds b = a[1]
return b
end
@test f18412([1]) == 1

# issue #18173
function f18173()
identity(()->successflag)
Expand Down

0 comments on commit 8cfe93a

Please sign in to comment.