Fix segfault in Tracing JIT with object reference #20948
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.
Fixes #20818
Problem
When
FE_RESET_RW(foreach by-reference) executes, it converts the CV to azend_referencebefore checking if the array/object is empty. However, when the JIT creates exit points forFE_RESET_RWinzend_jit_trace_handler(), it was not updating the stack type for op1 to reflect this change.This caused side traces compiled from these exit points to have incorrect type information. The side trace CV cleanup code would see
IS_OBJECTand generate a direct call tozend_objects_store_del(), but the actual value was azend_reference*, causing a segfault.Solution
Add
ZEND_FE_RESET_RWto the list of opcodes that temporarily set their op1 stack type toIS_UNKNOWNbefore creating exit points. This follows the same pattern already used forZEND_BIND_INIT_STATIC_OR_JMPandZEND_FE_FETCH_R/RW.When
IS_UNKNOWN, the JIT falls back to SSA type info which correctly includesMAY_BE_REFforFE_RESET_RWop1_def (seezend_inference.c:3483-3484).Changes
ext/opcache/jit/zend_jit_ir.c: AddZEND_FE_RESET_RWcase to both switch blocks inzend_jit_trace_handler()that handle stack type updates around exit point creationext/opcache/tests/jit/gh20818.phpt: Test case from the issueTesting
opcache.protect_memory=1