Skip to content

Commit

Permalink
Don't const evaluate increment of array in SCCP
Browse files Browse the repository at this point in the history
  • Loading branch information
nikic committed Sep 16, 2021
1 parent 1548418 commit 4c8093a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions ext/opcache/Optimizer/sccp.c
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
if (Z_TYPE_P(op1) == IS_ARRAY || IS_PARTIAL_ARRAY(op1)) {
return FAILURE;
}

ZVAL_COPY(result, op1);
if (opcode == ZEND_PRE_INC
|| opcode == ZEND_POST_INC
Expand Down
27 changes: 27 additions & 0 deletions ext/opcache/tests/inc_array.phpt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 4c8093a

Please sign in to comment.