Skip to content

Commit dc86ed3

Browse files
committed
Make jl_datatype_size reflect non-padded field size
Padding is then added when creating the struct layout, but otherwise the memory layout should be unchanged. This is an alternative to the proposal in #46260. LLVM size and julia size should now be aligned.
1 parent 61f58be commit dc86ed3

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

src/datatype.c

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ static unsigned union_isinlinable(jl_value_t *ty, int pointerfree, size_t *nbyte
282282
size_t sz = jl_datatype_size(ty);
283283
size_t al = jl_datatype_align(ty);
284284
// primitive types in struct slots need their sizes aligned. issue #37974
285-
if (asfield && jl_is_primitivetype(ty))
285+
if (asfield)
286286
sz = LLT_ALIGN(sz, al);
287287
if (*nbytes < sz)
288288
*nbytes = sz;
@@ -465,6 +465,8 @@ void jl_compute_field_offsets(jl_datatype_t *st)
465465
uint32_t fld_npointers = ((jl_datatype_t*)fld)->layout->npointers;
466466
if (((jl_datatype_t*)fld)->layout->haspadding)
467467
haspadding = 1;
468+
if (fsz < jl_datatype_size(fld))
469+
haspadding = 1;
468470
if (i >= nfields - st->name->n_uninitialized && fld_npointers &&
469471
fld_npointers * sizeof(void*) != fsz) {
470472
// field may be undef (may be uninitialized and contains pointer),
@@ -525,9 +527,7 @@ void jl_compute_field_offsets(jl_datatype_t *st)
525527
if (al > alignm)
526528
alignm = al;
527529
}
528-
st->size = LLT_ALIGN(sz, alignm);
529-
if (st->size > sz)
530-
haspadding = 1;
530+
st->size = sz;
531531
if (should_malloc && npointers)
532532
pointers = (uint32_t*)malloc_s(npointers * sizeof(uint32_t));
533533
else
@@ -1470,6 +1470,7 @@ static inline void memassign_safe(int hasptr, jl_value_t *parent, char *dst, con
14701470
memmove_refs((void**)dst, (void**)src, nptr);
14711471
jl_gc_multi_wb(parent, src);
14721472
src = (jl_value_t*)((char*)src + nptr * sizeof(void*));
1473+
dst += nptr * sizeof(void*);
14731474
nb -= nptr * sizeof(void*);
14741475
}
14751476
else {

0 commit comments

Comments
 (0)