Skip to content

Commit 1b0b028

Browse files
gbaraldigiordanoSeelengrab
authored
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]>
1 parent 18d5ccd commit 1b0b028

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
@@ -8534,3 +8534,9 @@ module GlobalBindingMulti
85348534
using .M.C
85358535
end
85368536
@test GlobalBindingMulti.S === GlobalBindingMulti.M.C.S
8537+
8538+
#58434 bitsegal comparison of oddly sized fields
8539+
primitive type ByteString58434 (18 * 8) end
8540+
8541+
@test Base.datatype_isbitsegal(Tuple{ByteString58434}) == false
8542+
@test Base.datatype_haspadding(Tuple{ByteString58434}) == (length(Base.padding(Tuple{ByteString58434})) > 0)

0 commit comments

Comments
 (0)