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
end end end # Issue #746: `bigint.abs` / `bigint.succ` / `bigint.pred` / # `bigint.divmod` return bigint when the recv is bigint. Without # this arm, expr_emit_is_bigint returns 0 and the caller wraps # the result with sp_bigint_new_int (treating the pointer as # int) -- garbage output. if mn_eb == "abs" || mn_eb == "succ" || mn_eb == "pred" || mn_eb == "next" rcv_abs = @nd_receiver[nid] if rcv_abs >= 0 && (base_type(infer_type(rcv_abs)) == "bigint" || expr_emit_is_bigint(rcv_abs) == 1) return 1 end end if mn_eb != "+" && mn_eb != "-" && mn_eb != "*" && mn_eb != "/" && mn_eb != "%" && mn_eb != "**" && mn_eb != "&" && mn_eb != "|" && mn_eb != "^" && mn_eb != "<<" && mn_eb != ">>" && mn_eb != "~" && mn_eb != "-@"