diff --git a/base/array.jl b/base/array.jl index 6c07d0f1b15e4..062359599d824 100644 --- a/base/array.jl +++ b/base/array.jl @@ -642,7 +642,7 @@ end ## Iteration ## start(A::Array) = 1 next(a::Array,i) = (@_propagate_inbounds_meta; (a[i],i+1)) -done(a::Array,i) = (@_inline_meta; i == length(a)+1) +done(a::Array,i) = (@_inline_meta; i >= length(a)+1) ## Indexing: getindex ## diff --git a/test/arrayops.jl b/test/arrayops.jl index cd8dd8cebadc9..53fe39b2ff6ec 100644 --- a/test/arrayops.jl +++ b/test/arrayops.jl @@ -2424,6 +2424,17 @@ end @inferred hash([1,2,3]) end +function f27079() + X = rand(5) + for x in X + resize!(X, 0) + end + length(X) +end +@testset "iteration over resized vector" begin + @test f27079() == 0 +end + @testset "indices-related shape promotion errors" begin @test_throws DimensionMismatch Base.promote_shape((2,), (3,)) @test_throws DimensionMismatch Base.promote_shape((2, 3), (2, 4)) diff --git a/test/boundscheck_exec.jl b/test/boundscheck_exec.jl index 138059d8fcb8a..62a20921bd44e 100644 --- a/test/boundscheck_exec.jl +++ b/test/boundscheck_exec.jl @@ -2,7 +2,7 @@ module TestBoundsCheck -using Test, Random +using Test, Random, InteractiveUtils @enum BCOption bc_default bc_on bc_off bc_opt = BCOption(Base.JLOptions().check_bounds) @@ -239,4 +239,17 @@ if bc_opt != bc_off @test_throws BoundsError BadVector20469([1,2,3])[:] end +# Ensure iteration over arrays is vectorizable with boundschecks off +function g27079(X) + r = 0 + @inbounds for x in X + r += x + end + r +end +if bc_opt == bc_default || bc_opt == bc_off + @test occursin("vector.body", sprint(code_llvm, g27079, Tuple{Vector{Int}})) +end + + end