Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/jlgen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -796,8 +796,11 @@ function relocate_gvs!(mod::LLVM.Module, gv_to_value::Dict{String, Ptr{Cvoid}})
val = nothing
if init != C_NULL
obj = Base.unsafe_pointer_to_objref(init)
# Zero-sized objects remain identity tokens.
if isbitstype(typeof(obj)) && sizeof(obj) > 0 && !(obj isa Bool)
# Zero-sized objects remain identity tokens. Type objects also stay
# identity tokens: some are isbits singletons (e.g. `Union{}`, whose
# `typeof` is the isbits singleton `Core.TypeofBottom`), but `sizeof`
# is undefined for uninhabited types and would throw here.
if isbitstype(typeof(obj)) && !(obj isa Type) && sizeof(obj) > 0 && !(obj isa Bool)
val, hdr = materialize_box!(mod, gv, obj, init)
# non-smalltag headers carry a host DataType pointer
portable &= hdr < UInt(64 << 4) # jl_max_tags << 4
Expand Down
13 changes: 13 additions & 0 deletions test/native.jl
Original file line number Diff line number Diff line change
Expand Up @@ -429,6 +429,19 @@ end
@test length(elements(LLVM.global_value_type(box))) == 3
dispose(m)
end

# Type objects stay identity tokens rather than being materialized.
# `Union{}` is the tricky case: `typeof(Union{})` is the isbits
# singleton `Core.TypeofBottom`, so the `isbitstype` guard passes,
# but `sizeof(Union{})` throws (uninhabited type). It must be baked
# as an address, not fed to `materialize_box!`.
let ptr = ccall(:jl_value_ptr, Ptr{Cvoid}, (Any,), Union{})
m, map = slot_module(ptr)
@test !GPUCompiler.relocate_gvs!(m, map)
@test !haskey(globals(m), "jl_global_0_box")
@test occursin("inttoptr", string(m))
dispose(m)
end
end
end

Expand Down