Commit f4e69c34

f4e69c34cfdcMerged

Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 1 file · ~1 modified

Description

fix(codegen): attr_writer stmt/expr forms coerce int rhs to bigint slot

Both the expression-form obj.attr = v at line 20389 and the statement-form short-circuited attr_writer emit at line 28412 copied the raw rhs into a lv_p->iv_x = 10LL; shape. With promote mode widening the ivar slot to sp_Bigint *, the literal int rhs tripped -Wint-conversion.

Mirror the existing slot_t == "poly" boxing arm: when slot_t is bigint and the rhs is int, wrap through sp_bigint_new_int; reverse direction unboxes via sp_bigint_to_int.

Promote-mode test count: 476 pass / 54 fail / 88 error -> 480 pass / 54 fail / 84 error. Default raise mode unchanged at 618 / 0 / 0.

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

Details

Commit
f4e69c34cfdc
Parent
33c8219ac984

spinel_codegen.rbmodifiedView file

@@ -20386,6 +20386,23 @@
2038620386 boxed = box_value_to_poly(arg_t, tmp_w)
2038720387 return "({" + c_type(arg_t) + " " + tmp_w + " = " + arg0_w + "; " + rc + arrow + sanitize_ivar(bname) + " = " + boxed + "; " + tmp_w + ";})"
2038820388 end
20389+ # promote-mode-widened ivar: wrap an int rhs through
20390+ # sp_bigint_new_int. Mirror the bigint coerce branches at
20391+ # the other ivar-write sites (line 24924, etc.).
20392+ if slot_t == "bigint"
20393+ arg_t_bw = "int"
20394+ args_id_bw = @nd_arguments[nid]
20395+ if args_id_bw >= 0
20396+ arg_ids_bw = get_args(args_id_bw)
20397+ if arg_ids_bw.length > 0
20398+ arg_t_bw = infer_type(arg_ids_bw[0])
20399+ end
20400+ end
20401+ if arg_t_bw == "int"
20402+ @needs_bigint = 1
20403+ return "(" + rc + arrow + sanitize_ivar(bname) + " = sp_bigint_new_int(" + arg0_w + "))"
20404+ end
20405+ end
2038920406 return "(" + rc + arrow + sanitize_ivar(bname) + " = " + arg0_w + ")"
2039020407 end
2039120408 j = j + 1
@@ -28381,17 +28398,24 @@
2838128398 # expression-form attr_writer above.
2838228399 slot_t = cls_ivar_type(r_ci, "@" + bname)
2838328400 arg0_w = compile_arg0(nid)
28384- if slot_t == "poly"
28385- args_id_w = @nd_arguments[nid]
28386- arg_t = "int"
28387- if args_id_w >= 0
28388- arg_ids_w = get_args(args_id_w)
28389- if arg_ids_w.length > 0
28390- arg_t = infer_type(arg_ids_w[0])
28391- end
28401+ arg_t_aw = "int"
28402+ args_id_aw = @nd_arguments[nid]
28403+ if args_id_aw >= 0
28404+ arg_ids_aw = get_args(args_id_aw)
28405+ if arg_ids_aw.length > 0
28406+ arg_t_aw = infer_type(arg_ids_aw[0])
2839228407 end
28393- arg0_w = box_value_to_poly(arg_t, arg0_w)
2839428408 end
28409+ if slot_t == "poly"
28410+ arg0_w = box_value_to_poly(arg_t_aw, arg0_w)
28411+ elsif slot_t == "bigint" && arg_t_aw == "int"
28412+ # promote-mode-widened ivar: wrap an int rhs.
28413+ @needs_bigint = 1
28414+ arg0_w = "sp_bigint_new_int(" + arg0_w + ")"
28415+ elsif slot_t == "int" && arg_t_aw == "bigint"
28416+ @needs_bigint = 1
28417+ arg0_w = "sp_bigint_to_int((sp_Bigint *)" + arg0_w + ")"
28418+ end
2839528419 emit(" " + rc + arrow2 + sanitize_ivar(bname) + " = " + arg0_w + ";")
2839628420 return 1
2839728421 end