Commit 85e22fcb
85e22fcba902Merged
Yukihiro "Matz" Matsumoto <[email protected]> · 6 months ago · 3 files · +2 added · ~1 modified
Description
fix(analyze): empty Array literal pushed with :ptr promotes to ptr_ptr_array
arr = []; arr.push(<:ptr value>) left arr typed as int_array
(the empty literal's default), so sp_IntArray_push(arr, <void *>)
warned -Wint-conversion and silently round-tripped FFI pointers
through mrb_int. Companion shape to #492 (which covered the
[ptr, ptr, ...] literal case at construction time).
- analyze: empty_array_promotion_for gets a "ptr" -> "ptr_ptr_array"
arm. The scan_locals push handler that walks local LVs also
picks up the new element type and widens
arr's slot from int_array to ptr_ptr_array on the first :ptr push.
The promoted array compiles through the existing is_ptr_array_type codegen path (sp_PtrArray_new_noscan for raw ptr elems).
Tests: default 459/0/0, promote 459/0/0, optcarrot checksum 59662.
Closes #688
Co-Authored-By: Claude Opus 4.7 [email protected]
Details
- Commit
- 85e22fcba902
- Parent
- b54d5d5020f3
spinel_analyze.rbmodifiedView file
@@ -16141,6 +16141,12 @@
1614116141
@needs_rb_value = 11614216142
return "poly_array"1614316143
end16144+
if elem_acc[0] == "ptr"16145+
# Raw `:ptr` (FFI handles, dlopen returns, ...) elements: use the16146+
# noscan PtrArray so the collector treats the slots as opaque16147+
# word-sized values without walking element headers. Issue #688.16148+
return "ptr_ptr_array"16149+
end1614416150
if is_obj_type(elem_acc[0]) == 11614516151
# Homogeneous obj array — use a typed `<obj>_ptr_array` so reads1614616152
# return a typed pointer (no sp_RbVal unbox needed at the call@@ -25608,6 +25614,22 @@
2560825614
end2560925615
ki = ki + 12561025616
end25617+
elsif arg_type == "ptr"25618+
# Raw :ptr (FFI handles, dlopen returns, ...). The empty25619+
# `[]` default of int_array can't hold opaque pointer-sized25620+
# values without -Wint-conversion; promote to the noscan25621+
# ptr_ptr_array so reads / pushes carry the void *. Issue25622+
# #688.25623+
@needs_gc = 125624+
ki = 025625+
while ki < names.length25626+
if names[ki] == arr_name25627+
if types[ki] == "int_array"25628+
types[ki] = "ptr_ptr_array"25629+
end25630+
end25631+
ki = ki + 125632+
end2561125633
elsif is_hash_type(arg_type) == 1 || is_array_type(arg_type) == 1 || is_ptr_array_type(arg_type) == 12561225634
# Hash or typed-array element: spinel has no2561325635
# <hash>_ptr_array / <array>_ptr_array_ptr_array slot,test/empty_array_push_ptr.rbaddedView file
Loading diff…
test/empty_array_push_ptr.rb.expectedaddedView file
Loading diff…