Merge branch 'PHP-8.2' into PHP-8.3

* PHP-8.2:
  Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
This commit is contained in:
Niels Dossche 2023-09-30 01:27:29 +02:00
commit 04a2a42f2a
3 changed files with 9 additions and 55 deletions

4
NEWS
View file

@ -2,10 +2,6 @@ PHP NEWS
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
?? ??? ????, PHP 8.3.0RC4 ?? ??? ????, PHP 8.3.0RC4
- Core:
. Fixed bug GH-10008 (Narrowing occurred during type inference of
ZEND_ADD_ARRAY_ELEMENT). (nielsdos, arnaud-lb)
- CType: - CType:
. Fixed bug GH-11997 (ctype_alnum 5 times slower in PHP 8.1 or greater). . Fixed bug GH-11997 (ctype_alnum 5 times slower in PHP 8.1 or greater).
(nielsdos) (nielsdos)

View file

@ -1942,21 +1942,6 @@ ZEND_API uint32_t zend_array_element_type(uint32_t t1, uint8_t op_type, int writ
return tmp; return tmp;
} }
static zend_always_inline uint32_t assign_long_dim_array_result_type(uint32_t arr_type)
{
/* Rules:
* HASH_ONLY -> MAY_BE_ARRAY_NUMERIC_HASH
* PACKED_ONLY -> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
* HASH || PACKED -> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
* 0 -> MAY_BE_ARRAY_NUMERIC_HASH
*/
if (MAY_BE_PACKED(arr_type)) {
return MAY_BE_ARRAY_KEY_LONG;
} else {
return MAY_BE_ARRAY_NUMERIC_HASH;
}
}
static uint32_t assign_dim_array_result_type( static uint32_t assign_dim_array_result_type(
uint32_t arr_type, uint32_t dim_type, uint32_t value_type, uint8_t dim_op_type) { uint32_t arr_type, uint32_t dim_type, uint32_t value_type, uint8_t dim_op_type) {
uint32_t tmp = 0; uint32_t tmp = 0;
@ -1970,13 +1955,13 @@ static uint32_t assign_dim_array_result_type(
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) { if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
tmp |= MAY_BE_ARRAY_PACKED; tmp |= MAY_BE_ARRAY_PACKED;
} }
tmp |= assign_long_dim_array_result_type(arr_type); tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
} else { } else {
if (dim_type & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) { if (dim_type & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) { if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
tmp |= MAY_BE_ARRAY_PACKED; tmp |= MAY_BE_ARRAY_PACKED;
} }
tmp |= assign_long_dim_array_result_type(arr_type); tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
} }
if (dim_type & MAY_BE_STRING) { if (dim_type & MAY_BE_STRING) {
tmp |= MAY_BE_ARRAY_KEY_STRING; tmp |= MAY_BE_ARRAY_KEY_STRING;
@ -1985,7 +1970,7 @@ static uint32_t assign_dim_array_result_type(
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) { if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
tmp |= MAY_BE_ARRAY_PACKED; tmp |= MAY_BE_ARRAY_PACKED;
} }
tmp |= assign_long_dim_array_result_type(arr_type); tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
} }
} }
if (dim_type & (MAY_BE_UNDEF|MAY_BE_NULL)) { if (dim_type & (MAY_BE_UNDEF|MAY_BE_NULL)) {
@ -3305,7 +3290,8 @@ static zend_always_inline zend_result _zend_update_type_info(
key_type |= MAY_BE_ARRAY_PACKED; key_type |= MAY_BE_ARRAY_PACKED;
} }
if (t1 & MAY_BE_ARRAY) { if (t1 & MAY_BE_ARRAY) {
key_type |= assign_long_dim_array_result_type(t1); key_type |= MAY_BE_HASH_ONLY(t1) ?
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
} }
} else { } else {
if (t2 & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) { if (t2 & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
@ -3313,7 +3299,8 @@ static zend_always_inline zend_result _zend_update_type_info(
key_type |= MAY_BE_ARRAY_PACKED; key_type |= MAY_BE_ARRAY_PACKED;
} }
if (t1 & MAY_BE_ARRAY) { if (t1 & MAY_BE_ARRAY) {
key_type |= assign_long_dim_array_result_type(t1); key_type |= MAY_BE_HASH_ONLY(t1) ?
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
} }
} }
if (t2 & MAY_BE_STRING) { if (t2 & MAY_BE_STRING) {
@ -3324,7 +3311,8 @@ static zend_always_inline zend_result _zend_update_type_info(
key_type |= MAY_BE_ARRAY_PACKED; key_type |= MAY_BE_ARRAY_PACKED;
} }
if (t1 & MAY_BE_ARRAY) { if (t1 & MAY_BE_ARRAY) {
key_type |= assign_long_dim_array_result_type(t1); key_type |= MAY_BE_HASH_ONLY(t1) ?
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
} }
} }
} }

View file

@ -1,30 +0,0 @@
--TEST--
GH-10008 (Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT)
--INI--
opcache.enable=1
opcache.enable_cli=1
opcache.optimization_level=0x20
--EXTENSIONS--
opcache
--FILE--
<?php
function test()
{
$bool = true;
for ($i = 0; $i < 10; $i++) {
if ($bool !== true) {
$string_key = "a";
// The following line triggers narrowing during type inference of ZEND_ADD_ARRAY_ELEMENT.
$array = ["b" => $bool, $string_key => 123];
}
$bool = false;
}
}
echo "Done\n";
?>
--EXPECT--
Done