From f9826c5df2ec8138f4d220a94ce12e5b7266da2f Mon Sep 17 00:00:00 2001 From: Matt Bauman Date: Thu, 7 Sep 2017 19:40:34 -0500 Subject: [PATCH] Fix and test #23629 --- base/deprecated.jl | 5 ++--- src/cgutils.cpp | 2 +- test/arrayops.jl | 6 ++++++ 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/base/deprecated.jl b/base/deprecated.jl index 63834b608fa02..643a2b6671284 100644 --- a/base/deprecated.jl +++ b/base/deprecated.jl @@ -1728,9 +1728,8 @@ end # issue #14470 # This definition will gracefully supercede the real definition until deprecations are removed @inline function checkbounds_indices(::Type{Bool}, IA::Tuple{Any,Vararg{Any}}, ::Tuple{}) - if any(x->unsafe_length(x)!=1, IA) - _depwarn_for_trailing_indices(IA) - end + any(x->unsafe_length(x)==0, IA) && return false + any(x->unsafe_length(x)!=1, IA) && return _depwarn_for_trailing_indices(IA) return true end function _depwarn_for_trailing_indices(n::Integer) # Called by the C boundscheck diff --git a/src/cgutils.cpp b/src/cgutils.cpp index 393d9b50b295b..e45a21c81bad7 100644 --- a/src/cgutils.cpp +++ b/src/cgutils.cpp @@ -1664,7 +1664,7 @@ static Value *emit_array_nd_index( if (bc) { // We have already emitted a bounds check for each index except for // the last one which we therefore have to do here. - if (nidxs == 1 && nd > 1) { + if (nidxs == 1) { // Linear indexing: Check against the entire linear span of the array Value *alen = emit_arraylen(ctx, ainfo, ex); ctx.builder.CreateCondBr(ctx.builder.CreateICmpULT(i, alen), endBB, failBB); diff --git a/test/arrayops.jl b/test/arrayops.jl index 3848aa14e61cc..bd16194f1938d 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -2210,3 +2210,9 @@ let a = Vector{Int}[[1]], @test eltype([a;b]) == Vector{Float64} @test eltype([a;c]) == Vector end + +# Issue #23629 +@testset "issue 23629" begin + @test_throws BoundsError zeros(2,3,0)[2,3] + @test_throws BoundsError checkbounds(zeros(2,3,0), 2, 3) +end