Don't const evaluate increment of array in SCCP

This commit is contained in:
Nikita Popov 2021-09-16 14:42:08 +02:00
parent 1548418461
commit 4c8093a9f1
2 changed files with 31 additions and 0 deletions

View file

@ -704,6 +704,10 @@ static inline int ct_eval_assign_obj(zval *result, zval *value, zval *key) {
} }
static inline int ct_eval_incdec(zval *result, zend_uchar opcode, zval *op1) { static inline int ct_eval_incdec(zval *result, zend_uchar opcode, zval *op1) {
if (Z_TYPE_P(op1) == IS_ARRAY || IS_PARTIAL_ARRAY(op1)) {
return FAILURE;
}
ZVAL_COPY(result, op1); ZVAL_COPY(result, op1);
if (opcode == ZEND_PRE_INC if (opcode == ZEND_PRE_INC
|| opcode == ZEND_POST_INC || opcode == ZEND_POST_INC

View file

@ -0,0 +1,27 @@
--TEST--
Do not constant fold increment of array
--FILE--
<?php
function test_inc_array() {
$a = [];
$a++;
}
function test_inc_partial_array($k) {
$a = [];
$a[$k] = 0;
$a++;
}
try {
test_inc_array();
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
try {
test_inc_partial_array(0);
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot increment array
Cannot increment array