@@ -377,13 +377,20 @@ macro _nospecializeinfer_meta()
377377    return  Expr (:meta , :nospecializeinfer )
378378end 
379379
380- function  _checkbounds_array (:: Type{Bool} , A:: Union{Array, GenericMemory} , i:: Int )
380+ #  NOTE: this function expects one-based indexing.  We can't use `require_one_based_indexing`
381+ #  here because it's defined later in the bootstrap process.  Use only where you are really
382+ #  sure about indexing.
383+ function  _checkbounds_array_onebased (:: Type{Bool} , len:: Integer , i:: Int )
381384    @inline 
382-     ult_int (bitcast (UInt, sub_int (i, 1 )), bitcast (UInt, length (A) ))
385+     ult_int (bitcast (UInt, sub_int (i, 1 )), bitcast (UInt, len ))
383386end 
384- function  _checkbounds_array (A :: Union{Array, GenericMemory} , i:: Int )
387+ function  _checkbounds_array_onebased ( :: Type{Bool} , A :: AbstractArray , i:: Int )
385388    @inline 
386-     _checkbounds_array (Bool, A, i) ||  throw_boundserror (A, (i,))
389+     _checkbounds_array_onebased (Bool, length (A), i)
390+ end 
391+ function  _checkbounds_array_onebased (A:: Union{Array, GenericMemory} , i:: Int )
392+     @inline 
393+     _checkbounds_array_onebased (Bool, A, i) ||  throw_boundserror (A, (i,))
387394end 
388395
389396default_access_order (a:: GenericMemory{:not_atomic} ) =  :not_atomic 
@@ -393,7 +400,7 @@ default_access_order(a::GenericMemoryRef{:atomic}) = :monotonic
393400
394401function  getindex (A:: GenericMemory , i:: Int )
395402    @_noub_if_noinbounds_meta 
396-     (@_boundscheck ) &&  _checkbounds_array (A, i)
403+     (@_boundscheck ) &&  _checkbounds_array_onebased (A, i)
397404    memoryrefget (memoryrefnew (memoryrefnew (A), i, false ), default_access_order (A), false )
398405end 
399406
@@ -962,13 +969,13 @@ end
962969#  linear indexing
963970function  getindex (A:: Array , i:: Int )
964971    @_noub_if_noinbounds_meta 
965-     @boundscheck  _checkbounds_array (A, i)
972+     @boundscheck  _checkbounds_array_onebased (A, i)
966973    memoryrefget (memoryrefnew (getfield (A, :ref ), i, false ), :not_atomic , false )
967974end 
968975#  simple Array{Any} operations needed for bootstrap
969976function  setindex! (A:: Array{Any} , @nospecialize (x), i:: Int )
970977    @_noub_if_noinbounds_meta 
971-     @boundscheck  _checkbounds_array (A, i)
978+     @boundscheck  _checkbounds_array_onebased (A, i)
972979    memoryrefset! (memoryrefnew (getfield (A, :ref ), i, false ), x, :not_atomic , false )
973980    return  A
974981end 
0 commit comments