Skip to content

Commit 2cff0e6

Browse files
committed
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0: Fix type narrowing warning during type inference of ZEND_FETCH_DIM_W
2 parents ff6b813 + 8286de2 commit 2cff0e6

File tree

2 files changed

+21
-2
lines changed

2 files changed

+21
-2
lines changed

Zend/Optimizer/zend_inference.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3326,11 +3326,12 @@ static zend_always_inline int _zend_update_type_info(
33263326
ZEND_ASSERT(j < 0 && "There should only be one use");
33273327
}
33283328
}
3329-
if ((tmp & MAY_BE_ARRAY) && (tmp & MAY_BE_ARRAY_KEY_ANY)) {
3329+
if (((tmp & MAY_BE_ARRAY) && (tmp & MAY_BE_ARRAY_KEY_ANY)) || opline->opcode == ZEND_FETCH_DIM_FUNC_ARG) {
33303330
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
33313331
} else {
33323332
/* invalid key type */
3333-
tmp = (tmp & (MAY_BE_RC1|MAY_BE_RCN)) | (t1 & ~(MAY_BE_RC1|MAY_BE_RCN));
3333+
tmp = (tmp & (MAY_BE_RC1|MAY_BE_RCN|MAY_BE_ARRAY)) |
3334+
(t1 & ~(MAY_BE_RC1|MAY_BE_RCN|MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE));
33343335
UPDATE_SSA_TYPE(tmp, ssa_op->op1_def);
33353336
}
33363337
COPY_SSA_OBJ_TYPE(ssa_op->op1_use, ssa_op->op1_def);
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
--TEST--
2+
Type inference 004: Type narrowing warning during type inference of ZEND_FETCH_DIM_W
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.optimization_level=-1
7+
--FILE--
8+
<?php
9+
function y() {
10+
for(;;){
11+
$arr[]->y = c;
12+
$arr = c;
13+
}
14+
}
15+
?>
16+
DONE
17+
--EXPECT--
18+
DONE

0 commit comments

Comments
 (0)