-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix GH-17747: Exception on reading property in register-based FETCH_OBJ_R breaks JIT #17749
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1965,7 +1965,12 @@ static zval* ZEND_FASTCALL zend_jit_fetch_obj_r_slow_ex(zend_object *zobj) | |
void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS); | ||
|
||
retval = zobj->handlers->read_property(zobj, name, BP_VAR_R, cache_slot, result); | ||
if (retval == result && UNEXPECTED(Z_ISREF_P(retval))) { | ||
if (retval != result) { | ||
/* On exception, we may free the result in the ZEND_HANDLE_EXCEPTION VM handler | ||
* so we need to initialize the result. | ||
* We don't need to copy because we use the return value directly as a register. */ | ||
ZVAL_UNDEF(result); | ||
} else if (UNEXPECTED(Z_ISREF_P(retval))) { | ||
zend_unwrap_reference(retval); | ||
} | ||
return retval; | ||
|
@@ -2017,7 +2022,12 @@ static zval* ZEND_FASTCALL zend_jit_fetch_obj_is_slow_ex(zend_object *zobj) | |
void **cache_slot = CACHE_ADDR(opline->extended_value & ~ZEND_FETCH_OBJ_FLAGS); | ||
|
||
retval = zobj->handlers->read_property(zobj, name, BP_VAR_IS, cache_slot, result); | ||
if (retval == result && UNEXPECTED(Z_ISREF_P(retval))) { | ||
if (retval != result) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I could also check for |
||
/* On exception, we may free the result in the ZEND_HANDLE_EXCEPTION VM handler | ||
* so we need to initialize the result. | ||
* We don't need to copy because we use the return value directly as a register. */ | ||
ZVAL_UNDEF(result); | ||
} else if (UNEXPECTED(Z_ISREF_P(retval))) { | ||
zend_unwrap_reference(retval); | ||
} | ||
return retval; | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
--TEST-- | ||
GH-17747 (Exception on reading property in register-based FETCH_OBJ_R breaks JIT) | ||
--EXTENSIONS-- | ||
opcache | ||
--INI-- | ||
opcache.jit=function | ||
--FILE-- | ||
<?php | ||
class C { | ||
public int $a; | ||
public function test() { | ||
var_dump($this->a); | ||
} | ||
} | ||
$test = new C; | ||
$test->test(); | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Uncaught Error: Typed property C::$a must not be accessed before initialization in %s:%d | ||
Stack trace: | ||
#0 %s(%d): C->test() | ||
#1 {main} | ||
thrown in %s on line %d |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This may cause problems for case without exceptions, because the type in memory is changed and it may be inconsistent with inferred type.
I think, it's better to use
zend_jit_check_exception_undef_result()
instead ofzend_jit_check_exception()
whenZ_MODE(res_addr) == IS_REG
.Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought this didn't matter as the value isn't actually used (the bytes are uninitialized anyway in this case).
I didn't know this helper existed, I should've looked better. This idea is actually something I briefly thought of doing myself but didn't know it existed already. Thanks for pointing out.