Commit ad76ddb1
ad76ddb15068Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
fix(codegen): puts on stale-int expression that emits bigint
Details
- Commit
- ad76ddb15068
- Parent
- 76b774cdbbb4
spinel_codegen.rbmodifiedView file
@@ -32359,7 +32359,22 @@
3235932359
end3236032360
3236132361
# Emit the puts-equivalent for a single arg (extracted for reuse from p).32362+
# Promote-mode stale-int: an attr_reader / method call returning32363+
# sp_Bigint * may infer as "int" because the @cls_meth_returns32364+
# entry was promoted after annotate_all_node_types cached the32365+
# int. compile_puts and compile_puts_single both run into this:32366+
# `printf("%lld", (long long)<sp_Bigint*>)` casts a pointer to32367+
# long long and prints the address. Detect via the unified emit32368+
# walker and route through the bigint puts arm instead.32369+
def upgrade_at_for_emit(aid, at)32370+
if at == "int" && aid >= 0 && expr_emit_is_bigint(aid) == 132371+
return "bigint"32372+
end32373+
at32374+
end32375+
3236232376
def compile_puts_single(aid, at, val)32377+
at = upgrade_at_for_emit(aid, at)3236332378
if at == "poly"3236432379
@needs_rb_value = 13236532380
emit(" sp_poly_puts(" + val + ");")@@ -32406,7 +32421,7 @@
3240632421
k = 03240732422
while k < arg_ids.length3240832423
aid = arg_ids[k]32409-
at = infer_type(aid)32424+
at = upgrade_at_for_emit(aid, infer_type(aid))3241032425
# Issue #640: `puts cond ? :sym : int` ternary's unify_return_type3241132426
# picks one arm's type (e.g. "symbol") and the other arm's emit3241232427
# gets dispatched through the wrong puts variant — `sp_sym_to_s