Commit Graph

496 Commits

Author SHA1 Message Date
Kirill Nesmeyanov
b495a916a4
Add string output escaping into zend dump (phpdbg + opcache debug) (#11337)
* Add string output escaping into zend dump (phpdbg + opcache debug)

* Use ZSTR_VAL macro instead direct string access

* Move "escaped_string" into local switch/case scope

* Add zend_string_release

* Add Z_STR_P macro instead direct string access

* Merge zend_string declaration and its assigment in one stmt
2023-05-29 16:45:00 +03:00
Ilija Tovilo
0b1d750d91
Allow arbitrary expressions in static variable initializer
Closes GH-9301
2023-05-24 20:17:31 +02:00
nielsdos
24ff7eee3f Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-11245 (In some specific cases SWITCH with one default statement will cause segfault)
2023-05-23 00:36:55 +02:00
nielsdos
f6563442db Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-11245 (In some specific cases SWITCH with one default statement will cause segfault)
2023-05-23 00:34:33 +02:00
Niels Dossche
5cad1a7176 Fix GH-11245 (In some specific cases SWITCH with one default statement will cause segfault)
The block optimizer pass allows the use of sources of the preceding
block if the block is a follower and not a target. This causes issues
when trying to remove FREE instructions: if the source is not in the
block of the FREE, then the FREE and source are still removed. Therefore
the other successor blocks, which must consume or FREE the temporary,
will still contain the FREE opline. This opline will now refer to a
temporary that doesn't exist anymore, which most of the time results in
a crash. For these kind of non-local scenarios, we'll let the SSA
based optimizations handle those cases.

Closes GH-11251.
2023-05-23 00:33:25 +02:00
Alex Dowad
97e29bed9e Use shared, immutable array for return value of mb_list_encodings
This will allow us to easily check in other mbstring functions if the
list of all supported encodings, returned by mb_list_encodings, is
passed in as input to another function.

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
2023-05-16 07:01:07 -07:00
nielsdos
41cda46b70 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix too wide OR and AND range inference
2023-05-02 20:20:15 +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
Ilija Tovilo
a00e2233e3
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix incorrect match default branch optimization
2023-04-26 15:20:35 +02:00
Ilija Tovilo
368dd81faa
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix incorrect match default branch optimization
2023-04-26 15:20:27 +02:00
Ilija Tovilo
3a76f795f8
Fix incorrect match default branch optimization
Fixes GH-11134
Closes GH-11135
2023-04-26 15:19:20 +02:00
Ilija Tovilo
6f63d4b274
Fix -Wenum-int-mismatch warnings on gcc 13
Closes GH-11103
2023-04-20 16:04:59 +02:00
Dmitry Stogov
0660fb5282 Merge branch 'PHP-8.2'
* PHP-8.2:
  Allow FETCH_OBJ_W and FETCH_STATIC_PROP_W to return INDIRECT/UNDEF zval for uninitialized typed properties (#11048)
2023-04-10 23:25:42 +03: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
Dmitry Stogov
706a9b2a39 Revert "Zend/zend_types.h: move zend_result to separate header (#10609)"
This reverts commit 3bce116069.
2023-04-04 22:48:26 +03:00
Dmitry Stogov
22d5d146e5 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix incorrect optimization
2023-03-27 17:58:35 +03:00
Dmitry Stogov
1f5d9534ae Fix incorrect optimization
Fixes oss-fuzz #57482
2023-03-27 17:57:54 +03:00
Niels Dossche
6a6e91f3c7
Shrink some commonly used structs by reordering members (#10880)
Struct members require some alignment based on their type. This means
that if a struct member is not aligned, there will be a hole created by
the compiler in the struct, which is wasted space. This patch reorders
some of the most commonly used structs, but in such a way that the
fields which were in the same cache line still belong together.
The only exception to this is exception_ignore_args, which was
temporally not close to nearby members, and as such I placed
it further up to close a hole.

On 64-bit Linux this gives us the following shrinks:
* zend_op_array: 248 -> 240
* zend_ssa_var: 56 -> 48
* zend_ssa_var_info: 48 -> 40
* php_core_globals: 672 -> 608
* zend_executor_globals: 1824 -> 1792

On 32-bit, the sizes will either remain the same or will result in
smaller shrinks.
2023-03-22 19:26:42 +01:00
Ilija Tovilo
96a3825849
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix RC1 assumption for typed properties with __get
2023-03-13 10:00:28 +01: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
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
Niels Dossche
f45b3acb90
[ci skip] Add a comment to clarify the value of zend_call_info->num_args (#10812)
This surprised me a couple of times already, and it probably surprised
others too. Add a comment to clarify.
2023-03-09 13:00:21 +00:00
George Peter Banyard
81e59c6497
Improve handling of XML options
Mark boolean options as such
Warn on invalid types
Stubs info

Closes GH-10675
2023-02-26 14:34:39 +00: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
Niels Dossche
821fc55a68
Implement GH-9826: Make class_alias() work with internal classes (#10483)
We can't increase the refcount of internal classes during request time.
To work around this problem we simply don't refcount aliases anymore and
add a check in the destruction to skip aliases entirely.
There were also some checks which checked for an alias implicitly by
comparing the refcount, these have been replaced by checking the type of
the zval instead.
2023-02-22 11:47:32 +01:00
Niels Dossche
2e78c080c6
Improve the optimizer's check if a function is a prototype or not (#10467)
Currently, a function is considered a prototype if the function is not
marked as final. However, a class marked as final also make it
impossible for a function to be overridden. Therefore, we know in this
case too that the function is not a prototype.
This allows the type inference algorithm to determine some types more
precisely, and can allow for more optimizations of the instructions.
Additionally, place some computation of the flags in their respective
blocks as a micro-optimization.

Note: anonymous classes *can* be extended (see test
Zend/tests/anon/011.phpt). Therefore we don't optimize this case.
2023-02-21 00:34:47 +03: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
Max Kellermann
3bce116069
Zend/zend_types.h: move zend_result to separate header (#10609)
Many sources need just `zend_result`, and with this new header, they
only need to include `zend_result.h` instead of `zend_types.h`; the
latter is large and has fat dependencies, which slows down the build.
2023-02-20 13:07:51 +00:00
Dmitry Stogov
bc1d780fef Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix updating SSA object type for *_ASSIGN_OP (#10458)
2023-02-14 11:29:55 +03: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
rj1
d2cdfdbe44
fixed some misspellings (#10503) 2023-02-04 07:03:10 +00:00
Ilija Tovilo
35a36b13e5
Fix comp-time and constant evaluation of dynamic class constant fetch
Fixes GH-10486
Fixes oss-fuzz #55436
Fixes oss-fuzz #55472
Closes GH-10487
2023-02-02 19:18:17 +01:00
Dmitry Stogov
ea37abd412 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix type inference
2023-01-30 13:16:17 +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
Ilija Tovilo
02bd52b5a8
Implement dynamic class const fetch
https://wiki.php.net/rfc/dynamic_class_constant_fetch

Closes GH-9793
2023-01-26 16:46:34 +01:00
Dmitry Stogov
e335630d8b Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix incorrect check condition in type inference (#10425)
2023-01-24 09:32:38 +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
David Carlier
585ac794b4 Merge branch 'PHP-8.2' 2023-01-16 20:44:01 +00:00
David Carlier
385f410e4c Merge branch 'PHP-8.1' into PHP-8.2 2023-01-16 20:43:08 +00:00
Niels Dossche
dfe9c2af19 Fix incorrect comparison in block optimization pass
We're in the case of ZEND_JMPZ_EX or ZEND_JMPNZ_EX. The opcode gets
overwritten and only after the overwriting gets checked if we're in a
JMPZ or JMPNZ case. This results in a wrong optimization.

Close GH-10329
2023-01-16 20:41:33 +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
492523a779 Zend/zend_inference: include cleanup 2023-01-12 15:12:45 +00:00