Skip to content

Commit ab198f9

Browse files
gbaraldigiordanoSeelengrab
authored andcommitted
Fix layout flags for types that have oddly sized primitive type fields (#58435)
This is caused because for LLVMs sake we have to say that the oddly typed field is smaller than it actually is. (I wonder if we could represent it as an iN field in a struct and have it work but the result would be the same for now) Fix #58434, fix #49318, close #49362. --------- Co-authored-by: Mosè Giordano <[email protected]> Co-authored-by: Sukera <[email protected]> (cherry picked from commit 1b0b028)
1 parent 1d4065e commit ab198f9

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

src/datatype.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -702,13 +702,19 @@ void jl_compute_field_offsets(jl_datatype_t *st)
702702
// Should never happen
703703
throw_ovf(should_malloc, desc, st, fsz);
704704
desc[i].isptr = 0;
705+
705706
if (jl_is_uniontype(fld)) {
706707
fsz += 1; // selector byte
707708
zeroinit = 1;
708709
// TODO: Some unions could be bits comparable.
709710
isbitsegal = 0;
710711
}
711712
else {
713+
if (fsz > jl_datatype_size(fld)) {
714+
// We have to pad the size to integer size class, but it means this has some padding
715+
isbitsegal = 0;
716+
haspadding = 1;
717+
}
712718
uint32_t fld_npointers = ((jl_datatype_t*)fld)->layout->npointers;
713719
if (((jl_datatype_t*)fld)->layout->flags.haspadding)
714720
haspadding = 1;

test/core.jl

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8518,3 +8518,9 @@ module GlobalBindingMulti
85188518
using .M.C
85198519
end
85208520
@test GlobalBindingMulti.S === GlobalBindingMulti.M.C.S
8521+
8522+
#58434 bitsegal comparison of oddly sized fields
8523+
primitive type ByteString58434 (18 * 8) end
8524+
8525+
@test Base.datatype_isbitsegal(Tuple{ByteString58434}) == false
8526+
@test Base.datatype_haspadding(Tuple{ByteString58434}) == (length(Base.padding(Tuple{ByteString58434})) > 0)

0 commit comments

Comments
 (0)