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
if vt == "" || type_is_pointer(vt) != 1 return val end # Skip the cast when `val` isn't a bare `lv_<name>` read -- # compile_expr_for_expected_type may have wrapped the LV in a # conversion call (e.g. `sp_StrPolyHash_from_sym_poly_hash(lv_form_attrs)`), # producing a value whose actual type differs from the LV's # declared type. Casting that to `(c_type(vt))` would emit the # wrong cast (LV's old type) on a value of the new type -- # the #700 shape "(sp_SymPolyHash *)sp_StrPolyHash_from_sym_poly_hash(...)" # symptom. The wrapping itself isn't volatile-sensitive (the # conversion fn reads h->order[i] which is safe under longjmp), # so dropping the cast here is correct. if val != ("lv_" + @nd_name[arg_id]) return val end "(" + c_type(vt) + ")" + val endtest/volatile_strip_skips_coerced_arg.expectedaddedView file
Loading diff…
test/volatile_strip_skips_coerced_arg.rbaddedView file
Loading diff…