Commit Graph

496 Commits

Author SHA1 Message Date
Nikita Popov
7408da7ac0 Merge branch 'PHP-8.1'
* PHP-8.1:
  Move MAY_BE_REF check into COPY_SSA_OBJ_TYPE
2022-04-15 23:15:06 +02: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
01996d1534 Merge branch 'PHP-8.1'
* PHP-8.1:
  Don't use CE for by-ref arguments
2022-04-15 23:01:05 +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
bc24c62030 Merge branch 'PHP-8.1'
* PHP-8.1:
  Don't use CE info from pi node for MAY_BE_REF var
2022-04-15 22:39:13 +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
838746bb4b Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix inference for assignment of known object to reference
2022-04-15 22:15:57 +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
George Peter Banyard
8649cb8a96
Improve and fix stub return types (#8368) 2022-04-14 18:38:00 +01:00
Nikita Popov
414f7fc2bb Merge branch 'PHP-8.1'
* PHP-8.1:
  Improve type narrowing fix
2022-04-10 11:22:52 +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
8e58828e89 Add debug assertion on type narrowing
This ensures that this will show up as a fuzzing failure.
2022-04-10 10:45:52 +02:00
Nikita Popov
d5c854d89a Merge branch 'PHP-8.1'
* PHP-8.1:
  Improve file/line information for narrowing warning
2022-04-10 10:42:11 +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
George Peter Banyard
2fe35cf807 Regenerate optimized func infos
Using the --generate-optimizer-info option for ./build/gen_stubs.php
2022-04-05 13:36:14 +01:00
Dmitry Stogov
d260e063a8 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed reference counting inference
2022-04-04 15:34:57 +03: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
d06422670c Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix memory leak
2022-03-14 12:59:13 +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
df14a07887 Merge branch 'PHP-8.1'
* PHP-8.1:
  Optimizer: Fix inorrect constant substitution in FETCH_LIST_R
2022-03-11 14:31:32 +03:00
Dmitry Stogov
770a544af4 Optimizer: Fix inorrect constant substitution in FETCH_LIST_R
Fixes oss-fuzz #45429
2022-03-11 14:30:27 +03:00
Dmitry Stogov
bf079d0515 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed memory leak
2022-03-11 11:33:32 +03:00
Dmitry Stogov
1f5562aa09 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed memory leak
2022-03-11 11:33:01 +03:00
Dmitry Stogov
486d654b7d Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix typr inference
2022-02-28 18:26:37 +03:00
Dmitry Stogov
aced867a95 Fix typr inference
Fixes oss-fuzz #45020
2022-02-28 18:25:49 +03:00
Dmitry Stogov
36ce177e5e Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed incorrect DCE for FREE
2022-02-28 11:54:34 +03:00
Dmitry Stogov
56d7672d56 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed incorrect DCE for FREE
2022-02-28 11:54:25 +03:00
Christoph M. Becker
bf32299184
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8140: Wrong first class callable by name optimization
2022-02-24 10:37:34 +01:00
Christoph M. Becker
33cd61c904
Fix GH-8140: Wrong first class callable by name optimization
When optimizing by name function calls, we must not replace
`CALLABLE_CONVERT` opcodes, but have to keep them.

Closes GH-8144.
2022-02-24 10:35:53 +01:00
Christoph M. Becker
3be34c3b95
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8074: Wrong type inference of range() result
2022-02-22 10:21:07 +01:00
Christoph M. Becker
7ea3b19331
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8074: Wrong type inference of range() result
2022-02-22 10:20:13 +01:00
Dmitry Stogov
ace00faddd Merge branch 'PHP-8.1'
* PHP-8.1:
  Disable ASSIGN optimization for values inferred for fatal errors.
2022-02-18 11:38:16 +03:00
Dmitry Stogov
7e8257fbd2 Disable ASSIGN optimization for values inferred for fatal errors. 2022-02-18 11:35:43 +03:00
Dmitry Stogov
3a069da0fd Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference
2022-02-11 13:16:01 +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
ca0afc3c8e Improve speed of dominators and loop identification algorithms 2022-02-07 12:48:44 +03:00
Dmitry Stogov
2af33234b2 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix too aggressive DCE that leads to memory leak
2022-01-28 12:18:57 +03:00
Dmitry Stogov
34c2324fbf Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix too aggressive DCE that leads to memory leak
2022-01-28 12:18:47 +03:00
Nikita Popov
4543cd32ae Remove JMPZNZ opcode
While JMPZNZ can avoid execution of a separate JMP opcode in some
cases, it also prevents smart branch optimization, so creating
JMPZNZ may actually have a negative effect. It also adds additional
complexity for optimizations.

Drop JMPZNZ in favor of JMPZ+JMP or JMPNZ+JMP.

Closes GH-7857.
2022-01-10 22:07:10 +01:00
Dmitry Stogov
387c78a41f Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference
2022-01-10 21:55:25 +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
4d907a6b43 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed NAN handling in SCCP
2022-01-10 19:42:29 +03:00
Dmitry Stogov
906cb52c63 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed NAN handling in SCCP
2022-01-10 19:40:22 +03:00
Dmitry Stogov
bd44c565b1 Merge branch 'PHP-8.1'
* PHP-8.1:
  Added test
  Fix type inference for assign to string offset with invalid index.
2022-01-10 16:06:08 +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
Nikita Popov
0698bf794f Add helper for convertion to CHECK_VAR/FREE/NOP
This is a recurring pattern whenever an instruction with an
operand is deleted.
2021-12-30 12:44:57 +01:00
Nikita Popov
7d2f2a1005 Remove an incorrect JMPZNZ optimization
This is already skipped for TMP/VAR, but also needs to be skipped
for CV, because we need to insert CHECK_VAR in that case, if we're
being pedantic. That leaves us with CONST as the only case
we can handle, which is already covered by constant folding.

This optimization never actually triggers in our tests, so it's
not a big loss.
2021-12-30 12:06:19 +01:00
Dmitry Stogov
3319f17650 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix reference contig inference
2021-12-28 10:02:48 +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
eb43f8a4f8 Eliminate more VERIFY_RETURN_TYPE instructions 2021-12-27 23:40:21 +03:00
Dmitry Stogov
a066b809de Skip abstract methods 2021-12-27 15:28:46 +03:00
Dmitry Stogov
2759e6bc69 Fixed assertion when check "instanceof" on unlinked class 2021-12-27 12:02:13 +03:00
Nikita Popov
e45653c089 Make sure SCCP can evaluate all functions pass1 can
Move evaluation of ini_get() into eval_special_func_call() and
use this helper both in pass1 and sccp.
2021-12-26 15:40:35 +01:00
Nikita Popov
1050edaef8 Extract special function evaluation from pass1
Pass1 handles a number of special functions that can be evaluated
under some circumstances. Move the core logic into a separate
helper, as I believe that SCCP should reuse this.
2021-12-26 15:40:35 +01:00
Nikita Popov
c4334fc616 Remove special chr/count handling in sccp function evaluation
These can be handled by the generic code. Worth noting that count
will usually go through ZEND_COUNT, and chr on constants is
evaluated in the compiler, so these are not particularly compile-time
sensitive either.
2021-12-26 09:55:18 +01:00
Nikita Popov
924e875651 Minor code cleanup in pass1
Move literal destruction into helper and use a common result
variable to make code more compact.
2021-12-26 09:48:06 +01:00
Nikita Popov
206d80e11a Reuse get_class_entry_from_op1() helper
Export and reuse this helper in places that fetch a class entry
from op1.
2021-12-25 22:18:50 +01:00
Nikita Popov
2cf93032ee Sink op_array scope case into get_class_entry()
This handles references to the current class through its name
rather than self (and for cases where is is not linked yet and
thus not covered by the context lookup). Rather than handling this
only for FETCH_CLASS_CONSTANT optimization, integrate this into
the generic get_class_entry() utility.
2021-12-25 21:51:29 +01:00
Nikita Popov
046096f265 Remove outdated FETCH_CLASS handling in FETCH_CLASS_CONSTANT optimization
Nowadays self::X is represented using an UNUSED operand with
FETCH_CLASS_SELF flag rather than a separate FETCH_CLASS instruction.
The code already handles the new pattern.
2021-12-25 21:00:07 +01:00
Nikita Popov
f6dce4a8ca Extract common replacement login in pass1
The replace const or replace with QM_ASSIGN pattern is common to
all constant folding, extract it into a function.
2021-12-25 20:56:25 +01:00
Nikita Popov
52676f2b7e Remove unnecessary wrapper function
This seems to date back to a time where zval_ptr_dtor was a macro
implicitly passing additional parameters.
2021-12-25 17:39:05 +01:00
Nikita Popov
0884048401 Don't exclude arrays from constant collection
These are supported as constants nowadays, so we can drop the
string check.

Also fix a potential leak, though I believe this doesn't matter in
current usage, as it will effectively be suppressed during persist.
2021-12-25 17:32:18 +01:00
Nikita Popov
7eae7e5e54 Remove FETCH_CLASS+INSTANCEOF special case
Instead propagate the FETCH_CLASS return value, so it can be
directly replaced if possible, which will also eliminate the
FETCH_CLASS subsequently.
2021-12-25 16:45:38 +01:00
Nikita Popov
92e7cf5962 Move FETCH_CLASS+INSTANCEOF special case out of update_op1_const()
The generic code was rejecting this to go into a special code path
in SCCP. We should directly do that in SCCP instead, to still allow
the generic (and valid) replacement.
2021-12-25 16:32:02 +01:00
Nikita Popov
98dfde2c14 Remove unnecessary INSTANCEOF special case in sccp
While we can't replace the instanceof operand, we will evaluate
the instanceof to false and replace its result anyway. Even in
cases where the instanceof user cannot be replaced, we already
have generic code to convert the opcode to QM_ASSIGN in that
case.
2021-12-25 13:02:10 +01:00
Nikita Popov
36dafade51 Remove unnecessary try_replace_op1() special cases
update_op1_const() can handle these nowadays.
2021-12-25 12:39:52 +01:00
Nikita Popov
4ad9dbbac9 Don't replace SEND opcodes with different by-ref behavior
update_op1_const() implements the right logic here -- these cannot
be replaced by different opcodes, as the by-ref passing behavior
is not the same.
2021-12-25 12:34:02 +01:00
Nikita Popov
46d1e503dd Remove redundant code in zend_optimizer_replace_by_const()
zend_optimizer_update_op1_const() already handles these cases.
2021-12-25 12:18:12 +01:00
Dmitry Stogov
8b23538034 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix memory leak in SCCP
2021-12-24 13:11:09 +03:00
Dmitry Stogov
b2939b636d Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix memory leak in SCCP
2021-12-24 13:10:58 +03:00
Tyson Andre
32e2d97a26
Allow internal functions to declare if they support compile-time evaluation, add functions. (#7780)
https://wiki.php.net/rfc/strtolower-ascii means that these functions no longer
depend on the current locale in php 8.2. Before that, this was unsafe to
evaluate at compile time.

Followup to GH-7506

Add strcmp/strcasecmp/strtolower/strtoupper functions

Add bin2hex/hex2bin and related functions

Update test of garbage collection using strtolower to use something else to create a refcounted string
2021-12-20 09:27:06 -05:00
Dmitry Stogov
e4cf3f7420 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix incorrect optimization of ASSIGN_OP that may lead to memory leak
2021-12-20 15:17:45 +03:00
Dmitry Stogov
ca3f7b0a73 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix incorrect optimization of ASSIGN_OP that may lead to memory leak
2021-12-20 15:17:30 +03:00
Dmitry Stogov
6b60dc29de Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference for INIT_ARRAY with invalid index
2021-12-20 11:46:45 +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
2337c0516a Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix incorrect optimization that leads to memory leak
2021-12-13 13:25:47 +03:00
Dmitry Stogov
f8f0a650a7 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix incorrect optimization that leads to memory leak
2021-12-13 13:09:05 +03:00
Christoph M. Becker
fe2c13cda4
Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-7759: Incorrect return types for hash() and hash_hmac()
2021-12-12 15:47:39 +01:00
Christoph M. Becker
a708db9c8a
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-7759: Incorrect return types for hash() and hash_hmac()
2021-12-12 15:47:19 +01:00
Dmitry Stogov
bdcef24f4b Merge branch 'PHP-8.1'
* PHP-8.1:
  Remove range inference for booleans.
2021-12-10 14:44:21 +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
abcf68387d Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix incorrect JMP optimization
2021-12-10 01:45:03 +03:00
Dmitry Stogov
363434bab2 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix incorrect JMP optimization
2021-12-10 01:44:55 +03:00
Nikita Popov
09e991f39f Merge branch 'PHP-8.1'
* PHP-8.1:
  Don't convert assign op operand types in opcache
2021-12-06 21:57:29 +01:00
Nikita Popov
cf377eefa6 Don't convert assign op operand types in opcache
This is the same change as 56b18d478e
but for ASSIGN_OP. Changing the operand type may change the error
message and can result in different behavior with operator overloading.

As with the other patch, if there is strong interest this could be
added to the DFA pass instead, with an appropriate type check.
2021-12-06 21:56:04 +01:00
Dmitry Stogov
8a5c604c3e Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed incorrect DCE of a constructor call
2021-12-06 16:00:39 +03:00
Dmitry Stogov
572c09d373 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed incorrect DCE of a constructor call
2021-12-06 16:00:30 +03:00
Dmitry Stogov
ebb7b173b0 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix refcount inferemce ($a += $a returns old array with RCN)
2021-12-06 11:32:02 +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
923bd51599 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix SCDF cleanup of unused basic block, kept only because of FREE of a loop var
2021-12-01 18:04:47 +03:00
Dmitry Stogov
c3766c08f4 Fix SCDF cleanup of unused basic block, kept only because of FREE of a loop var
Fixes oss-fuzz #41516
2021-12-01 18:03:08 +03:00
Dmitry Stogov
c2aea6e805 Merge branch 'PHP-8.1'
* PHP-8.1:
  JIT: Fix incorrect reference counting inference
2021-11-30 13:00:13 +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
e1baef1835 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed type inference (it's safe to ignore reference counting narrowing)
2021-11-29 23:40:49 +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
8cdead1568 Merge branch 'PHP-8.1'
* PHP-8.1:
  JIT: Fix exception handling when next array element is already occupied
2021-11-29 21:57:38 +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
ee38e3ac37 Merge branch 'PHP-8.1'
* PHP-8.1:
  Disable type narrowing optimization when we contruct SSA for JIT
2021-11-29 15:54:53 +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
Nikita Popov
902d64390e Deprecate implicit dynamic properties
Writing to a proprety that hasn't been declared is deprecated,
unless the class uses the #[AllowDynamicProperties] attribute or
defines __get()/__set().

RFC: https://wiki.php.net/rfc/deprecate_dynamic_properties
2021-11-26 14:10:11 +01:00
Dmitry Stogov
7dcf853235 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed incorrect narrowing to double
2021-11-25 15:16:03 +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
35786e321b Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed incorrect refcountion inference for BW_NOT
2021-11-25 13:53:35 +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
40b258fb78 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed incorrect DCE for ADD_ARRAY_ELEMENT instruction
2021-11-25 13:36:04 +03:00
Dmitry Stogov
97f0c0b189 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed incorrect DCE for ADD_ARRAY_ELEMENT instruction
2021-11-25 13:35:54 +03:00
Nikita Popov
b9165671d5 Verify that used SSA variables are defined
There should either be a defining instruction, defining phi, or
it should be an undef entry variable.
2021-11-25 11:18:36 +01:00
Nikita Popov
71b2f46798 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix bug #81652
2021-11-24 15:20:38 +01:00
Nikita Popov
51ae5c5397 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix bug #81652
2021-11-24 15:19:33 +01:00
Nikita Popov
1845b712e7 Remove commented code in pass1
This has been disabled for a long time, and the whole optimization
is no longer relevant given changes in PHP 8.1
2021-11-18 14:51:55 +01:00
Máté Kocsis
d608319529
Merge branch 'PHP-8.1'
* PHP-8.1:
  Add more specific array return type hints for various extensions - part 2
  Add the --generate-optimizer-info option to the help of gen_stub.php
2021-11-17 10:57:01 +01:00
Máté Kocsis
20fb26e55c
Add more specific array return type hints for various extensions - part 2
ext/ftp, ext/gmp, ext/intl

Closes GH-7433
2021-11-17 10:56:27 +01:00
Dmitry Stogov
e1c561508d Merge branch 'PHP-8.1'
* PHP-8.1:
  Optimize closures nested in other closures
2021-11-15 13:33:23 +03:00
Dmitry Stogov
f313b65acb Optimize closures nested in other closures 2021-11-15 13:32:42 +03:00
Dmitry Stogov
b976e75def Merge branch 'PHP-8.1'
* PHP-8.1:
  JIT: Fixed reference-counting inference
2021-11-15 10:40:51 +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
Dmitry Stogov
b7f19f2674 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed incorrect reference counter inference
2021-11-08 20:55:09 +03:00
Dmitry Stogov
9bd490dc33 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed incorrect reference counter inference
2021-11-08 20:54:45 +03:00
Nikita Popov
e506564e08 Merge branch 'PHP-8.1'
* PHP-8.1:
  Drop pi nodes for both old/new pred in replace_predecessor
2021-11-08 14:58:42 +01:00
Nikita Popov
e5c2ad45dd Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Drop pi nodes for both old/new pred in replace_predecessor
2021-11-08 14:57:16 +01:00
Máté Kocsis
fdf63bfef3
Merge branch 'PHP-8.1'
* PHP-8.1:
  Add more specific array return type hints for various extensions - part 1
2021-11-07 08:48:49 +01:00
Máté Kocsis
d02b9b953d
Add more specific array return type hints for various extensions - part 1
ext/bz2, ext/calendar, ext/dba, ext/enchant

Closes GH-7432
2021-11-07 08:46:25 +01:00
Dmitry Stogov
e465218e35 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed type inference for FETCH_DIM_W without use
2021-11-03 19:45:42 +03:00
Dmitry Stogov
22a171a0b5 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed type inference for FETCH_DIM_W without use
2021-11-03 19:45:30 +03:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Dmitry Stogov
bcef615959 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed incorrect assumption about reference counting
2021-11-01 20:29:27 +03:00
Dmitry Stogov
d4a7e4d1ff Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed incorrect assumption about reference counting
2021-11-01 20:28:33 +03:00
Nikita Popov
b4f2b24430 Merge branch 'PHP-8.1'
* PHP-8.1:
  Handle FETCH_DIM_R after FETCH_DIM_FUNC_ARG in inference
2021-11-01 14:27:22 +01:00
Nikita Popov
a89546d8b3 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Handle FETCH_DIM_R after FETCH_DIM_FUNC_ARG in inference
2021-11-01 14:27:14 +01:00
Nikita Popov
b41adb16cd Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix range inference hang
2021-11-01 12:32:15 +01:00
Nikita Popov
3d38960979 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix range inference hang
2021-11-01 12:32:04 +01:00
Nikita Popov
8d1db82c32 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix scdf loop var free check for phi vars
2021-11-01 11:04:23 +01:00
Nikita Popov
64878757be Fix scdf loop var free check for phi vars
The variable may come from a phi node, in which case we should
take the defining block from it.

Fixes oss-fuzz #40453.
2021-11-01 11:03:17 +01:00
Nikita Popov
b743cd72d0 Fix inference if FETCH_DIM_W user optimized away
In this case the user may be a FREE.

Also add the test file that I forgot in
3ce472d1a6.
2021-10-21 09:58:07 +02:00
Nikita Popov
e7a5ec5fd9 Merge branch 'PHP-8.1'
* PHP-8.1:
  Handle operand replacement in JMP_NULL
2021-10-19 15:19:39 +02:00
Nikita Popov
1f19401ffa Handle operand replacement in JMP_NULL
In this case it's not sufficient to replace the JMP_NULL operand,
as it keeps the temporary alive and there may be more uses later.
Fix this by generalizing existing handling for other similar opcodes
like CASE/SWITCH and LIST_R.

Fixes oss-fuzz 5820123475214336.
2021-10-19 15:19:02 +02:00
Dmitry Stogov
564d54192f Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed incorrect optimization that may cause JIT assertion
2021-10-18 23:21:01 +03:00
Dmitry Stogov
bdebefaa61 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed incorrect optimization that may cause JIT assertion
2021-10-18 23:20:53 +03:00
Nikita Popov
a00446ca90 Merge branch 'PHP-8.1'
* PHP-8.1:
  Don't replace tmp with cv in YIELD argument
2021-10-12 14:27:13 +02:00
Nikita Popov
9c1d7b43e9 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Don't replace tmp with cv in YIELD argument
2021-10-12 14:27:07 +02:00
Dmitry Stogov
176c319109 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed type inference for COPY_TMP
2021-10-11 16:56:49 +03:00
Dmitry Stogov
1208fe932a Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed type inference for COPY_TMP
2021-10-11 16:56:40 +03:00
Nikita Popov
9ecec661ce Merge branch 'PHP-8.1'
* PHP-8.1:
  Preserve key/value type invariant in range() type inference
2021-10-11 12:42:06 +02:00
Nikita Popov
f0cf999223 Preserve key/value type invariant in range() type inference
Don't set PACKED key type if no value type is set.

Fixes oss-fuzz 6718410667458560.
2021-10-11 12:41:46 +02:00
Dmitry Stogov
f440894d9f Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed type inference (ASSIGN_OP with typed reference may cause type conversion)
2021-10-11 10:50:15 +03:00
Dmitry Stogov
04064187c2 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed type inference (ASSIGN_OP with typed reference may cause type conversion)
2021-10-11 10:50:06 +03:00
Nikita Popov
c6a4fb3911 Merge branch 'PHP-8.1'
* PHP-8.1:
  Regenerate optimizer info
2021-10-08 11:41:10 +02:00
Nikita Popov
41789e1fc9 Regenerate optimizer info
While the stub definitions were updated, the generated optimizer
info was stale.
2021-10-08 11:40:38 +02:00
Nikita Popov
bce040ddf2 Merge branch 'PHP-8.1'
* PHP-8.1:
  Set opline before calling undef op helper
  Add more specific array return type hints for various extensions - part 6 (#7474)
2021-10-07 14:40:48 +02:00
Máté Kocsis
d9e5e63032
Add more specific array return type hints for various extensions - part 6 (#7474) 2021-10-07 14:29:29 +02:00
Dmitry Stogov
c84c07e2db Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed type inference that may cause JIT failure
2021-10-06 14:58:47 +03:00
Dmitry Stogov
0b5d62e39c Fixed type inference that may cause JIT failure
PHP allows to override a method that returns non-reference with a method
that returns a reference. This mean that we cannot use prototypes to
predict return types of a child functions.
2021-10-06 14:55:34 +03:00
Nikita Popov
aa2f8311c6 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix array cast type inference wrt packed arrays
2021-10-06 10:51:30 +02:00
Nikita Popov
3661c1932c Fix array cast type inference wrt packed arrays
Use KEY_LONG instead of PACKED if it's possible for the array to
be empty. It won't be packed in that case.

Fixes oss-fuzz #39650.
2021-10-06 10:50:44 +02:00
Nikita Popov
43b3cf110f Merge branch 'PHP-8.1'
* PHP-8.1:
  Don't start new block after loop free
2021-10-06 10:13:24 +02:00
Nikita Popov
f455894bb6 Don't start new block after loop free
This reverts the change from 493c91c742.
Starting a new block means that in the common case where the loop var
free is not unreachable, we'll always merge back the block.

Instead fix the original problem by explicitly removing instructions
apart from the loop var free in block pass.
2021-10-06 10:13:15 +02:00
Dmitry Stogov
2f5cc67eba Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed SSA construction
2021-10-05 16:16:38 +03:00
Dmitry Stogov
41dc14792e Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed SSA construction
2021-10-05 16:14:58 +03:00
Nikita Popov
3dcf52c20e Merge branch 'PHP-8.1'
* PHP-8.1:
  POST_INC_OBJ/POST_DEC_OBJ don't have optional result
2021-10-05 12:06:09 +02:00
Nikita Popov
20a784e026 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  POST_INC_OBJ/POST_DEC_OBJ don't have optional result
2021-10-05 12:05:57 +02:00
Nikita Popov
d1aff29a04 Merge branch 'PHP-8.1'
* PHP-8.1:
  Start new block after loop free
2021-10-04 17:02:40 +02:00
Nikita Popov
493c91c742 Start new block after loop free
In the attached test case we ended up not updating a leftover
MATCH jump in the unreachable_free block. There's different ways
this can be addressed, but in this case we can just make sure that
a new block is started after the loop free, which will allow it
to be dropped as unreachable. We only need to retain the free
itself for live-range reconstruction.

Fixes oss-fuzz #39516.
2021-10-04 16:59:46 +02:00
Nikita Popov
5bf088f6eb Move TYPE_CHECK handling from sccp to inference
The handling of TYPE_CHECK makes for an awkward special case,
because it is determined outside the usual SCCP framework. Instead
move the logic into type inference (to infer a more specific
may_be_true or may_be_false if possible). This will get picked up
by SCCP through the existing logic to make use of type and range
information.

However, this also requires us to make use of type info in
feasible edge marking, otherwise we would regress existing
optimization power.
2021-10-01 15:56:22 +02:00
Nikita Popov
6858ad123e Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix cache slot assignment for ASSIGN_OBJ_OP
2021-09-30 14:35:07 +02:00
Nikita Popov
5cdbfa897c Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix cache slot assignment for ASSIGN_OBJ_OP
2021-09-30 14:34:50 +02:00
Nikita Popov
c19977d054 Fix delayed early binding with optimization
It's possible for delayed early binding opcodes to get optimized
away if they are "unreachable". However, we still need to attempt
early binding for them. (In some cases we also corrupt the early
binding list outright during optimization, which is how I got here.)

Fix this by storing information about delayed early binding
independently of DECLARE_CLASS_DELAYED opcodes, so early binding is
performed even after the opcode has been dropped.
2021-09-29 18:00:20 +02:00
Nikita Popov
e7a0c5b8c8 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix inference for INIT_ARRAY with illegal offset type
2021-09-29 11:09:22 +02:00
Nikita Popov
944d653b3d Fix inference for INIT_ARRAY with illegal offset type
Extract assign_dim_array_result_type() helper that can be reused
for INIT_ARRAY and implements all this logic correctly.

Fixes oss-fuzz 5156868775870464.
2021-09-29 11:09:04 +02:00
Nikita Popov
8b7874b262 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix ASSIGN_DIM result inference with typed refs
  Remove outdated code in ASSIGN_DIM type inference
2021-09-28 14:14:41 +02:00
Nikita Popov
69eb6e04a7 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix ASSIGN_DIM result inference with typed refs
  Remove outdated code in ASSIGN_DIM type inference
2021-09-28 14:14:29 +02:00
Nikita Popov
25c264245b Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix type inference and SCCP with typed references
2021-09-28 12:59:33 +02:00
Nikita Popov
2b71df71a1 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference and SCCP with typed references
2021-09-28 12:59:24 +02:00
Nikita Popov
223370e506 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix block marking for two arm math
2021-09-28 10:38:34 +02:00
Nikita Popov
1e4a9a4999 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix block marking for two arm math
2021-09-28 10:38:22 +02:00
Nikita Popov
2dd61521f2 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix relative offsets when copying JMPZNZ
2021-09-27 16:20:21 +02:00
Nikita Popov
0015fc9a8e Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix relative offsets when copying JMPZNZ
2021-09-27 16:20:04 +02:00
Nikita Popov
3981f43058 Merge branch 'PHP-8.1'
* PHP-8.1:
  Start block at loop var free
2021-09-27 11:59:03 +02:00
Nikita Popov
b86fdf84f0 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Start block at loop var free
2021-09-27 11:58:53 +02:00
Nikita Popov
52c6fcbf45 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix DCE of unreachable phi in cycle
2021-09-27 11:27:03 +02:00
Nikita Popov
b7ec15f7fe Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix DCE of unreachable phi in cycle
2021-09-27 11:26:56 +02:00
Nikita Popov
78bd138232 Merge branch 'PHP-8.1'
* PHP-8.1:
  Handle pi nodes in replace_predecessor
2021-09-27 10:48:35 +02:00
Nikita Popov
d5e80c1c0c Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Handle pi nodes in replace_predecessor
2021-09-27 10:48:23 +02:00
Nikita Popov
2157d11ddc Merge branch 'PHP-8.1'
* PHP-8.1:
  Don't treat expression exit as terminator
2021-09-23 10:26:34 +02:00
Nikita Popov
c9762be566 Don't treat expression exit as terminator
Same as with throw expressions, this may remove later temporary
consuming instructions and thus eliminate live ranges, resulting
in a memory leak. We make use of the same hack and don't consider
exit a terminator if used in an expression context.
2021-09-23 10:26:07 +02:00
Nikita Popov
aa285a015f Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix ASSIGN_STATIC_PROP_REF type inference
2021-09-22 15:55:57 +02:00
Nikita Popov
2dc8c7b3a7 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix ASSIGN_STATIC_PROP_REF type inference
2021-09-22 15:55:42 +02:00
Dmitry Stogov
dd73e5a0b6 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed type inference
2021-09-22 15:32:24 +03:00
Dmitry Stogov
cffba945e5 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fixed type inference
2021-09-22 15:32:16 +03:00
Nikita Popov
2067388fe6 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix range() return type inference for undef operand
2021-09-21 17:04:12 +02:00
Nikita Popov
a846547ed4 Fix range() return type inference for undef operand
This results in a long range.
2021-09-21 17:03:18 +02:00
Nikita Popov
e05f36651b Merge branch 'PHP-8.1'
* PHP-8.1:
  Don't unconditionally add array value type for undef
2021-09-21 14:54:42 +02:00
Nikita Popov
37337507ec Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Don't unconditionally add array value type for undef
2021-09-21 14:54:34 +02:00
Nikita Popov
7e565daad9 Fix incorrect use chain unlink
This issue has been introduced in 87ea3c1f4c,
where an || has been misinterpreted as an &&.
2021-09-21 14:35:45 +02:00
George Peter Banyard
44bc955619 Check against FAILURE instead of different then SUCCESS 2021-09-21 11:35:53 +01:00
George Peter Banyard
f345f6d529 Voidify zend_optimize_script()
It always returned 1

As a consequence voidify preload_optimize()
2021-09-21 11:35:53 +01:00
George Peter Banyard
4818765560 Voidify zend_worklist_prepare()
It always returned SUCCESS
2021-09-21 11:35:53 +01:00
George Peter Banyard
87ea3c1f4c Voidify zend_ssa_unlink_use_chain()
It always returned 1 or threw an assertion failure

Also drop else branch by moving it to the main scope
2021-09-21 11:35:53 +01:00
George Peter Banyard
35dfdd9b1b Voidify zend_ssa_compute_use_def_chains()
It always returned SUCCESS
2021-09-21 11:35:53 +01:00
George Peter Banyard
25deb7d254 Voidify zend_mark_cv_references()
It always returned SUCCESS
2021-09-21 11:35:53 +01:00
George Peter Banyard
85634c9c1c Voidify zend_infer_ranges()
It always returned SUCCESS
2021-09-21 11:35:53 +01:00