You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When a generic function uses $new(T.pointee_type) and is instantiated with two or more different pointer types in the same program, every instantiation generates C code that allocates the same (last-seen) pointee type rather than the per-instantiation type. The result is silently wrong code: the returned pointer's static V type is correct but the heap object behind it is of a different type, leading to memory corruption, wrong values, or runtime errors.
Describe the bug
When a generic function uses
$new(T.pointee_type)and is instantiated with two or more different pointer types in the same program, every instantiation generates C code that allocates the same (last-seen) pointee type rather than the per-instantiation type. The result is silently wrong code: the returned pointer's static V type is correct but the heap object behind it is of a different type, leading to memory corruption, wrong values, or runtime errors.Introduced by 8b5f74e.
Reproduction Steps
Expected Behavior
Current Behavior
*int_ptrreads garbage. Inspecting the generated C withv -keepcshows themake_pointer[&int]instantiation allocates aFoo, not anint:Both
_T___ptr__intand_T___ptr__main__Fooinstantiations emitHEAP(main__Foo, ...). The "last seen" pointee type wins for all instantiations.This blocks refactoring
vlib/x/json2/decode.vto use$new(T.pointee_type)instead of the manualcreate_decoded_ptrhelper.Possible Solution
Resolve
T.pointee_typeper-instantiation in the C generator instead of caching/sharing across instantiations.V version
V 0.5.1 6dd9033.eb1d47b
Environment details
linux, Ubuntu 24.04 LTS, gcc 14.2.0, tcc 0.9.28rc
Note
You can use the 👍 reaction to increase the issue's priority for developers.
Please note that only the 👍 reaction to the issue itself counts as a vote.
Other reactions and those to comments will not be taken into account.