error.h, array.h: support MRB_NAN_BOXING on 32-bit

On 32-bit platforms whose ABI gives 8-byte members 8-byte alignment
(xtensa, ARM, MIPS, PowerPC, ...), MRB_NAN_BOXING failed to build with
"RVALUE size must be within 5 words" because two structs got padded
past the budget:

- struct RBreak: had an existing MRB_USE_RBREAK_VALUE_UNION workaround
  that stores the value as uint32_t[] to avoid forcing 8-byte alignment
  on the struct, but the gate only enabled it for MRB_NO_BOXING.
  Extend to NAN_BOXING + 32-bit, with a NAN_BOXING-specific get/set
  (no separate tt to stash since nan-boxing encodes type in the bits).

- struct RArray: MRB_ARY_NO_EMBED was similarly gated to NO_BOXING;
  embedded mrb_value[] forces 8-byte alignment of the inner union and
  pads the heap-form layout. Extend the gate to NAN_BOXING + 32-bit.

Both gates now name the structural property (32-bit + mrb_value has an
8-byte aligned member) rather than enumerating boxing modes, so adding
new boxing modes won't silently miss this class of bug again.

i386's System V ABI gives uint64_t only 4-byte alignment, hiding the
problem on x86 -m32; -malign-double simulates the strict-alignment ABI
that exhibits the failure, and is what was used to verify the fix.

Closes #6815, reported by dearblue.

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Yukihiro "Matz" Matsumoto
2026-05-06 07:56:25 +09:00
parent 90ead4bdaf
commit 3cc60d31c6
2 changed files with 38 additions and 7 deletions
+11 -1
View File
@@ -20,7 +20,17 @@ typedef struct mrb_shared_array {
mrb_value *ptr;
} mrb_shared_array;
#if defined(MRB_32BIT) && defined(MRB_NO_BOXING) && (!defined(MRB_USE_FLOAT32) || defined(MRB_INT64)) && !defined(MRB_ARY_NO_EMBED)
/* On 32-bit platforms whose ABI gives 8-byte members 8-byte alignment
(ARM, MIPS, xtensa, ...), an embedded mrb_value array forces 8-byte
alignment of the inner union, padding the heap-form layout and
inflating struct size past the 5-word RVALUE limit. Disable embedding
whenever mrb_value contains an 8-byte aligned member: nan-boxing
(uint64_t), or no-boxing with int64_t/double inside the union. */
#if defined(MRB_32BIT) && \
(defined(MRB_NAN_BOXING) || \
(defined(MRB_NO_BOXING) && \
(!defined(MRB_USE_FLOAT32) || defined(MRB_INT64)))) && \
!defined(MRB_ARY_NO_EMBED)
# define MRB_ARY_NO_EMBED
#endif