Commit graph

102 commits

Author SHA1 Message Date
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
52bb39e661 Backport implementation of iterative Pearce's SCC finding algoritm (#12528)
Fixes GH-11795
2023-10-31 09:54:44 +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
5f46d86955 Fixed GH-12509: JIT assertion when running php-parser tests 2023-10-26 23:58:29 +03:00
Dmitry Stogov
aa45df4849 Fixed incorrect type inference 2023-10-24 18:48:29 +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
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
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
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
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
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
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
81607a62ca Fix type inference
Fixes oss-fuzz #55358
2023-01-30 13:15:05 +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
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
95befc786a Fix type inference
Fixes oss-fuzz #50272
2022-08-22 21:11:39 +03:00
Dmitry Stogov
d50875c822 Fix type inference
Fixes oss-fuzz #49423 and #49474
2022-07-25 15:53:06 +03:00
Dmitry Stogov
82d3ad64df Fix type inference
Fixes oss-fuzz #48908
2022-07-18 14:20:06 +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
729be469ae Fix type inference
This dixes oss-fuzz #47921
2022-06-14 11:59:35 +03:00
Dmitry Stogov
1b45efb6fb Fix type inference
This fixes oss-fuzz #47920
2022-06-14 10:20:45 +03:00
Dmitry Stogov
b86c6245cc Fix type inference
This fixes oss-fuzz #47777
2022-06-06 11:13:53 +03:00
Dmitry Stogov
aad5fbac85 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference
2022-05-16 12:42:04 +03:00
Dmitry Stogov
84c1e99ecf Fix type inference
This fizes oss-fuzz #47044
2022-05-11 12:39:26 +03:00
Dmitry Stogov
f1fc58ed8d Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference
2022-05-11 12:09:53 +03:00
Dmitry Stogov
e14dc15e13 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference
2022-04-25 12:17:07 +03:00
Dmitry Stogov
2cff0e674d Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type narrowing warning during type inference of ZEND_FETCH_DIM_W
2022-04-25 11:17:04 +03:00
Nikita Popov
4026daee2b Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Move MAY_BE_REF check into COPY_SSA_OBJ_TYPE
2022-04-15 23:14:59 +02:00
Nikita Popov
38547b996a Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Don't use CE for by-ref arguments
2022-04-15 23:00:59 +02:00
Nikita Popov
f1814e6a1f Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Don't use CE info from pi node for MAY_BE_REF var
2022-04-15 22:37:29 +02:00
Nikita Popov
3fdb1aa14e Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix inference for assignment of known object to reference
2022-04-15 22:15:32 +02:00
Nikita Popov
c72e9621ce Improve type narrowing fix
We need to explicitly model the null return type for property
accesses on non-objects.
2022-04-10 11:22:36 +02:00
Nikita Popov
323f3c6914 Improve file/line information for narrowing warning
Report the file/line of the opline rather than the include location.

This should make issues like #8251 easier to debug.
2022-04-10 10:41:20 +02:00
Dmitry Stogov
e721a42211 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed reference counting inference
2022-04-04 15:34:46 +03:00
Dmitry Stogov
156d3aedc1 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix memory leak
2022-03-14 12:58:11 +03:00
Dmitry Stogov
aced867a95 Fix typr inference
Fixes oss-fuzz #45020
2022-02-28 18:25:49 +03:00
Dmitry Stogov
0eb96b6e13 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference
2022-02-11 13:04:12 +03:00
Dmitry Stogov
9824735aa4 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference
2022-01-10 21:54:14 +03:00
Dmitry Stogov
8e5f54ed0c Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference for assign to string offset with invalid index.
2022-01-10 16:05:01 +03:00
Dmitry Stogov
8862e23098 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix reference contig inference
2021-12-28 10:00:14 +03:00
Dmitry Stogov
c8d10a8243 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference for INIT_ARRAY with invalid index
2021-12-20 11:46:36 +03:00
Dmitry Stogov
cfcee97ad6 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Remove range inference for booleans.
2021-12-10 14:33:36 +03:00
Dmitry Stogov
4ed10f3d47 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix refcount inferemce ($a += $a returns old array with RCN)
2021-12-06 11:31:51 +03:00
Dmitry Stogov
3564001502 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  JIT: Fix incorrect reference counting inference
2021-11-30 13:00:04 +03:00
Dmitry Stogov
2d3ea98624 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed type inference (it's safe to ignore reference counting narrowing)
2021-11-29 23:39:37 +03:00
Dmitry Stogov
23c5a6fd16 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  JIT: Fix exception handling when next array element is already occupied
2021-11-29 21:57:29 +03:00
Dmitry Stogov
c6e895aec2 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Disable type narrowing optimization when we contruct SSA for JIT
2021-11-29 15:53:16 +03:00
Dmitry Stogov
b1a1ed380f Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed incorrect narrowing to double
2021-11-25 15:15:01 +03:00
Dmitry Stogov
ecc4d1326b Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed incorrect refcountion inference for BW_NOT
2021-11-25 13:53:26 +03:00
Dmitry Stogov
fb582f4230 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  JIT: Fixed reference-counting inference
2021-11-15 10:40:35 +03:00