Skip to content

Commit 4c8093a

Browse files
committed
Don't const evaluate increment of array in SCCP
1 parent 1548418 commit 4c8093a

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

ext/opcache/Optimizer/sccp.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,10 @@ static inline int ct_eval_assign_obj(zval *result, zval *value, zval *key) {
704704
}
705705

706706
static inline int ct_eval_incdec(zval *result, zend_uchar opcode, zval *op1) {
707+
if (Z_TYPE_P(op1) == IS_ARRAY || IS_PARTIAL_ARRAY(op1)) {
708+
return FAILURE;
709+
}
710+
707711
ZVAL_COPY(result, op1);
708712
if (opcode == ZEND_PRE_INC
709713
|| opcode == ZEND_POST_INC

ext/opcache/tests/inc_array.phpt

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
--TEST--
2+
Do not constant fold increment of array
3+
--FILE--
4+
<?php
5+
function test_inc_array() {
6+
$a = [];
7+
$a++;
8+
}
9+
function test_inc_partial_array($k) {
10+
$a = [];
11+
$a[$k] = 0;
12+
$a++;
13+
}
14+
try {
15+
test_inc_array();
16+
} catch (TypeError $e) {
17+
echo $e->getMessage(), "\n";
18+
}
19+
try {
20+
test_inc_partial_array(0);
21+
} catch (TypeError $e) {
22+
echo $e->getMessage(), "\n";
23+
}
24+
?>
25+
--EXPECT--
26+
Cannot increment array
27+
Cannot increment array

0 commit comments

Comments
 (0)