JuliaLang / julia

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

Testing Julia pipeline in isolation via `opt` leads to invalid IR #55010

Open topolarity opened 2 weeks ago

topolarity commented 2 weeks ago

I followed the instructions at https://docs.julialang.org/en/v1.12-dev/devdocs/llvm/#Debugging-LLVM-transformations-in-isolation to do some Julia pass debugging.

optimize = false
fun, T = iterate, Tuple{Base.ANSIIterator, Tuple{Int64, Tuple{Base.RegexMatch{String}, Tuple{Int64, Bool}}}}
open("iterate.ll", "w") do file
    println(file, InteractiveUtils._dump_function(fun, T, false, false, false, true, :att, optimize, :default, false))
end

It looks like this is not a correct workflow, since it leads to invalid IR when trying to run opt:

$ ./usr/tools/opt -load-pass-plugin=usr/lib/libjulia-codegen.so --passes='julia' -o iterate_opt.bc iterate.ll
Invalid derived pointer in jlcall
          %35 = call nonnull ptr (ptr, ptr, ...) @julia.call(ptr @ijl_apply_generic, ptr %"+Core.BoundsError#596", ptr %"box::SubString193", ptr %box_Int64195)
Invalid derived pointer in jlcall
          %35 = call nonnull ptr (ptr, ptr, ...) @julia.call(ptr @ijl_apply_generic, ptr %"+Core.BoundsError#596", ptr %"box::SubString193", ptr %box_Int64195)
Invalid derived pointer in jlcall
          %184 = call nonnull ptr (ptr, ptr, ...) @julia.call(ptr @ijl_apply_generic, ptr %"+Core.ArgumentError#561", ptr %"jl_global#562")
Invalid derived pointer in jlcall
          %265 = call nonnull ptr (ptr, ptr, ...) @julia.call(ptr @ijl_apply_generic, ptr %"+Core.ArgumentError#56125", ptr %"jl_global#568")
Invalid derived pointer in jlcall
          %290 = call nonnull ptr (ptr, ptr, ...) @julia.call(ptr @ijl_apply_generic, ptr %"jl_global#571", ptr %"I::ANSIIterator.captures", ptr %"box::Tuple")
Invalid derived pointer in jlcall
          %290 = call nonnull ptr (ptr, ptr, ...) @julia.call(ptr @ijl_apply_generic, ptr %"jl_global#571", ptr %"I::ANSIIterator.captures", ptr %"box::Tuple")
Invalid derived pointer in jlcall
          %jl_f_tuple_ret = call nonnull ptr (ptr, ptr, ...) @julia.call(ptr @jl_f_tuple, ptr null, ptr %box_Int64, ptr %290)
Invalid derived pointer in jlcall
          %jl_f_tuple_ret = call nonnull ptr (ptr, ptr, ...) @julia.call(ptr @jl_f_tuple, ptr null, ptr %box_Int64, ptr %290)
Invalid derived pointer in jlcall
          %jl_f_tuple_ret46 = call nonnull ptr (ptr, ptr, ...) @julia.call(ptr @jl_f_tuple, ptr null, ptr %295, ptr %jl_f_tuple_ret)
Invalid derived pointer in jlcall
          %jl_f_tuple_ret46 = call nonnull ptr (ptr, ptr, ...) @julia.call(ptr @jl_f_tuple, ptr null, ptr %295, ptr %jl_f_tuple_ret)
PLEASE submit a bug report to https://github.com/julialang/julia and include the crash backtrace.
gbaraldi commented 2 weeks ago

You need raw=true which I think thoose docs don't have.

topolarity commented 2 weeks ago

Aha! Yes, that seems to do the trick.