From aa45df484903b1e24c348493cf1cda9cc56e44cd Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Tue, 24 Oct 2023 18:48:29 +0300 Subject: [PATCH] Fixed incorrect type inference --- Zend/Optimizer/zend_inference.c | 4 ++- ext/opcache/tests/jit/gh12482.phpt | 57 ++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 1 deletion(-) create mode 100644 ext/opcache/tests/jit/gh12482.phpt diff --git a/Zend/Optimizer/zend_inference.c b/Zend/Optimizer/zend_inference.c index 4cc9f70c27f..ea144bbb34c 100644 --- a/Zend/Optimizer/zend_inference.c +++ b/Zend/Optimizer/zend_inference.c @@ -3415,7 +3415,9 @@ static zend_always_inline int _zend_update_type_info( UPDATE_SSA_TYPE(tmp, ssa_op->result_def); break; case ZEND_FETCH_THIS: - UPDATE_SSA_OBJ_TYPE(op_array->scope, 1, ssa_op->result_def); + if (!(op_array->fn_flags & ZEND_ACC_TRAIT_CLONE)) { + UPDATE_SSA_OBJ_TYPE(op_array->scope, 1, ssa_op->result_def); + } UPDATE_SSA_TYPE(MAY_BE_RCN|MAY_BE_OBJECT, ssa_op->result_def); break; case ZEND_FETCH_OBJ_R: diff --git a/ext/opcache/tests/jit/gh12482.phpt b/ext/opcache/tests/jit/gh12482.phpt new file mode 100644 index 00000000000..021f7ce4526 --- /dev/null +++ b/ext/opcache/tests/jit/gh12482.phpt @@ -0,0 +1,57 @@ +--TEST-- +GH-12482: Invalid type inference +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.jit_hot_func=2 +--FILE-- +x = 42; + return $cloned; + } +} +class A { + use T; + public $a = 1; + public $b = 2; + public $c = 3; + public $x = 4; +} +class B { + use T; + public $x = 5; +} +$a = new A; +var_dump($a->foo()); +var_dump($a->foo()); +$b = new B; +var_dump($b->foo()); +?> +--EXPECT-- +object(A)#2 (4) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) + ["x"]=> + int(42) +} +object(A)#2 (4) { + ["a"]=> + int(1) + ["b"]=> + int(2) + ["c"]=> + int(3) + ["x"]=> + int(42) +} +object(B)#3 (1) { + ["x"]=> + int(42) +}