Commit graph

195 commits

Author SHA1 Message Date
Dmitry Stogov
6bf4041398 Backport fix for HASH/PACKED array inference through MAY_BE_ARRAY_EMPTY flag (#12591)
* Fixed HASH/PACKED array inference through MAY_BE_ARRAY_EMPTY flag

This fixes GH-12527

* typo
2023-11-03 10:54:57 +03:00
Dmitry Stogov
177a6f5d8a Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
2023-11-02 08:11:00 +03:00
Dmitry Stogov
798b9d097b Fixed GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT 2023-11-02 08:09:29 +03:00
Dmitry Stogov
00352429ca Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Backport implementation of iterative Pearce's SCC finding algoritm (#12528)
2023-10-31 09:59:31 +03:00
Dmitry Stogov
52bb39e661 Backport implementation of iterative Pearce's SCC finding algoritm (#12528)
Fixes GH-11795
2023-10-31 09:54:44 +03:00
Dmitry Stogov
14b36c8583 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed GH-12511: Use must be in next opline assertion with patched infection
2023-10-31 07:52:38 +03:00
Dmitry Stogov
b3b46a44c5 Fixed GH-12511: Use must be in next opline assertion with patched infection 2023-10-31 07:51:36 +03:00
Dmitry Stogov
770c1b0361 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed GH-12509: JIT assertion when running php-parser tests
2023-10-26 23:59:03 +03:00
Dmitry Stogov
5f46d86955 Fixed GH-12509: JIT assertion when running php-parser tests 2023-10-26 23:58:29 +03:00
Dmitry Stogov
7320f33f7f Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed incorrect type inference
2023-10-24 18:48:58 +03:00
Dmitry Stogov
aa45df4849 Fixed incorrect type inference 2023-10-24 18:48:29 +03:00
Dmitry Stogov
101bd1b199 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fixed GH-12262: Tracing JIT assertion crash when using phpstan
2023-10-03 13:25:22 +03:00
Dmitry Stogov
54452b4811 Fixed GH-12262: Tracing JIT assertion crash when using phpstan 2023-10-03 13:22:33 +03:00
Niels Dossche
0f5b382528 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"
2023-09-30 01:27:06 +02:00
Niels Dossche
643c4ba417 Revert "Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT"
Although it passes CI on 8.1, it causes CI failures in the JIT on 8.2 and
higher.
See 1726922500

This reverts commit e72fc12058.
2023-09-30 01:25:48 +02:00
Niels Dossche
d7a7309b53 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
  Fix type error on XSLTProcessor::transformToDoc return value with SimpleXML
2023-09-30 00:10:35 +02:00
Niels Dossche
e72fc12058 Fix GH-10008: Narrowing occurred during type inference of ZEND_ADD_ARRAY_ELEMENT
This test triggers narrowing for two ops: first ZEND_ADD_ARRAY_ELEMENT,
and then ZEND_ASSIGN.

The type inference happens in the following order:
1) The ZEND_ADD_ARRAY_ELEMENT infers type 0x40e04080 (packed flag is set),
   arr_type=0 at this point because it hasn't been set by ZEND_INIT_ARRAY yet.
2) The ZEND_INIT_ARRAY infers type 0x40804080
3) The ZEND_ADD_ARRAY_ELEMENT infers type 0x40e04080, arr_type=0x40804080,
   which does not have the packed flag set while the existing result of
   ZEND_ADD_ARRAY_ELEMENT has the packed flag set.

This seems to occur because of the phi node introduced by the while
loop. If I remove the loop the problem goes away.

As Arnaud noted, this seems to be caused by a too wide type inference
for arr_type==0. We should keep the invariant that if x>=y then
key_type(x) >= key_type(y).
If we write the possible results down in a table we get:

```
arr_type           resulting key type
---------------    --------------------------------------------------------------------------
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 | MAY_BE_ARRAY_PACKED (== MAY_BE_ARRAY_KEY_LONG)
```

As we can see, `HASH_ONLY > 0` but
`MAY_BE_ARRAY_NUMERIC_HASH < MAY_BE_ARRAY_NUMERIC_HASH | MAY_BE_ARRAY_PACKED`,
which violates the invariant.
Instead if we modify the zero case to have MAY_BE_ARRAY_NUMERIC_HASH instead,
we get the following table which satisfies the invariant.

```
arr_type           resulting key type
---------------    --------------------------------------------------------------------------
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
```

Broke in 1ffbb73.
Closes GH-10294.
2023-09-30 00:08:32 +02:00
nielsdos
e1fc246444 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix too wide OR and AND range inference
2023-05-02 20:18:05 +02:00
nielsdos
fbf5216ca0 Fix too wide OR and AND range inference
There is a typo which causes the AND and OR range inference to infer a
wider range than necessary. Fix this typo. There are many ranges for
which the inference is too wide, I just picked one for AND and one for
OR that I found through symbolic execution.

In this example test, the previous range inferred for test_or was [-27..-1]
instead of [-20..-1].
And the previous range inferred for test_and was [-32..-25]
instead of [-28..-25].

Closes GH-11170.
2023-05-02 20:08:59 +02:00
Dmitry Stogov
e14ac1caee Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Allow FETCH_OBJ_W and FETCH_STATIC_PROP_W to return INDIRECT/UNDEF zval for uninitialized typed properties (#11048)
2023-04-10 23:25:08 +03:00
Dmitry Stogov
0c65b396d6
Allow FETCH_OBJ_W and FETCH_STATIC_PROP_W to return INDIRECT/UNDEF zval for uninitialized typed properties (#11048) 2023-04-10 23:19:17 +03:00
Ilija Tovilo
b1a49ff053
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix RC1 assumption for typed properties with __get
2023-03-13 10:00:17 +01:00
Ilija Tovilo
3175f24d6a
Fix RC1 assumption for typed properties with __get
Unsetting typed properties resorts back to __get which may have RC1.

Closes GH-10833
2023-03-13 09:58:49 +01:00
Dmitry Stogov
e3aa73904a Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix updating SSA object type for *_ASSIGN_OP (#10458)
2023-02-14 11:29:47 +03:00
Niels Dossche
d94ddbed2c
Fix updating SSA object type for *_ASSIGN_OP (#10458)
The code fetched the class entry into ce for objects and static
properties. However, when the actual update needs to take place (when
result_def exists), the class entry in ce was reset to NULL. So the SSA
object type update never happened. Fetch the class entry in the
result_def>=0 case instead after the reset of ce to NULL.
2023-02-14 11:29:29 +03:00
Dmitry Stogov
55e3f73109 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix type inference
2023-01-30 13:16:05 +03:00
Dmitry Stogov
81607a62ca Fix type inference
Fixes oss-fuzz #55358
2023-01-30 13:15:05 +03:00
Dmitry Stogov
227b3b3281 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect check condition in type inference (#10425)
2023-01-24 09:32:26 +03:00
Niels Dossche
2787e3cd65
Fix incorrect check condition in type inference (#10425)
The "nothing to do" case would never be hit because the switch block
would execute if the opcode is ZEND_ASSIGN_STATIC_PROP_OP,
not ZEND_ASSIGN_STATIC_PROP. This meant that we were falling through to
the else block. Fix this by correcting the check condition.
2023-01-24 09:32:07 +03:00
Dmitry Stogov
94b8c2da9f Fixed type inference
Fixes oss-fuzz #51640
2022-09-26 12:19:12 +03:00
Dmitry Stogov
7496a400aa Fix SSA construction and type inference
Fixes oss-fuzz #51476
2022-09-19 15:45:34 +03:00
Dmitry Stogov
c151e9b75b Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix type inference
2022-09-05 13:01:04 +03:00
Dmitry Stogov
c852e0fff9 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference
2022-09-05 12:56:34 +03:00
Dmitry Stogov
567213c32a Drop range inference for IS_NULL/IS_FALSE/IS_TRUE.
These values not always converted to IS_LONG (e.g. by -- and ++) and
this leads to incorrect range inferene and later to incorrect JIT code
generation.
2022-08-23 11:22:31 +03:00
Dmitry Stogov
e10d2c2bf9 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference
2022-08-22 21:12:49 +03:00
Dmitry Stogov
95befc786a Fix type inference
Fixes oss-fuzz #50272
2022-08-22 21:11:39 +03:00
Dmitry Stogov
87cf05e8be Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference
2022-07-25 15:55:15 +03:00
Dmitry Stogov
d50875c822 Fix type inference
Fixes oss-fuzz #49423 and #49474
2022-07-25 15:53:06 +03:00
Dmitry Stogov
71814e9d99 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference
2022-07-18 14:20:41 +03:00
Dmitry Stogov
82d3ad64df Fix type inference
Fixes oss-fuzz #48908
2022-07-18 14:20:06 +03:00
Dmitry Stogov
26d890e6ba Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference for FETCH_DI_UNSET
2022-07-18 13:15:12 +03:00
Dmitry Stogov
b734d45626 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference for FETCH_DI_UNSET
2022-07-18 13:15:03 +03:00
Dmitry Stogov
20a902749a Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference
2022-06-14 12:00:26 +03:00
Dmitry Stogov
729be469ae Fix type inference
This dixes oss-fuzz #47921
2022-06-14 11:59:35 +03:00
Dmitry Stogov
f56371bdd3 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference
2022-06-14 10:21:24 +03:00
Dmitry Stogov
1b45efb6fb Fix type inference
This fixes oss-fuzz #47920
2022-06-14 10:20:45 +03:00
Ilija Tovilo
5a855ee8d6
Fix GH-8661: Nullsafe in coalesce triggers undefined variable warning
Closes GH-8690
2022-06-12 21:52:14 +02:00
George Peter Banyard
b40ae80804
Convert iterable into an internal alias for Traversable|array (#7309)
This does a compile time transformation of ``iterable`` into ``Traversable|array`` which simplifies some of the LSP variance handling.

The arginfo generation script from stubs is updated to produce a union type when it encounters the type ``iterable``
Extension functions which do not regenerate the arginfo, or write them manually are still supported by mimicking the compile time transformation while registering the function.

Type Reflection is preserved for single ``iterable`` (and ``?iterable``) to produce a ReflectionNamedType with name ``iterable``, however usage of ``iterable`` in union types will be converted to ``array|Traversable``
2022-06-07 13:35:34 +01:00
Dmitry Stogov
faf3410957 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference
2022-06-06 11:14:33 +03:00
Dmitry Stogov
b86c6245cc Fix type inference
This fixes oss-fuzz #47777
2022-06-06 11:13:53 +03:00