Skip to content

Commit 76b9754

Browse files
committed
add a missing propagate_inbounds to a getindex method (#40281)
* add a missing propagate_inbounds (cherry picked from commit 80002db)
1 parent a595d69 commit 76b9754

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

base/abstractarray.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1170,7 +1170,7 @@ function getindex(A::AbstractArray, I...)
11701170
_getindex(IndexStyle(A), A, to_indices(A, I)...)
11711171
end
11721172
# To avoid invalidations from multidimensional.jl: getindex(A::Array, i1::Union{Integer, CartesianIndex}, I::Union{Integer, CartesianIndex}...)
1173-
getindex(A::Array, i1::Integer, I::Integer...) = A[to_indices(A, (i1, I...))...]
1173+
@propagate_inbounds getindex(A::Array, i1::Integer, I::Integer...) = A[to_indices(A, (i1, I...))...]
11741174

11751175
function unsafe_getindex(A::AbstractArray, I...)
11761176
@_inline_meta

test/boundscheck_exec.jl

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,5 +251,12 @@ if bc_opt == bc_default || bc_opt == bc_off
251251
@test occursin("vector.body", sprint(code_llvm, g27079, Tuple{Vector{Int}}))
252252
end
253253

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

255262
end

0 commit comments

Comments
 (0)