From 62dd4f708f5523a22ae95c216bc9ee4aff5ccf14 Mon Sep 17 00:00:00 2001 From: Kristoffer Carlsson Date: Thu, 1 Apr 2021 15:01:16 +0200 Subject: [PATCH] add a missing propagate_inbounds to a getindex method (#40281) * add a missing propagate_inbounds --- base/abstractarray.jl | 2 +- test/boundscheck_exec.jl | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 724b23c6e8ca33..47d66559910006 100644 --- a/base/abstractarray.jl +++ b/base/abstractarray.jl @@ -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 diff --git a/test/boundscheck_exec.jl b/test/boundscheck_exec.jl index 62a20921bd44ea..e1a7029334a3da 100644 --- a/test/boundscheck_exec.jl +++ b/test/boundscheck_exec.jl @@ -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