Commit 39a30d36
39a30d368438Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 5 months ago · 3 files · +2 added · ~1 modified
Description
codegen: pad proc-call args + recognise .inspect cache-miss path
Two related bugs in Proc.new { |a, b| ... }.call(1):
-
compile_proc_call_args built the C99 compound literal
(mrb_int[]){1}. The proc body readargs[1], which lay past the stack-local literal — pointer-sized garbage. Pad to 16 zero slots so missing args read as 0 (matches sp_proc_call's noargs path which already uses a 16-element zero buffer). -
Codegen's infer_type cache-miss fallback recognised
.to_sbut not.inspect, so a proc body's"#{a.inspect}"got typed int by the default arm. The string-interp dispatcher then picked%lldand cast the string pointer to long long — printing a decimal address instead of the value.
The user-visible result for unfilled params is now 0 (matches the
existing #997 pattern) rather than the prior pointer-garbage; the
int→int? widening for true nil parity is the same deferred cascade
as #801 Phase 4.
Fixes #976
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 39a30d368438
- Parent
- 5599c98e9229
spinel_codegen.rbmodifiedView file
if cmp_mname == "to_s" return "string" end # `.inspect` returns string for every recv type. Without this # arm a proc/lambda body's `"#{a.inspect}"` got typed int by # the fallback, the interp dispatcher picked %lld, and the # string pointer printed as a decimal address. if cmp_mname == "inspect" return "string" end # `lv.call(...)` / `lv.()` on a lambda local — recover the # lambda's recorded return type from @lambda_var_ret_*. # walk_and_cache skips lambda bodies, so the call itself isn't def compile_proc_call_args(nid) args_id = @nd_arguments[nid] if args_id < 0 return "0" return "0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0" end arg_ids = get_args(args_id) if arg_ids.length == 0 return "0" end result = "" k = 0 while k < arg_ids.length end k = k + 1 end # Pad the compound literal to 16 zero slots so a proc body that # reads `args[i]` past the caller-supplied arity sees 0 instead # of past-the-end stack garbage. Matches sp_proc_call's noargs # fast-path which already uses a 16-element zero-init buffer. while k < 16 if k > 0 result = result + ", " end result = result + "0" k = k + 1 end result endtest/i976.rbaddedView file
Loading diff…
test/i976.rb.expectedaddedView file
Loading diff…