Commit graph

58 commits

Author SHA1 Message Date
Ilija Tovilo
631bc81607
Implement stackless internal function calls
Co-authored-by: Dmitry Stogov <dmitry@zend.com>

Closes GH-12461
2024-02-06 17:42:28 +01:00
George Peter Banyard
d8696f9216
[RFC] Path to Saner Increment/Decrement operators (#10358)
* Add behavioural tests for incdec operators

* Add support to ++/-- for objects castable to _IS_NUMBER

* Add str_increment() function

* Add str_decrement() function

RFC: https://wiki.php.net/rfc/saner-inc-dec-operators

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
2023-07-17 15:51:24 +01:00
Ilija Tovilo
0b1d750d91
Allow arbitrary expressions in static variable initializer
Closes GH-9301
2023-05-24 20:17:31 +02:00
Niels Dossche
5c058d7b15 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10801: Named arguments in CTE functions cause a segfault
2023-03-10 19:31:19 +01:00
Niels Dossche
c4508422eb Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10801: Named arguments in CTE functions cause a segfault
2023-03-10 19:27:17 +01:00
Niels Dossche
2c53d63197 Fix GH-10801: Named arguments in CTE functions cause a segfault
Fixes GH-10801

Named arguments are not supported by the constant evaluation routine, in
the sense that they are ignored. This causes two issues:
  - It causes a crash because not all oplines belonging to the call are
    removed, which results in SEND_VA{L,R} which should've been removed.
  - It causes semantic issues (demonstrated in the test case).

This case never worked anyway, leading to crashes or incorrect behaviour,
so just prevent CTE of calls with named parameters for now.
We can choose to support it later, but introducing support for this in
a stable branch seems too dangerous.

This patch does not change the removal of SEND_* opcodes in remove_call
because the crash bug can't be triggered anymore with this patch as
there are no named parameters anymore and no variadic CTE functions
exist.

Closes GH-10811.
2023-03-10 19:22:44 +01:00
Max Kellermann
d5c649b36b
zend_compiler, ...: use uint8_t instead of zend_uchar (#10621)
`zend_uchar` suggests that the value is an ASCII character, but here,
it's about very small integers.  This is misleading, so let's use a
C99 integer instead.

On all architectures currently supported by PHP, `zend_uchar` and
`uint8_t` are identical.  This change is only about code readability.
2023-02-23 14:56:54 +00:00
Max Kellermann
49c1e6eb33
Make various pointers const in Zend/ (#10608)
* Zend/zend_operators: pass const pointers to zend_is_identical()

* Zend/zend_operators: pass const pointers to zend_get_{long,double}()

* Zend/Optimizer/sccp: make pointers const

* Zend/Optimizer/scdf: make pointers const

* Zend/Optimizer/zend_worklist: make pointers const

* Zend/Optimizer/zend_optimizer: make pointers const

* Zend/zend_compile: make pointers const
2023-02-20 14:00:59 +00:00
Christoph M. Becker
2f4973fd88
Revert GH-10279
Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit 45a128c9de.
This reverts commit 1eb71c3f15.
This reverts commit 492523a779.
This reverts commit c7a4633891.
This reverts commit 308adb915c.
This reverts commit cd27d5e07f.
This reverts commit c5933409b4.
This reverts commit 46371f4eb3.
This reverts commit 623e2e9fc6.
This reverts commit e7434c1247.
This reverts commit d28d323ca2.
This reverts commit 1a067b84ee.
This reverts commit a55c0c5fc3.
This reverts commit b5aeb3a4d4.
This reverts commit f061a035e4.
This reverts commit b088575119.
This reverts commit b1d48774a7.
This reverts commit 94f9a20ce6.
This reverts commit 4831e48708.
This reverts commit cd985de190.
This reverts commit 9521d21681.
This reverts commit d6136151e9.
2023-01-16 12:25:59 +01:00
Max Kellermann
308adb915c Zend/Optimizer/sccp: include cleanup 2023-01-12 15:12:45 +00:00
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