Skip to content

Commit f473132

Browse files
nikicMajkl578
authored andcommitted
Add SCCP support for ZEND_ARRAY_KEY_EXISTS
1 parent 6ce76d5 commit f473132

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

ext/opcache/Optimizer/sccp.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -695,6 +695,26 @@ static inline int ct_eval_in_array(zval *result, uint32_t extended_value, zval *
695695
return SUCCESS;
696696
}
697697

698+
static inline int ct_eval_array_key_exists(zval *result, zval *op1, zval *op2) {
699+
zval *value;
700+
701+
if (Z_TYPE_P(op2) != IS_ARRAY && !IS_PARTIAL_ARRAY(op2)) {
702+
return FAILURE;
703+
}
704+
if (Z_TYPE_P(op1) != IS_STRING && Z_TYPE_P(op1) != IS_LONG && Z_TYPE_P(op1) != IS_NULL) {
705+
return FAILURE;
706+
}
707+
if (fetch_array_elem(&value, op2, op1) == FAILURE) {
708+
return FAILURE;
709+
}
710+
if (IS_PARTIAL_ARRAY(op2) && (!value || IS_BOT(value))) {
711+
return FAILURE;
712+
}
713+
714+
ZVAL_BOOL(result, value != NULL);
715+
return SUCCESS;
716+
}
717+
698718
/* The functions chosen here are simple to implement and either likely to affect a branch,
699719
* or just happened to be commonly used with constant operands in WP (need to test other
700720
* applications as well, of course). */
@@ -1572,6 +1592,16 @@ static void sccp_visit_instr(scdf_ctx *scdf, zend_op *opline, zend_ssa_op *ssa_o
15721592
}
15731593
SET_RESULT_BOT(result);
15741594
break;
1595+
case ZEND_ARRAY_KEY_EXISTS:
1596+
SKIP_IF_TOP(op1);
1597+
SKIP_IF_TOP(op2);
1598+
if (ct_eval_array_key_exists(&zv, op1, op2) == SUCCESS) {
1599+
SET_RESULT(result, &zv);
1600+
zval_ptr_dtor_nogc(&zv);
1601+
break;
1602+
}
1603+
SET_RESULT_BOT(result);
1604+
break;
15751605
case ZEND_FETCH_DIM_R:
15761606
case ZEND_FETCH_DIM_IS:
15771607
case ZEND_FETCH_LIST_R:

0 commit comments

Comments
 (0)