Skip to content

Extra 1 dimensions in reinterpreted arrays cause stack overflow #57170

@AaronGhost

Description

@AaronGhost

Hi, thanks for everyone's work on Julia!

Following the manual on arrays, one can add extra "1" in indexing Nd arrays.
This works as expected for Array but creates a Stack Overflow with ReinterpretArray on 1.10, last release and nightly.

X = rand(Float32, (2,5))
X[1, :, 1] # works as expected

X2 = rand(ComplexF32, 5)
Xr = reinterpret(reshape, Float32, X2)
Xr[1, :, 1] # Stack overflow

The stack overflow error:

[1] _getindex(::Base.IndexSCartesian2{2}, ::Base.ReinterpretArray{Float32, 2, ComplexF32, Vector{ComplexF32}, true}, ::Int64, ::Int64, ::Vararg{Int64})
@ Base ./multidimensional.jl:953
[2] getindex(::Base.ReinterpretArray{Float32, 2, ComplexF32, Vector{ComplexF32}, true}, ::Int64, ::Int64, ::Int64)
 @ Base ./abstractarray.jl:1342
 [3] macro expansion
@ ./multidimensional.jl:979 [inlined]
[4] macro expansion
@ ./cartesian.jl:64 [inlined]
[5] macro expansion
@ ./multidimensional.jl:977 [inlined]
[6] _unsafe_getindex!
@ ./multidimensional.jl:987 [inlined]
[7] _unsafe_getindex(::Base.IndexSCartesian2{2}, ::Base.ReinterpretArray{Float32, 2, ComplexF32, Vector{ComplexF32}, true}, ::Int64, ::Int64, ::Int64)
 @ Base ./multidimensional.jl:968
 [8] _getindex(::Base.IndexSCartesian2{2}, ::Base.ReinterpretArray{Float32, 2, ComplexF32, Vector{ComplexF32}, true}, ::Int64, ::Int64, ::Vararg{Int64})
@ Base ./multidimensional.jl:954
--- the above 7 lines are repeated 11134 more times ---
 [77947] getindex
 @ ./abstractarray.jl:1342 [inlined]
[77948] macro expansion
@ ./multidimensional.jl:979 [inlined]
[77949] macro expansion
@ ./cartesian.jl:64 [inlined]
[77950] macro expansion
@ ./multidimensional.jl:977 [inlined]
[77951] _unsafe_getindex!
@ ./multidimensional.jl:987 [inlined]
[77952] _unsafe_getindex
 @ ./multidimensional.jl:968 [inlined]
[77953] _getindex
@ ./multidimensional.jl:954 [inlined]
[77954] getindex(::Base.ReinterpretArray{Float32, 2, ComplexF32, Vector{ComplexF32}, true}, ::UnitRange{Int64}, ::Function, ::Int64)
 @ Base ./abstractarray.jl:1342

Metadata

Metadata

Assignees

No one assigned

    Labels

    arrays[a, r, r, a, y, s]bugIndicates an unexpected problem or unintended behavior

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions