Commit 255307ce

255307cef2c6Merged

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

Description

fix(codegen): cast_away_volatile_arg skips coerced (non-bare-LV) args

cast_away_volatile_arg(arg_id, val) strips the volatile qualifier by casting the value to the LV's declared type. The intent is for raw lv_<name> reads -- when the value has been wrapped by compile_expr_for_expected_type (e.g. through a hash-variant conversion like sp_StrPolyHash_from_sym_poly_hash(lv_form_attrs)), the result no longer has the LV's declared type, and casting it to that type emits the wrong cast on top of the conversion -- producing (sp_SymPolyHash *)sp_StrPolyHash_from_sym_poly_hash(...) for #700's button_to → render_attrs call where lv_form_attrs is sym_poly and render_attrs takes str_poly.

Skip the cast when val differs from the bare lv_<arg_id_name> read -- the wrapping function already operates on the volatile LV correctly via implicit C arg-passing conversion, and the resulting value is non-volatile, so the cast is both wrong and unnecessary.

Test: test/volatile_strip_skips_coerced_arg.rb (needs @needs_setjmp armed via a sibling begin/rescue, plus LV-recv → cross-variant hash call). 448 -> 449 tests pass.

Refs #700

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

Details

Commit
255307cef2c6
Parent
2ba0b9be1b67

spinel_codegen.rbmodifiedView file

@@ -26540,6 +26540,19 @@
2654026540 if vt == "" || type_is_pointer(vt) != 1
2654126541 return val
2654226542 end
26543+ # Skip the cast when `val` isn't a bare `lv_<name>` read --
26544+ # compile_expr_for_expected_type may have wrapped the LV in a
26545+ # conversion call (e.g. `sp_StrPolyHash_from_sym_poly_hash(lv_form_attrs)`),
26546+ # producing a value whose actual type differs from the LV's
26547+ # declared type. Casting that to `(c_type(vt))` would emit the
26548+ # wrong cast (LV's old type) on a value of the new type --
26549+ # the #700 shape "(sp_SymPolyHash *)sp_StrPolyHash_from_sym_poly_hash(...)"
26550+ # symptom. The wrapping itself isn't volatile-sensitive (the
26551+ # conversion fn reads h->order[i] which is safe under longjmp),
26552+ # so dropping the cast here is correct.
26553+ if val != ("lv_" + @nd_name[arg_id])
26554+ return val
26555+ end
2654326556 "(" + c_type(vt) + ")" + val
2654426557 end
2654526558