Fix segfault when matching tuple elements against unions or interfaces via Any#5134
Open
SeanTAllen wants to merge 1 commit intomainfrom
Open
Fix segfault when matching tuple elements against unions or interfaces via Any#5134SeanTAllen wants to merge 1 commit intomainfrom
SeanTAllen wants to merge 1 commit intomainfrom
Conversation
…s via Any When pattern matching a boxed tuple (via Any val), unboxed numeric elements were loaded as pointers when the match pattern expected a union or interface type, causing a segfault. The fix adds a runtime type_id parity check in dynamic_capture_ptr and dynamic_value_ptr: odd type_id means the field is an object pointer (load directly), even means raw inline data that needs boxing into a heap object. The boxing helper allocates via pony_alloc, stores the descriptor, and memcpys the raw data at the correct alignment-aware offset. Also fixes make_field_offset to return the correct value offset for boxable numeric types — it was returning 0, which would break types like I128/U128 where alignment padding puts the value past the pointer-sized offset. Closes #4507
Member
Author
|
@nisanharamati please give this a test. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When pattern matching a boxed tuple (via
Any val), unboxed numeric elements were loaded as pointers when the match pattern expected a union or interface type. The raw byte value got interpreted as a memory address and the program segfaulted.The codegen for
dynamic_capture_ptranddynamic_value_ptrnow checks the runtime type_id to distinguish object pointers (odd type_id, load directly) from raw inline data (even type_id, box into a heap object first). The boxing helper allocates viapony_alloc, stores the descriptor, and memcpys the data at the correct alignment-aware offset. This uses the same type_id encoding thatgentrace.calready relies on.The fix also corrects
make_field_offsetto return the actual struct offset for boxable numeric types. It was returning 0 for all types withfield_count == 0, which would put the value at the wrong offset for types like I128/U128 where alignment padding pushes the value past the pointer-sized offset.Five regression tests cover: union-typed element, interface-typed element, the no-double-boxing scenario from PR #4787's regression, I128 alignment, and nested inline tuples.
Note: The
dynamic_value_ptrfix mirrorsdynamic_capture_ptrbut has no dedicated test. I think the pointer-type branch there is probably unreachable in practice since value patterns resolve to concreteeq()parameter types rather than unions or interfaces. The code is defensive.Closes #4507