Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Missing boundscheck in meta_elim_pass! #18414

Merged
merged 1 commit into from
Sep 9, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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