From dc86ed3287d9da475b7112ccc03c07bd7931278d Mon Sep 17 00:00:00 2001 From: Keno Fischer Date: Thu, 11 Aug 2022 19:51:57 +0000 Subject: [PATCH] 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. --- src/datatype.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/datatype.c b/src/datatype.c index 593a2ededd169a..54fab4f17f28b2 100644 --- a/src/datatype.c +++ b/src/datatype.c @@ -282,7 +282,7 @@ static unsigned union_isinlinable(jl_value_t *ty, int pointerfree, size_t *nbyte size_t sz = jl_datatype_size(ty); size_t al = jl_datatype_align(ty); // primitive types in struct slots need their sizes aligned. issue #37974 - if (asfield && jl_is_primitivetype(ty)) + if (asfield) sz = LLT_ALIGN(sz, al); if (*nbytes < sz) *nbytes = sz; @@ -465,6 +465,8 @@ void jl_compute_field_offsets(jl_datatype_t *st) uint32_t fld_npointers = ((jl_datatype_t*)fld)->layout->npointers; if (((jl_datatype_t*)fld)->layout->haspadding) haspadding = 1; + if (fsz < jl_datatype_size(fld)) + haspadding = 1; if (i >= nfields - st->name->n_uninitialized && fld_npointers && fld_npointers * sizeof(void*) != fsz) { // field may be undef (may be uninitialized and contains pointer), @@ -525,9 +527,7 @@ void jl_compute_field_offsets(jl_datatype_t *st) if (al > alignm) alignm = al; } - st->size = LLT_ALIGN(sz, alignm); - if (st->size > sz) - haspadding = 1; + st->size = sz; if (should_malloc && npointers) pointers = (uint32_t*)malloc_s(npointers * sizeof(uint32_t)); else @@ -1470,6 +1470,7 @@ static inline void memassign_safe(int hasptr, jl_value_t *parent, char *dst, con memmove_refs((void**)dst, (void**)src, nptr); jl_gc_multi_wb(parent, src); src = (jl_value_t*)((char*)src + nptr * sizeof(void*)); + dst += nptr * sizeof(void*); nb -= nptr * sizeof(void*); } else {