Skip to content

Fix handling of inline-allocated structures with unions. - #1717

Merged
maleadt merged 1 commit into
masterfrom
tb/union_structs
Jan 5, 2023
Merged

maleadt merged 1 commit into
masterfrom
tb/union_structs

Conversation

@maleadt

@maleadt maleadt commented Jan 5, 2023

Copy link
Copy Markdown
Member

These aren't isbits, but also do not require a selector array. Instead, Julia handles the selector bit automatically:

julia> struct Bar
       x::Union{Int8,UInt8}
       end

julia> a = [Bar(Int8(1)), Bar(UInt8(2)), Bar(Int8(3))]
3-element Vector{Bar}:
 Bar(1)
 Bar(0x02)
 Bar(3)

julia> hexdump(pointer(a), 6)
00000000  01 00 02 01 03 00                                 │ ...... │
00000006
julia> unsafe_load(pointer(a,1))
Bar(1)

julia> unsafe_load(pointer(a,2))
Bar(0x02)

julia> unsafe_load(pointer(a,3))
Bar(3)

julia> sizeof(Bar)
2

julia> Base.allocatedinline(Bar)
true

julia> Base.isbitstype(Bar)
false

Encountered using an assertions build:

julia: /home/tim/Julia/src/julia/src/array.c:58: ijl_array_typetagdata: Assertion `jl_array_isbitsunion(a)' failed.

[4188443] signal (6.-6): Aborted
in expression starting at /home/tim/Julia/pkg/CUDA/wip.jl:9
unknown function (ip: 0x7f47b461e64c)
gsignal at /usr/lib/libc.so.6 (unknown line)
abort at /usr/lib/libc.so.6 (unknown line)
unknown function (ip: 0x7f47b45b845b)
__assert_fail at /usr/lib/libc.so.6 (unknown line)
ijl_array_typetagdata at /home/tim/Julia/src/julia/src/array.c:58 [inlined]
ijl_array_typetagdata at /home/tim/Julia/src/julia/src/array.c:56
typetagdata at /home/tim/Julia/pkg/CUDA/wip.jl:1 [inlined]
typetagdata at /home/tim/Julia/pkg/CUDA/wip.jl:1

These aren't isbits, but also do not require a selector array.
Instead, Julia handles the selector bit automatically.
@maleadt
maleadt merged commit d57c20d into master Jan 5, 2023
@maleadt
maleadt deleted the tb/union_structs branch January 5, 2023 16:02
@maleadt maleadt added bugfix This gets something working again. cuda array Stuff about CuArray. labels Jan 5, 2023
simonbyrne pushed a commit to simonbyrne/CUDA.jl that referenced this pull request Nov 13, 2023
These aren't isbits, but also do not require a selector array.
Instead, Julia handles the selector bit automatically.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bugfix This gets something working again. cuda array Stuff about CuArray.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant