Skip to content

Commit 0f5b382

Browse files
committed
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1: Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
2 parents d7a7309 + 643c4ba commit 0f5b382

File tree

3 files changed

+9
-53
lines changed

3 files changed

+9
-53
lines changed

NEWS

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ PHP NEWS
88
. Fixed bug GH-12215 (Module entry being overwritten causes type errors in
99
ext/dom). (nielsdos)
1010
. Fixed bug GH-12273 (__builtin_cpu_init check). (Freaky)
11-
. Fixed bug GH-10008 (Narrowing occurred during type inference of
12-
ZEND_ADD_ARRAY_ELEMENT). (nielsdos, arnaud-lb)
1311

1412
- CType:
1513
. Fixed bug GH-11997 (ctype_alnum 5 times slower in PHP 8.1 or greater).

Zend/Optimizer/zend_inference.c

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1942,21 +1942,6 @@ ZEND_API uint32_t zend_array_element_type(uint32_t t1, zend_uchar op_type, int w
19421942
return tmp;
19431943
}
19441944

1945-
static zend_always_inline uint32_t assign_long_dim_array_result_type(uint32_t arr_type)
1946-
{
1947-
/* Rules:
1948-
* HASH_ONLY -> MAY_BE_ARRAY_NUMERIC_HASH
1949-
* PACKED_ONLY -> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
1950-
* HASH || PACKED -> MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
1951-
* 0 -> MAY_BE_ARRAY_NUMERIC_HASH
1952-
*/
1953-
if (MAY_BE_PACKED(arr_type)) {
1954-
return MAY_BE_ARRAY_KEY_LONG;
1955-
} else {
1956-
return MAY_BE_ARRAY_NUMERIC_HASH;
1957-
}
1958-
}
1959-
19601945
static uint32_t assign_dim_array_result_type(
19611946
uint32_t arr_type, uint32_t dim_type, uint32_t value_type, zend_uchar dim_op_type) {
19621947
uint32_t tmp = 0;
@@ -1970,13 +1955,13 @@ static uint32_t assign_dim_array_result_type(
19701955
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
19711956
tmp |= MAY_BE_ARRAY_PACKED;
19721957
}
1973-
tmp |= assign_long_dim_array_result_type(arr_type);
1958+
tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
19741959
} else {
19751960
if (dim_type & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
19761961
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
19771962
tmp |= MAY_BE_ARRAY_PACKED;
19781963
}
1979-
tmp |= assign_long_dim_array_result_type(arr_type);
1964+
tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
19801965
}
19811966
if (dim_type & MAY_BE_STRING) {
19821967
tmp |= MAY_BE_ARRAY_KEY_STRING;
@@ -1985,7 +1970,7 @@ static uint32_t assign_dim_array_result_type(
19851970
if (arr_type & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
19861971
tmp |= MAY_BE_ARRAY_PACKED;
19871972
}
1988-
tmp |= assign_long_dim_array_result_type(arr_type);
1973+
tmp |= MAY_BE_HASH_ONLY(arr_type) ? MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
19891974
}
19901975
}
19911976
if (dim_type & (MAY_BE_UNDEF|MAY_BE_NULL)) {
@@ -3301,15 +3286,17 @@ static zend_always_inline zend_result _zend_update_type_info(
33013286
key_type |= MAY_BE_ARRAY_PACKED;
33023287
}
33033288
if (t1 & MAY_BE_ARRAY) {
3304-
key_type |= assign_long_dim_array_result_type(t1);
3289+
key_type |= MAY_BE_HASH_ONLY(t1) ?
3290+
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
33053291
}
33063292
} else {
33073293
if (t2 & (MAY_BE_LONG|MAY_BE_FALSE|MAY_BE_TRUE|MAY_BE_RESOURCE|MAY_BE_DOUBLE)) {
33083294
if (t1 & (MAY_BE_UNDEF|MAY_BE_NULL|MAY_BE_FALSE)) {
33093295
key_type |= MAY_BE_ARRAY_PACKED;
33103296
}
33113297
if (t1 & MAY_BE_ARRAY) {
3312-
key_type |= assign_long_dim_array_result_type(t1);
3298+
key_type |= MAY_BE_HASH_ONLY(t1) ?
3299+
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
33133300
}
33143301
}
33153302
if (t2 & MAY_BE_STRING) {
@@ -3320,7 +3307,8 @@ static zend_always_inline zend_result _zend_update_type_info(
33203307
key_type |= MAY_BE_ARRAY_PACKED;
33213308
}
33223309
if (t1 & MAY_BE_ARRAY) {
3323-
key_type |= assign_long_dim_array_result_type(t1);
3310+
key_type |= MAY_BE_HASH_ONLY(t1) ?
3311+
MAY_BE_ARRAY_NUMERIC_HASH : MAY_BE_ARRAY_KEY_LONG;
33243312
}
33253313
}
33263314
}

ext/opcache/tests/opt/gh10008.phpt

Lines changed: 0 additions & 30 deletions
This file was deleted.

0 commit comments

Comments
 (0)