Commit 80bc7206

80bc72064363Merged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): bigint.abs/succ/pred surface as bigint to callers (#746)

In promote mode, lv_x.abs (where lv_x is bigint) returned the correct sp_Bigint* expression in compile_call's bigint arm, but expr_emit_is_bigint returned 0 -- so puts/printf/string format sites wrapped it with sp_bigint_new_int treating the pointer as int. Output was garbage (the pointer cast to long long).

INT64_MIN.abs is the canonical trigger: x = -9223372036854775808; puts x.abs printed garbage like 99606556542496 instead of 9223372036854775808.

Add a pre-check in expr_emit_is_bigint for the four bigint- preserving unary methods (abs / succ / pred / next): if the receiver is bigint, the result is too.

Closes #746

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

Details

Commit
80bc72064363
Parent
8507ff7c7e88

spinel_codegen.rbmodifiedView file

@@ -17239,6 +17239,18 @@
1723917239 end
1724017240 end
1724117241 end
17242+ # Issue #746: `bigint.abs` / `bigint.succ` / `bigint.pred` /
17243+ # `bigint.divmod` return bigint when the recv is bigint. Without
17244+ # this arm, expr_emit_is_bigint returns 0 and the caller wraps
17245+ # the result with sp_bigint_new_int (treating the pointer as
17246+ # int) -- garbage output.
17247+ if mn_eb == "abs" || mn_eb == "succ" || mn_eb == "pred" || mn_eb == "next"
17248+ rcv_abs = @nd_receiver[nid]
17249+ if rcv_abs >= 0 && (base_type(infer_type(rcv_abs)) == "bigint" ||
17250+ expr_emit_is_bigint(rcv_abs) == 1)
17251+ return 1
17252+ end
17253+ end
1724217254 if mn_eb != "+" && mn_eb != "-" && mn_eb != "*" && mn_eb != "/" && mn_eb != "%" && mn_eb != "**" &&
1724317255 mn_eb != "&" && mn_eb != "|" && mn_eb != "^" && mn_eb != "<<" && mn_eb != ">>" &&
1724417256 mn_eb != "~" && mn_eb != "-@"