1
0
mirror of https://github.com/php/php-src.git synced 2026-04-26 17:38:14 +02:00

Add SCCP support for ZEND_ARRAY_KEY_EXISTS

This commit is contained in:
Nikita Popov
2018-08-21 08:56:17 +02:00
committed by Dmitry Stogov
parent f5044a12dd
commit 0bbfebb6d9
+30
View File
@@ -695,6 +695,26 @@ static inline int ct_eval_in_array(zval *result, uint32_t extended_value, zval *
return SUCCESS;
}
static inline int ct_eval_array_key_exists(zval *result, zval *op1, zval *op2) {
zval *value;
if (Z_TYPE_P(op2) != IS_ARRAY && !IS_PARTIAL_ARRAY(op2)) {
return FAILURE;
}
if (Z_TYPE_P(op1) != IS_STRING && Z_TYPE_P(op1) != IS_LONG && Z_TYPE_P(op1) != IS_NULL) {
return FAILURE;
}
if (fetch_array_elem(&value, op2, op1) == FAILURE) {
return FAILURE;
}
if (IS_PARTIAL_ARRAY(op2) && (!value || IS_BOT(value))) {
return FAILURE;
}
ZVAL_BOOL(result, value != NULL);
return SUCCESS;
}
/* The functions chosen here are simple to implement and either likely to affect a branch,
* or just happened to be commonly used with constant operands in WP (need to test other
* 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
}
SET_RESULT_BOT(result);
break;
case ZEND_ARRAY_KEY_EXISTS:
SKIP_IF_TOP(op1);
SKIP_IF_TOP(op2);
if (ct_eval_array_key_exists(&zv, op1, op2) == SUCCESS) {
SET_RESULT(result, &zv);
zval_ptr_dtor_nogc(&zv);
break;
}
SET_RESULT_BOT(result);
break;
case ZEND_FETCH_DIM_R:
case ZEND_FETCH_DIM_IS:
case ZEND_FETCH_LIST_R: