Commit 15b216b6
15b216b66030Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified
Description
codegen: fix min/max comparator emit at -O0 — shadow lv_ in block scope
CI red on master after a5b63f6 — sort_min_max_block_comparator failed to compile at -O0 with int↔string type mismatch on lv_a/lv_b. The emit was relying on emit_iter_open's bare `lv_a = sp_StrArray_get(...)` assignment, but the function-scope lv_a slot was typed as mrb_int by other call sites of the same block param name; -O3 elided the dead type-mismatched read, masking the bug locally.
Inline the for-loop emit with a fresh ` lv_ = sp__get(...)` declaration so the loop body shadows the outer slot. -O0 now compiles cleanly; output unchanged.
Refs #980
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 15b216b66030
- Parent
- 4af1b4df8b8f
spinel_codegen.rbmodifiedView file
# best and update when the comparator says the new element wins. # 1-param block is the legacy min_by-style scoring function. if bp2 != "" # Declare lv_<bp1> / lv_<bp2> fresh inside the loop body so we # shadow any function-scope slot (the same `a` / `b` names may # have been widened to a different type by other call sites). # Without the shadow, emit_iter_open's bare assignment hits a # type mismatch at -O0 (the optimizer elides at -O3, masking # the bug from local testing). emit(" " + c_type(elem_type) + " " + tmp_res + " = " + c_default_val(elem_type) + ";") emit_iter_open(rc, recv_type, "lv_" + bp1, tmp_i) pfx_mm = array_c_prefix(recv_type) emit(" for (mrb_int " + tmp_i + " = 0; " + tmp_i + " < sp_" + pfx_mm + "_length(" + rc + "); " + tmp_i + "++) {") emit(" " + c_type(elem_type) + " lv_" + bp1 + " = sp_" + pfx_mm + "_get(" + rc + ", " + tmp_i + ");") push_scope declare_var(bp1, elem_type) declare_var(bp2, elem_type)