@@ -235,20 +235,23 @@ STATIC_INLINE void jl_maybe_allocate_singleton_instance(jl_datatype_t *st)
235
235
}
236
236
}
237
237
238
- static unsigned union_isinlinable (jl_value_t * ty , int pointerfree , size_t * nbytes , size_t * align ) JL_NOTSAFEPOINT
238
+ static unsigned union_isinlinable (jl_value_t * ty , int pointerfree , size_t * nbytes , size_t * align , int asfield ) JL_NOTSAFEPOINT
239
239
{
240
240
if (jl_is_uniontype (ty )) {
241
- unsigned na = union_isinlinable (((jl_uniontype_t * )ty )-> a , 1 , nbytes , align );
241
+ unsigned na = union_isinlinable (((jl_uniontype_t * )ty )-> a , 1 , nbytes , align , asfield );
242
242
if (na == 0 )
243
243
return 0 ;
244
- unsigned nb = union_isinlinable (((jl_uniontype_t * )ty )-> b , 1 , nbytes , align );
244
+ unsigned nb = union_isinlinable (((jl_uniontype_t * )ty )-> b , 1 , nbytes , align , asfield );
245
245
if (nb == 0 )
246
246
return 0 ;
247
247
return na + nb ;
248
248
}
249
249
if (jl_is_datatype (ty ) && jl_datatype_isinlinealloc (ty ) && (!pointerfree || ((jl_datatype_t * )ty )-> layout -> npointers == 0 )) {
250
250
size_t sz = jl_datatype_size (ty );
251
251
size_t al = jl_datatype_align (ty );
252
+ // primitive types in struct slots need their sizes aligned. issue #37974
253
+ if (asfield && jl_is_primitivetype (ty ))
254
+ sz = LLT_ALIGN (sz , al );
252
255
if (* nbytes < sz )
253
256
* nbytes = sz ;
254
257
if (* align < al )
@@ -258,9 +261,15 @@ static unsigned union_isinlinable(jl_value_t *ty, int pointerfree, size_t *nbyte
258
261
return 0 ;
259
262
}
260
263
264
+ int jl_uniontype_size (jl_value_t * ty , size_t * sz ) JL_NOTSAFEPOINT
265
+ {
266
+ size_t al = 0 ;
267
+ return union_isinlinable (ty , 0 , sz , & al , 0 ) != 0 ;
268
+ }
269
+
261
270
JL_DLLEXPORT int jl_islayout_inline (jl_value_t * eltype , size_t * fsz , size_t * al ) JL_NOTSAFEPOINT
262
271
{
263
- unsigned countbits = union_isinlinable (eltype , 0 , fsz , al );
272
+ unsigned countbits = union_isinlinable (eltype , 0 , fsz , al , 1 );
264
273
return (countbits > 0 && countbits < 127 ) ? countbits : 0 ;
265
274
}
266
275
0 commit comments