JuliaLang / julia

The Julia Programming Language
https://julialang.org/
MIT License
45.86k stars 5.49k forks source link

gotoing to inside of a gc_preserve crashes julia #55905

Open gbaraldi opened 1 month ago

gbaraldi commented 1 month ago
function foo()
              x = Ref{Int}(101)
              p = Base.unsafe_convert(Ptr{Int}, x)
              @goto foo2
              GC.@preserve x begin
              @label foo2
              unsafe_load(p)
              end
              end

foo()
Internal error: during type inference of
foo()
Encountered unexpected error in runtime:
MethodError(f=Base.inferencebarrier, args=(typeof(Core.Compiler._assert_tostring)(),), world=0x00000000000017b6)
jl_method_error_bare at /Users/gabrielbaraldi/julia2/src/gf.c:2349
jl_method_error at /Users/gabrielbaraldi/julia2/src/gf.c:2367
jl_lookup_generic_ at /Users/gabrielbaraldi/julia2/src/gf.c:3344 [inlined]
ijl_apply_generic at /Users/gabrielbaraldi/julia2/src/gf.c:3359
renumber_ssa at ./compiler/ssair/slot2ssa.jl:56
#renumber_ssa!##0 at ./compiler/ssair/slot2ssa.jl:62 [inlined]
ssamap at ./compiler/utilities.jl:392
renumber_ssa! at ./compiler/ssair/slot2ssa.jl:62 [inlined]
domsort_ssa! at ./compiler/ssair/slot2ssa.jl:460
construct_ssa! at ./compiler/ssair/slot2ssa.jl:879
slot2reg at ./compiler/optimize.jl:1280 [inlined]
run_passes_ipo_safe at ./compiler/optimize.jl:986
run_passes_ipo_safe at ./compiler/optimize.jl:1001 [inlined]
optimize at ./compiler/optimize.jl:975
jfptr_optimize_34044 at /Users/gabrielbaraldi/julia2/usr/lib/julia/sys.dylib (unknown line)
_jl_invoke at /Users/gabrielbaraldi/julia2/src/gf.c:3167
finish_nocycle at ./compiler/typeinfer.jl:278
_typeinf at ./compiler/typeinfer.jl:266
typeinf at ./compiler/typeinfer.jl:207
typeinf_ext at ./compiler/typeinfer.jl:1184
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1255 [inlined]
typeinf_ext_toplevel at ./compiler/typeinfer.jl:1253
jfptr_typeinf_ext_toplevel_31411 at /Users/gabrielbaraldi/julia2/usr/lib/julia/sys.dylib (unknown line)
_jl_invoke at /Users/gabrielbaraldi/julia2/src/gf.c:3167
jl_apply at /Users/gabrielbaraldi/julia2/src/julia.h:2220 [inlined]
jl_type_infer at /Users/gabrielbaraldi/julia2/src/gf.c:394
jl_compile_method_internal at /Users/gabrielbaraldi/julia2/src/gf.c:2733
_jl_invoke at /Users/gabrielbaraldi/julia2/src/gf.c:3178
topolarity commented 1 month ago

Our definition of gc_preserve_begin strongly suggests there should be a single syntactic entry to the block, so I guess the bug here is that we don't enforce that in lowering