mirror of
https://github.com/php/php-src.git
synced 2026-04-22 07:28:09 +02:00
Merge branch 'PHP-8.0'
* PHP-8.0: Fix SSA integrity violation for type inference in dead code
This commit is contained in:
@@ -0,0 +1,18 @@
|
||||
--TEST--
|
||||
Make sure type inference upholds invariants for dead arrays
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
function test() {
|
||||
foreach ($a as $v) {
|
||||
$b[] = $v;
|
||||
}
|
||||
}
|
||||
|
||||
test();
|
||||
|
||||
?>
|
||||
--EXPECTF--
|
||||
Warning: Undefined variable $a in %s on line %d
|
||||
|
||||
Warning: foreach() argument must be of type array|object, null given in %s on line %d
|
||||
@@ -2011,24 +2011,28 @@ static uint32_t assign_dim_result_type(
|
||||
tmp |= MAY_BE_RC1 | MAY_BE_RCN;
|
||||
}
|
||||
if (tmp & MAY_BE_ARRAY) {
|
||||
if (value_type & MAY_BE_UNDEF) {
|
||||
tmp |= MAY_BE_ARRAY_OF_NULL;
|
||||
}
|
||||
if (dim_op_type == IS_UNUSED) {
|
||||
tmp |= MAY_BE_ARRAY_KEY_LONG;
|
||||
} else {
|
||||
if (dim_type & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
|
||||
tmp |= MAY_BE_ARRAY_KEY_LONG;
|
||||
/* Only add key type if we have a value type. We want to maintain the invariant that a
|
||||
* key type exists iff a value type exists even in dead code that may use empty types. */
|
||||
if (value_type & (MAY_BE_ANY|MAY_BE_UNDEF)) {
|
||||
if (value_type & MAY_BE_UNDEF) {
|
||||
tmp |= MAY_BE_ARRAY_OF_NULL;
|
||||
}
|
||||
if (dim_type & MAY_BE_STRING) {
|
||||
tmp |= MAY_BE_ARRAY_KEY_STRING;
|
||||
if (dim_op_type != IS_CONST) {
|
||||
// FIXME: numeric string
|
||||
if (dim_op_type == IS_UNUSED) {
|
||||
tmp |= MAY_BE_ARRAY_KEY_LONG;
|
||||
} else {
|
||||
if (dim_type & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
|
||||
tmp |= MAY_BE_ARRAY_KEY_LONG;
|
||||
}
|
||||
}
|
||||
if (dim_type & (MAY_BE_UNDEF|MAY_BE_NULL)) {
|
||||
tmp |= MAY_BE_ARRAY_KEY_STRING;
|
||||
if (dim_type & MAY_BE_STRING) {
|
||||
tmp |= MAY_BE_ARRAY_KEY_STRING;
|
||||
if (dim_op_type != IS_CONST) {
|
||||
// FIXME: numeric string
|
||||
tmp |= MAY_BE_ARRAY_KEY_LONG;
|
||||
}
|
||||
}
|
||||
if (dim_type & (MAY_BE_UNDEF|MAY_BE_NULL)) {
|
||||
tmp |= MAY_BE_ARRAY_KEY_STRING;
|
||||
}
|
||||
}
|
||||
}
|
||||
/* Only add value type if we have a key type. It might be that the key type is illegal
|
||||
|
||||
Reference in New Issue
Block a user