Skip to content

Segfault when reinterpreting in a for loop #20847

@fredrikekre

Description

@fredrikekre

Found this in https://github.com/KristofferC/JuAFEM.jl/pull/123 on all nightly build bots. Reduced to the following MRE:

function segfaultfunction{N, T}(A::Vector{NTuple{N, T}})
    B = reinterpret(T, A, (N, length(A)))
    return nothing
end

tuplevec = Tuple{Float64, Float64}[(0.0,0.0), (1.0,0.0)]

for A in (1,)
    segfaultfunction(tuplevec)
end

Pasting this in the REPL gives:

signal (4): Illegal instruction
while loading no file, in expression starting on line 0
macro expansion at ./REPL[3]:2 [inlined]
anonymous at ./<missing> (unknown line)
jl_call_method_internal at /home/fredrik/julia-master/src/julia_internal.h:248 [inlined]
jl_toplevel_eval_flex at /home/fredrik/julia-master/src/toplevel.c:589
jl_toplevel_eval_in at /home/fredrik/julia-master/src/builtins.c:484
eval at ./boot.jl:235
unknown function (ip: 0x7ff385ed745f)
jl_call_method_internal at /home/fredrik/julia-master/src/julia_internal.h:248 [inlined]
jl_apply_generic at /home/fredrik/julia-master/src/gf.c:2212
eval_user_input at ./REPL.jl:66
unknown function (ip: 0x7ff176788ac6)
jl_call_method_internal at /home/fredrik/julia-master/src/julia_internal.h:248 [inlined]
jl_apply_generic at /home/fredrik/julia-master/src/gf.c:2212
macro expansion at ./REPL.jl:97 [inlined]
#1 at ./event.jl:73
unknown function (ip: 0x7ff176782eff)
jl_call_method_internal at /home/fredrik/julia-master/src/julia_internal.h:248 [inlined]
jl_apply_generic at /home/fredrik/julia-master/src/gf.c:2212
jl_apply at /home/fredrik/julia-master/src/julia.h:1410 [inlined]
start_task at /home/fredrik/julia-master/src/task.c:261
unknown function (ip: 0xffffffffffffffff)
Allocations: 3330816 (Pool: 3329230; Big: 1586); GC: 4
Illegal instruction (core dumped)

The following functions also segfaults:

function segfaultfunction{T}(A::Vector{Tuple{T, T}})
    B = reinterpret(T, A, (2, length(A)))
    return nothing
end

function segfaultfunction{N}(A::Vector{NTuple{N, Float64}})
    B = reinterpret(Float64, A, (N, length(A)))
    return nothing
end

but this one (without any paremeters N or T) works

function no_segfaultfunction(A::Vector{Tuple{Float64, Float64}})
    B = reinterpret(Float64, A, (2, length(A)))
    return nothing
end
  • It should also be noted that this only segfaults if the for-loop is there.
  • If tuplevec is defined inside the for-loop it doesn't segfault (same mechanism as if the for-loop wouldn't be there I guess)
  • The reinterpret inside the function is successful, e.g. @show B before returning works

Perhaps related to #17003 but the examples in this issue all work on 0.5 so I figured this might be another issue.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugIndicates an unexpected problem or unintended behaviortypes and dispatchTypes, subtyping and method dispatch

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions