Skip to content

Commit

Permalink
Make jl_datatype_size reflect non-padded field size
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
Keno committed Aug 11, 2022
1 parent 61f58be commit dc86ed3
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions src/datatype.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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),
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit dc86ed3

Please sign in to comment.