From 535a0553e815b93a46a5724a355db2b96521b48b Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 8 Nov 2021 20:54:17 +0300 Subject: [PATCH] Fixed incorrect reference counter inference --- ext/opcache/Optimizer/zend_inference.c | 2 +- ext/opcache/Optimizer/zend_ssa.c | 8 ++++++++ ext/opcache/tests/jit/copy_tmp_002.phpt | 15 +++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 ext/opcache/tests/jit/copy_tmp_002.phpt diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c index 9604536d5a5..10228196bbf 100644 --- a/ext/opcache/Optimizer/zend_inference.c +++ b/ext/opcache/Optimizer/zend_inference.c @@ -2505,7 +2505,7 @@ static zend_always_inline int _zend_update_type_info( } if (t1 & (MAY_BE_RC1|MAY_BE_RCN)) { tmp |= (t1 & (MAY_BE_RC1|MAY_BE_RCN)); - if (opline->op1_type == IS_CV) { + if (opline->opcode == ZEND_COPY_TMP || opline->op1_type == IS_CV) { tmp |= MAY_BE_RCN; } } diff --git a/ext/opcache/Optimizer/zend_ssa.c b/ext/opcache/Optimizer/zend_ssa.c index e56f0c78e0d..23b78222839 100644 --- a/ext/opcache/Optimizer/zend_ssa.c +++ b/ext/opcache/Optimizer/zend_ssa.c @@ -770,6 +770,14 @@ add_op1_def: //NEW_SSA_VAR(opline->op2.var) } break; + case ZEND_COPY_TMP: + if (build_flags & ZEND_SSA_RC_INFERENCE) { + ssa_ops[k].op1_def = ssa_vars_count; + var[EX_VAR_TO_NUM(opline->op1.var)] = ssa_vars_count; + ssa_vars_count++; + //NEW_SSA_VAR(opline->op1.var) + } + break; default: break; } diff --git a/ext/opcache/tests/jit/copy_tmp_002.phpt b/ext/opcache/tests/jit/copy_tmp_002.phpt new file mode 100644 index 00000000000..4b1cee2f627 --- /dev/null +++ b/ext/opcache/tests/jit/copy_tmp_002.phpt @@ -0,0 +1,15 @@ +--TEST-- +JIT COPY_TMP: 002 +--INI-- +opcache.enable=1 +opcache.enable_cli=1 +opcache.file_update_protection=0 +opcache.jit_buffer_size=1M +opcache.protect_memory=1 +--FILE-- + +DONE +--EXPECT-- +DONE \ No newline at end of file