Skip to content

Commit

Permalink
Broadcast shouldn't use inbounds when calling f
Browse files Browse the repository at this point in the history
Previously, `broadcast(getindex, A, I...)` would call `getindex` within an
at-inbounds context. This patch simply moves the function call so that it
will throw a BoundsError appropriately.
  • Loading branch information
mbauman committed Nov 2, 2016
1 parent 7aba3f5 commit 940c111
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
3 changes: 2 additions & 1 deletion base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,8 @@ end
# extract array values
@nexprs $nargs i->(@inbounds val_i = _broadcast_getindex(A_i, I_i))
# call the function and store the result
@inbounds B[I] = @ncall $nargs f val
result = @ncall $nargs f val
@inbounds B[I] = result
end
end
end
Expand Down
5 changes: 5 additions & 0 deletions test/boundscheck_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -174,4 +174,9 @@ if bc_opt != bc_off
@test_throws BoundsError k1(Int[])
end

# Ensure that broadcast doesn't use @inbounds when calling the function
let A = zeros(3,3)
@test_throws BoundsError broadcast(getindex, A, 1:3, 1:3)
end

end

0 comments on commit 940c111

Please sign in to comment.