diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2019-10-25 11:25:49 +0200 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2019-10-25 11:25:49 +0200 |
commit | 711e2a1216b4a2c68d52752906ca1f0e51832e01 (patch) | |
tree | bf30197c2ed44f3aee4fe27496d4ff9e76d003ab /ext/opcache | |
parent | c858d17f06179aa25f6e8aa06965313fd519d8e9 (diff) | |
parent | f07565b0ebdfc5b8210bbf58d994ebd319014e67 (diff) | |
download | php-git-711e2a1216b4a2c68d52752906ca1f0e51832e01.tar.gz |
Merge branch 'PHP-7.4'
* PHP-7.4:
Check class linking in VERIFY_RETURN_TYPE optimization
Simplify travis setup scripts
Diffstat (limited to 'ext/opcache')
-rw-r--r-- | ext/opcache/Optimizer/dfa_pass.c | 13 | ||||
-rw-r--r-- | ext/opcache/tests/verify_return_instanceof.phpt | 19 |
2 files changed, 31 insertions, 1 deletions
diff --git a/ext/opcache/Optimizer/dfa_pass.c b/ext/opcache/Optimizer/dfa_pass.c index d753c54a00..d69f862019 100644 --- a/ext/opcache/Optimizer/dfa_pass.c +++ b/ext/opcache/Optimizer/dfa_pass.c @@ -278,6 +278,17 @@ static void zend_ssa_remove_nops(zend_op_array *op_array, zend_ssa *ssa, zend_op free_alloca(shiftlist, use_heap); } +static zend_bool safe_instanceof(zend_class_entry *ce1, zend_class_entry *ce2) { + if (ce1 == ce2) { + return 1; + } + if (!(ce1->ce_flags & ZEND_ACC_LINKED)) { + /* This case could be generalized, similarly to unlinked_instanceof */ + return 0; + } + return instanceof_function(ce1, ce2); +} + static inline zend_bool can_elide_return_type_check( zend_op_array *op_array, zend_ssa *ssa, zend_ssa_op *ssa_op) { zend_arg_info *info = &op_array->arg_info[-1]; @@ -302,7 +313,7 @@ static inline zend_bool can_elide_return_type_check( } if (ZEND_TYPE_IS_CLASS(info->type)) { - if (!use_info->ce || !def_info->ce || !instanceof_function(use_info->ce, def_info->ce)) { + if (!use_info->ce || !def_info->ce || !safe_instanceof(use_info->ce, def_info->ce)) { return 0; } } diff --git a/ext/opcache/tests/verify_return_instanceof.phpt b/ext/opcache/tests/verify_return_instanceof.phpt new file mode 100644 index 0000000000..14323d533b --- /dev/null +++ b/ext/opcache/tests/verify_return_instanceof.phpt @@ -0,0 +1,19 @@ +--TEST-- +Instanceof checks in VERIFY_RETURN_TYPE optimization may deal with unlinked classes +--FILE-- +<?php +interface foo { } + +interface biz {} + +class qux implements foo { + public function bar(): biz { + $x = $this; + return $x; + } +} + +?> +===DONE=== +--EXPECT-- +===DONE=== |