Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix regression in generic_bitcast with Union{} arguments. #47605

Merged
merged 2 commits into from
Nov 24, 2022

Conversation

maleadt
Copy link
Member

@maleadt maleadt commented Nov 17, 2022

#47170 introduced a regression with bitcasts of error values (i.e. ::Union{}), resulting in a failed assertion/segfault:

julia> f(x) = Core.bitcast(UInt64, x)
f (generic function with 1 method)

julia> code_llvm(f, Type{Union{}})
julia-debug: /home/tim/Julia/src/julia/src/intrinsics.cpp:536: jl_cgval_t generic_bitcast(jl_codectx_t&, const jl_cgval_t*): Assertion `!v.isghost' failed.

[730343] signal (6): Aborted
in expression starting at REPL[2]:1
unknown function (ip: 0x7fb345c8c64c)
gsignal at /usr/lib/libc.so.6 (unknown line)
abort at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0x7fb345c2645b)
__assert_fail at /usr/lib/libc.so.6 (unknown line)
generic_bitcast at /home/tim/Julia/src/julia/src/intrinsics.cpp:536

This manifested on PkgEval in the testing of ANOVAapprox.jl (as well as Gtk.jl, and probably others), https://s3.amazonaws.com/julialang-reports/nanosoldier/pkgeval/by_date/2022-11/15/ANOVAapprox.primary.log, which contains code like:

struct Foo
    bar::Int32
end

function Base.getproperty(obj::Foo, field::Symbol)
    if field == :whatever
        unsafe_wrap(Vector{Float64}, ptr, obj.bar)
    elseif field == :return
        ccall(:jl_breakpoint, Int64, ())
    else
        getfield(obj, field)
    end
end

Compiling this results in essentially:

%4 = Main.getfield(_2, :bar)::Int32
%32 = π (%4, Int64)
%40 = bitcast(UInt64, %32)

... where inference thinks that %32 produces a Int64, but during codegen it turns out that π (%4::Int32, Int64) produces Union{} (as determined by convert_julia_type) which then crashes bitcast as seen above.

@maleadt maleadt added regression Regression in behavior compared to a previous version compiler:codegen Generation of LLVM IR and native code bugfix This change fixes an existing bug labels Nov 17, 2022
@maleadt maleadt added this to the 1.9 milestone Nov 17, 2022
@maleadt maleadt requested a review from vtjnash November 17, 2022 12:05
@maleadt maleadt added the backport 1.9 Change should be backported to release-1.9 label Nov 17, 2022
@maleadt
Copy link
Member Author

maleadt commented Nov 23, 2022

Rebased and addressed review comments.

@maleadt maleadt requested a review from vtjnash November 23, 2022 12:15
@vtjnash vtjnash added the merge me PR is reviewed. Merge when all tests are passing label Nov 24, 2022
@maleadt
Copy link
Member Author

maleadt commented Nov 24, 2022

CI failures unrelated; win32 seems broken on master too.

@maleadt maleadt merged commit 726bbd7 into master Nov 24, 2022
@maleadt maleadt deleted the tb/bitcast_bottom branch November 24, 2022 11:30
@DilumAluthge DilumAluthge removed the merge me PR is reviewed. Merge when all tests are passing label Nov 28, 2022
KristofferC pushed a commit that referenced this pull request Nov 28, 2022
@KristofferC KristofferC mentioned this pull request Dec 14, 2022
26 tasks
@KristofferC KristofferC removed the backport 1.9 Change should be backported to release-1.9 label Dec 27, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug compiler:codegen Generation of LLVM IR and native code regression Regression in behavior compared to a previous version
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants