pointer(A::Array{T}) has misleading type for non-bitstype A #30276
Open
Description
julia> function foo()
A=[([],), ([],)];
x=unsafe_load(pointer(A));
A[2]=x;
p1 = unsafe_load(reinterpret(Ptr{UInt64},pointer(A)), 1)
p2 = unsafe_load(reinterpret(Ptr{UInt64},pointer(A)), 2)
p3 = unsafe_load(reinterpret(Ptr{UInt64},p2))
@show p1,p2,p3
return A
end
julia> r=foo();
(p1, p2, p3) = (0x00007f2f0543f8d0, 0x00007f2f05638110, 0x00007f2f0543f8d0)
julia> r
2-element Array{Tuple{Array{Any,1}},1}:
signal (11): Segmentation fault
I am not entirely sure whether this is supposed to be working. If not, then maybe unsafe_load
could error out earlier.
If this is supposed to be working, we see that someone got confused about types / numbers of indirection: A[2]
points to something that points to A[1]
, instead of pointing to something that points to A[1][1]
(like e.g. A[1]
). Also reproduces in the REPL (ie without compilation). Tested on 1.0.2.