Commit graph

48 commits

Author SHA1 Message Date
Dmitry Stogov
fa75bd0785 Fix incorrect constant propagation for VERIFY_RETURN_TYPE
This fixes oss-fuzz #48104
2022-06-20 11:30:07 +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
Dmitry Stogov
462d00f548 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix memory leak
2022-05-16 13:48:51 +03:00
Dmitry Stogov
c430116a11 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix memory leak
2022-05-16 13:48:40 +03:00
Arnaud Le Blanc
332bd03782
Do not optimize out ini_get() when the entry does not exist during compilation (#8507)
The entry may exist later if dl is enabled

Fixes GH-8466
2022-05-13 12:35:00 +02:00
Dmitry Stogov
6ed3b57e67 Fix incorrect constant propagation for VERIFY_RETURN_TYPE
Fixes oss-fuzz #46616
2022-04-18 10:33:52 +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
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
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
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
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
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
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
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
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
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
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
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
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
George Peter Banyard
44bc955619 Check against FAILURE instead of different then SUCCESS 2021-09-21 11:35:53 +01:00
George Peter Banyard
53d5420d49 Use more appropriate types in Optimizer
Mainly using zend_result and bool instead of int
2021-09-21 11:35:53 +01:00
Nikita Popov
55582a2527 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Don't replace values in unreachable code in sccp
2021-09-20 13:12:43 +02:00
Nikita Popov
3191f83146 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Don't const evaluate increment of array in SCCP
2021-09-16 14:43:28 +02:00
Nikita Popov
54bbee96ba Check for no uses before removing result operand
It's possible for there to still be phi uses.
2021-09-14 13:20:28 +02:00
Nikita Popov
fa3d603ba2 Mark ASSIGN result as UNUSED in SCCP
We can't drop the ASSIGN entirely, but we should mark the result
as UNUSED. Otherwise we'll replace uses of it in operands and
will not free the ASSIGN result value. This can happen with
non-interned strings, but possibly there's some other cases that
can trigger this as well.
2021-09-14 13:16:51 +02:00
Nikita Popov
273720dcf2 Add str_replace/array_unique to ct eval list
Taken from GH-5870.
2021-07-19 15:31:26 +02:00
Kamil Tekiela
7bbc85f16a
Sccp new functions for ct (#7220)
* strstr

* explode
2021-07-08 10:00:26 +01:00
George Peter Banyard
b6958bb847
Implement "Deprecate implicit non-integer-compatible float to int conversions" RFC. (#6661)
RFC: https://wiki.php.net/rfc/implicit-float-int-deprecate

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-05-31 15:48:45 +01:00
KsaR
01b3fc03c3
Update http->https in license (#6945)
1. Update: http://www.php.net/license/3_01.txt to https, as there is anyway server header "Location:" to https.
2. Update few license 3.0 to 3.01 as 3.0 states "php 5.1.1, 4.1.1, and earlier".
3. In some license comments is "at through the world-wide-web" while most is without "at", so deleted.
4. fixed indentation in some files before |
2021-05-06 12:16:35 +02:00
Nikita Popov
c4a749c932 Remove php includes from sccp.c 2021-04-20 12:26:12 +02:00
twosee
c457be80dd
Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #80900
2021-04-14 00:21:37 +08:00
George Peter Banyard
5caaf40b43
Introduce pseudo-keyword ZEND_FALLTHROUGH
And use it instead of comments
2021-04-07 00:46:29 +01:00
Nikita Popov
2d0e2733c8 Support prototypes in call graph
Even if we don't know the exact method being called, include it
in the call graph with the is_prototype flag. In particular, we
can still make use of return types from prototype methods, as
PHP 8 makes LSP violations a hard error.

Most other places are adjusted to skip calls with !is_prototype.
Maybe some of them would be fine, but ignoring them is conservative.
2021-03-19 10:49:15 +01:00
Nikita Popov
4c088c5da7 Handle warnings during sccp function evaluation
Some upcoming changes like https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
will make it somewhat inconvenient to determine whether a given
function invocation will generate a diagnostic. Rather than trying
to exclude this in advance, call the function with diagnostics
suppressed, and check whether anything was thrown.

This adds a new EG flag that is kept specific to the SCCP use-case.
This does not use the error_cb hook as it is a (non-TLS) global,
and doesn't fully suppress error handling besides.

Test this by removing the in advance checks for implode and array_flip.
2021-02-11 12:36:35 +01:00
Nikita Popov
27cd7a11cb Add support for string keys in array unpacking
This adds support for:

    $array1 = ['a' => 1, 'b' => 2];
    $array2 = ['b' => 3, 'c' => 4];
    $array = [...$array1, ...$array2];
    // => ['a' => 1, 'b' => 3, 'c' => 4]

RFC: https://wiki.php.net/rfc/array_unpacking_string_keys

Closes GH-6584.
2021-02-09 10:04:27 +01:00
Nikita Popov
83be073abe Move optimizer into core
This only moves the files, adjusts the build system, exports APIs
and does minor fixups to make sure the code builds.

This does not yet try to make the optimizer usable independently
of opcache.

Closes GH-6642.
2021-01-28 10:38:25 +01:00
Renamed from ext/opcache/Optimizer/sccp.c (Browse further)