Skip to content

Commit 40b258f

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fixed incorrect DCE for ADD_ARRAY_ELEMENT instruction
2 parents b916567 + 97f0c0b commit 40b258f

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

Zend/Optimizer/dce.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,6 @@ static inline bool may_have_side_effects(
111111
case ZEND_ROPE_INIT:
112112
case ZEND_ROPE_ADD:
113113
case ZEND_INIT_ARRAY:
114-
case ZEND_ADD_ARRAY_ELEMENT:
115114
case ZEND_SPACESHIP:
116115
case ZEND_STRLEN:
117116
case ZEND_COUNT:
@@ -128,6 +127,12 @@ static inline bool may_have_side_effects(
128127
case ZEND_ARRAY_KEY_EXISTS:
129128
/* No side effects */
130129
return 0;
130+
case ZEND_ADD_ARRAY_ELEMENT:
131+
/* TODO: We can't free two vars. Keep instruction alive. <?php [0, "$a" => "$b"]; */
132+
if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) && (opline->op2_type & (IS_VAR|IS_TMP_VAR))) {
133+
return 1;
134+
}
135+
return 0;
131136
case ZEND_ROPE_END:
132137
/* TODO: Rope dce optimization, see #76446 */
133138
return 1;

ext/opcache/tests/opt/dce_011.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
Incorrect DCE of ADD_ARRAY_ELEMENT
3+
--FILE--
4+
<?php
5+
[0, "$a" => "$b"];
6+
?>
7+
DONE
8+
--EXPECTF--
9+
Warning: Undefined variable $a in %sdce_011.php on line 2
10+
11+
Warning: Undefined variable $b in %sdce_011.php on line 2
12+
DONE

0 commit comments

Comments
 (0)