Commit e5d831ac

e5d831ac948dMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified

Description

codegen: lower a bitwise op whose bigint operand is a 64-bit mask literal

x & 0xFFFFFFFFFFFFFFFF regressed once integer literals wider than int64 were typed as bigints: the scalar bitwise-op codegen emitted mrb_int & sp_Bigint *, which is invalid C. The result slot is already inferred int, so coerce a TY_BIGINT operand with sp_bigint_to_int (low-64 bit pattern) -- the xorshift64 / 64-bit-mask idiom now compiles and matches CRuby.

Fixes #1513.

Default test 997 pass / 0 fail and optcarrot checksum 59662 unchanged.

Co-Authored-By: Claude Opus 4.8 [email protected]

Details

Commit
e5d831ac948d
Parent
bca81be8fa6b

src/codegen_call.cmodifiedView file

@@ -7587,6 +7587,12 @@
75877587 if (at0 == TY_POLY) {
75887588 buf_puts(b, "sp_poly_to_i("); emit_expr(c, argv[0], b); buf_puts(b, ")");
75897589 }
7590+ /* A literal wider than int64 (a 64-bit mask like 0xFFFFFFFFFFFFFFFF) is
7591+ typed as a bigint; the result slot is int, so take its low-64 bit pattern
7592+ (sp_bigint_to_int truncates) -- this is the xorshift/64-bit-mask idiom. */
7593+ else if (at0 == TY_BIGINT) {
7594+ buf_puts(b, "sp_bigint_to_int("); emit_expr(c, argv[0], b); buf_puts(b, ")");
7595+ }
75907596 else emit_expr(c, argv[0], b);
75917597 buf_puts(b, ")");
75927598 return;