From d5869b71e5e153792cfc92b4ce2063a51906104e Mon Sep 17 00:00:00 2001 From: KristofferC Date: Wed, 31 Mar 2021 16:49:29 +0200 Subject: [PATCH 1/2] add a missing propagate_inbounds --- base/abstractarray.jl | 2 +- test/boundscheck_exec.jl | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/base/abstractarray.jl b/base/abstractarray.jl index 4bc3c4f70ebb4..d2c309bbcc5e7 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 62a20921bd44e..a8a63e7f1542a 100644 --- a/test/boundscheck_exec.jl +++ b/test/boundscheck_exec.jl @@ -251,5 +251,10 @@ 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}) +@test occursin("arrayref(false", typed_40281) +@test !occursin("arrayref(true", typed_40281) end From 8dc558d27cf77d8695303ddd7d73e9f7a7382b7f Mon Sep 17 00:00:00 2001 From: KristofferC Date: Wed, 31 Mar 2021 18:29:09 +0200 Subject: [PATCH 2/2] try fix test --- test/boundscheck_exec.jl | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/test/boundscheck_exec.jl b/test/boundscheck_exec.jl index a8a63e7f1542a..e1a7029334a3d 100644 --- a/test/boundscheck_exec.jl +++ b/test/boundscheck_exec.jl @@ -254,7 +254,9 @@ 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}) -@test occursin("arrayref(false", typed_40281) -@test !occursin("arrayref(true", typed_40281) +if bc_opt == bc_default || bc_opt == bc_off + @test occursin("arrayref(false", typed_40281) + @test !occursin("arrayref(true", typed_40281) +end end