Skip to content

Commit

Permalink
add a missing propagate_inbounds to a getindex method (#40281)
Browse files Browse the repository at this point in the history
* add a missing propagate_inbounds

(cherry picked from commit 80002db)
  • Loading branch information
KristofferC authored and staticfloat committed Dec 22, 2022
1 parent ef74fed commit d9a8523
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1170,7 +1170,7 @@ function getindex(A::AbstractArray, I...)
_getindex(IndexStyle(A), A, to_indices(A, I)...)
end
# To avoid invalidations from multidimensional.jl: getindex(A::Array, i1::Union{Integer, CartesianIndex}, I::Union{Integer, CartesianIndex}...)
getindex(A::Array, i1::Integer, I::Integer...) = A[to_indices(A, (i1, I...))...]
@propagate_inbounds getindex(A::Array, i1::Integer, I::Integer...) = A[to_indices(A, (i1, I...))...]

function unsafe_getindex(A::AbstractArray, I...)
@_inline_meta
Expand Down
7 changes: 7 additions & 0 deletions test/boundscheck_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -251,5 +251,12 @@ if bc_opt == bc_default || bc_opt == bc_off
@test occursin("vector.body", sprint(code_llvm, g27079, Tuple{Vector{Int}}))
end

# Boundschecking removal of indices with different type, see #40281
getindex_40281(v, a, b, c) = @inbounds getindex(v, a, b, c)
typed_40281 = sprint((io, args...) -> code_warntype(io, args...; optimize=true), getindex_40281, Tuple{Array{Float64, 3}, Int, UInt8, Int})
if bc_opt == bc_default || bc_opt == bc_off
@test occursin("arrayref(false", typed_40281)
@test !occursin("arrayref(true", typed_40281)
end

end

0 comments on commit d9a8523

Please sign in to comment.