From e696927e48b5433417a46a7377f2554d91755f89 Mon Sep 17 00:00:00 2001 From: Dmitry Stogov Date: Mon, 31 Oct 2016 19:51:19 +0300 Subject: [PATCH] Fixed reference-counter inference --- ext/opcache/Optimizer/zend_dfg.c | 3 +++ ext/opcache/Optimizer/zend_inference.c | 19 +++++++++++++++++++ ext/opcache/Optimizer/zend_ssa.c | 3 +++ 3 files changed, 25 insertions(+) diff --git a/ext/opcache/Optimizer/zend_dfg.c b/ext/opcache/Optimizer/zend_dfg.c index 693fcc8e51..6c52d6eb58 100644 --- a/ext/opcache/Optimizer/zend_dfg.c +++ b/ext/opcache/Optimizer/zend_dfg.c @@ -76,6 +76,9 @@ int zend_build_dfg(const zend_op_array *op_array, const zend_cfg *cfg, zend_dfg case ZEND_FE_RESET_R: case ZEND_SEND_VAR: case ZEND_CAST: + case ZEND_QM_ASSIGN: + case ZEND_JMP_SET: + case ZEND_COALESCE: if (build_flags & ZEND_SSA_RC_INFERENCE) { goto op1_def; } diff --git a/ext/opcache/Optimizer/zend_inference.c b/ext/opcache/Optimizer/zend_inference.c index 0635cc5119..1fff94ea19 100644 --- a/ext/opcache/Optimizer/zend_inference.c +++ b/ext/opcache/Optimizer/zend_inference.c @@ -1054,6 +1054,17 @@ int zend_inference_calc_range(const zend_op_array *op_array, zend_ssa *ssa, int case ZEND_QM_ASSIGN: case ZEND_JMP_SET: case ZEND_COALESCE: + if (ssa->ops[line].op1_def == var) { + if (ssa->ops[line].op1_def >= 0) { + if (OP1_HAS_RANGE()) { + tmp->underflow = OP1_RANGE_UNDERFLOW(); + tmp->min = OP1_MIN_RANGE(); + tmp->max = OP1_MAX_RANGE(); + tmp->overflow = OP1_RANGE_OVERFLOW(); + return 1; + } + } + } if (ssa->ops[line].result_def == var) { if (OP1_HAS_RANGE()) { tmp->min = OP1_MIN_RANGE(); @@ -2549,6 +2560,14 @@ static void zend_update_type_info(const zend_op_array *op_array, case ZEND_QM_ASSIGN: case ZEND_JMP_SET: case ZEND_COALESCE: + if (ssa_ops[i].op1_def >= 0) { + tmp = t1; + if ((t1 & (MAY_BE_RC1|MAY_BE_REF)) && (opline->op1_type == IS_CV)) { + tmp |= MAY_BE_RCN; + } + UPDATE_SSA_TYPE(tmp, ssa_ops[i].op1_def); + COPY_SSA_OBJ_TYPE(ssa_ops[i].op1_use, ssa_ops[i].op1_def); + } tmp = t1 & ~(MAY_BE_UNDEF|MAY_BE_REF); if (t1 & MAY_BE_UNDEF) { tmp |= MAY_BE_NULL; diff --git a/ext/opcache/Optimizer/zend_ssa.c b/ext/opcache/Optimizer/zend_ssa.c index a0a2df92de..537258394f 100644 --- a/ext/opcache/Optimizer/zend_ssa.c +++ b/ext/opcache/Optimizer/zend_ssa.c @@ -656,6 +656,9 @@ static int zend_ssa_rename(const zend_op_array *op_array, uint32_t build_flags, break; case ZEND_SEND_VAR: case ZEND_CAST: + case ZEND_QM_ASSIGN: + case ZEND_JMP_SET: + case ZEND_COALESCE: if ((build_flags & ZEND_SSA_RC_INFERENCE) && opline->op1_type == IS_CV) { ssa_ops[k].op1_def = ssa_vars_count; var[EX_VAR_TO_NUM(opline->op1.var)] = ssa_vars_count; -- 2.50.1