Commit graph

1681 commits

Author SHA1 Message Date
Nikita Popov
d5c886ab7d Merge branch 'PHP-7.4'
* PHP-7.4:
  Properly propagate url_stat exceptions during include
2019-12-30 22:57:07 +01:00
Nikita Popov
f77747b06c Properly propagate url_stat exceptions during include
Make sure we abort operations early, and that we don't emit
additional warnings or errors if an exception has been thrown.
2019-12-30 22:56:42 +01:00
Nikita Popov
e15915d21c Merge branch 'PHP-7.4'
* PHP-7.4:
  Avoid signed integer overflow in string offset check
2019-12-19 11:48:20 +01:00
Nikita Popov
527ad1d80c Avoid signed integer overflow in string offset check
Cast to size_t before performing operations instead of afterwards.
2019-12-19 11:47:50 +01:00
Nikita Popov
2a76384b87 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix leak in assign_ref with function
2019-12-18 17:18:46 +01:00
Nikita Popov
df08d6bffe Fix leak in assign_ref with function
As far as I can see, the retval copying is already done in all
callers of this function, so it should not be duplicated here.
2019-12-18 17:18:10 +01:00
Nikita Popov
8eabaf7efc Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix const/cv freeing on failed reference assignment
2019-12-18 09:54:18 +01:00
Nikita Popov
0301ab70b3 Fix const/cv freeing on failed reference assignment 2019-12-18 09:54:10 +01:00
Nikita Popov
7194825c86 Fix leak of dynamic property name in address helper 2019-12-17 16:59:35 +01:00
Dmitry Stogov
b1577f5a57 Merge branch 'PHP-7.4'
* PHP-7.4:
  Export zend_init_func_run_time_cache()
2019-12-09 15:58:19 +03:00
Dmitry Stogov
03d1c788ea Export zend_init_func_run_time_cache() 2019-12-09 15:58:00 +03:00
Nikita Popov
aed2bf7ab3 Remove unused function 2019-12-06 14:18:52 +01:00
Nikita Popov
0bac785477 Optimize return type checking
Split off the fast-path case and avoid redundant checks.
2019-12-06 14:17:03 +01:00
Nikita Popov
999e32b65a Implement union types
According to RFC: https://wiki.php.net/rfc/union_types_v2

The type representation now makes use of both the pointer payload
and the type mask at the same time. Additionall, zend_type_list is
introduced as a new kind of pointer payload, which is used to store
multiple class types. Each of the class types is a tagged pointer,
which may be either a class name or class entry. The latter is only
used for typed properties, while arguments/returns will instead use
cache slots. A type list can contain a mix of both names and CEs at
the same time, as not all classes may be resolvable.

One thing this is missing is support for union types in arginfo
and stubs, which I want to handle separately.

I've also dropped the special object code from the JIT implementation
for now -- I plan to add this back in a different form at a later time.
For now I did not want to include non-trivial JIT changes together
with large functional changes.

Another possible piece of follow-up work is to implement "iterable"
as an internal alias for "array|Traversable". I believe this will
eliminate quite a few special-cases that had to be implemented.

Closes GH-4838.
2019-11-08 15:15:48 +01:00
Nikita Popov
ac4e0f0852 Make zend_type a 2-field struct
We now store the pointer payload and the type mask separately. This
is in preparation for union types, where we will be using both at
the same time.

To avoid increasing the size of arginfo structures, the
pass_by_reference and is_variadic fields are now stored as part of
the type_mask (8-bit are reserved for custom use).

Different types of pointer payloads are distinguished based on bits
in the type_mask.
2019-11-08 15:15:48 +01:00
Máté Kocsis
14bdb0cfc7 Fix consistency issues with array accesses warnings/exceptions
* Change a number of "resource used as offset" notices to warnings,
   which were previously missed.
 * Throw the "resource used as offset" warning for isset() as well.
 * Make array_key_exists() behavior with regard to different key
   types consistent with isset() and normal array accesses. All key
   types now use the usual coercions and array/object keys throw
   TypeError.

Closes GH-4887.
2019-11-06 12:56:47 +01:00
Nikita Popov
c46b2ed677 Remove support for array_key_exists() with objects 2019-11-04 13:10:03 +01:00
Nikita Popov
bd7b1afd6e Check type is set when verifying variadic args
Weird that there was no test for this...

This code is somewhat inefficient, because it will be performed
for every arg, rather than only once.
2019-10-25 10:27:45 +02:00
Nikita Popov
d71a6ee54f Remove unnecessary type checks in verify_missing_return_type
We don't emit VERIFY_RETURN_TYPE for void functions, so there's
no need to check it here. It's always an error.
2019-10-24 15:52:06 +02:00
Nikita Popov
9666d7a753 Don't check ZEND_TYPE_IS_SET() in zend_check_type()
Usually this function is only used if we already know that there is
a type. Add checks to the places where we don't.
2019-10-24 15:41:26 +02:00
Nikita Popov
13e0c5f4c9 Merge branch 'PHP-7.4'
* PHP-7.4:
  Don't autoload when checking property types
2019-10-23 12:24:01 +02:00
Nikita Popov
f841388781 Don't autoload when checking property types
Noticed while working on union types: We do not load argument and
return types during type checks, but we do load property types.

I'm normalizing the behavior towards the existing status quo (not
loading), though we may consider loading everywhere (all types,
and instanceof) in order to properly support class aliases.
2019-10-23 12:21:30 +02:00
Nikita Popov
fe6c420b02 JIT: Handle typed refs in assign dim 2019-10-23 11:25:10 +02:00
Nikita Popov
e80934d747 Pass cache slot when printing type errors
Instead of using a separate ce.
2019-10-17 17:06:48 +02:00
Nikita Popov
93b39f68f5 Merge branch 'PHP-7.4' 2019-10-10 15:17:44 +02:00
Nikita Popov
5a076e670a Return error_zval form get_property_ptr_ptr on exception
This goes in the reverse direction of 4463acb951.
After looking around a bit, it seems that we already check for
Z_ISERROR_P() on the get_property_ptr_ptr return value in other places.
So do this in zend_fetch_property_address() as well, and also make
sure that EG(error_zval) is indeed returned on exception in
get_property_ptr_ptr.

In particular, this fixes the duplicate exceptions that we used to
get because first get_property_ptr_ptr threw one and then
read_property throws the same exception again.
2019-10-10 15:14:04 +02:00
Nikita Popov
2118f6a898 Merge branch 'PHP-7.4' 2019-10-10 14:44:53 +02:00
Nikita Popov
4463acb951 Explicitly check for exceptions in by-ref obj prop assign
Relying on setting ERROR if an exception happened during the
property address fetch is both a bit fragile and may pessimize
other codepaths that will check for exceptions in the VM. Adding
an extra exception check instead, which should also allow us to
drop the use of ERROR in this area in master.
2019-10-10 14:41:35 +02:00
Nikita Popov
51501dacb1 Merge branch 'PHP-7.4' 2019-10-10 10:08:32 +02:00
Nikita Popov
382f9b28e8 Fix leak on "Cannot assign by reference to overloaded object" error 2019-10-10 10:07:54 +02:00
Dmitry Stogov
f6f32f2cf0 SAMRT BRANCH improvement.
Avoid need of insertion NOP opcoes between unrelated SMART BRANCH instruction and following JMPZ/JMPNZ.
Now instead of checking the opcode of following instruction, the same information is encoded into SMART BRANH result_type.
2019-10-09 13:48:39 +03:00
Nikita Popov
7c1bc91e52 Merge branch 'PHP-7.4' 2019-10-08 17:19:52 +02:00
Nikita Popov
21148679d1 Handle "non well formed" exception during ZPP
Previously if the "non well formed" notice was converted into an
exception we'd still end up executing the function.

Also drop the now unnecessary EG(exception) checks in the engine.

Additionally remote a bogus exception in zend_is_callable: It
should only be writing to error, but not directly throwing.
2019-10-08 17:17:49 +02:00
Dmitry Stogov
31c3b0c7cc Fixed Zend/tests/bug70785.phpt on builds wothout global regesters 2019-10-08 17:08:59 +03:00
Dmitry Stogov
eec04f6b56 Encapsulate all SMART BRANCH related logic inside macros. Result of SMART BRANCH may be uninitialized (on exception). 2019-10-08 16:37:21 +03:00
Nikita Popov
d98497615c Merge branch 'PHP-7.4' 2019-10-08 14:33:01 +02:00
Nikita Popov
ad3ddf46f9 Fixed bug #78644
Make sure the initialize the result of FETCH_OBJ_UNSET operations.
I'm using a NULL value rather than ERROR here, because the latter
no longer exists in master.
2019-10-08 14:32:49 +02:00
Nikita Popov
57670c6769 Check num required args is correct in debug builds
Also replace the assertion failure with an E_CORE_ERROR that
includes the function name, so these are easier to debug.
2019-10-07 16:34:05 +02:00
Nikita Popov
2f92957fd3 Convert some notices to warnings
Part of https://wiki.php.net/rfc/engine_warnings.
2019-10-02 10:34:08 +02:00
Nikita Popov
01fc1a3057 Remove most uses of the ERROR type
It is now only used to signal exceptions for property reads. ERROR
zvals are never returned back to the VM anymore, so there's no
need to check for them when receiving a VAR.

Also return MAY_BE_ERROR, as ERROR is now no longer relevant for
inference.
2019-09-30 11:35:07 +02:00
Nikita Popov
e8b0163e0b Promote write "use scalar as array" warning to Error 2019-09-27 15:49:18 +02:00
Nikita Popov
0ebf2bdba0 Convert "Illegal offset type" warnings to exceptions 2019-09-27 13:00:07 +02:00
Nikita Popov
f2b09969db Convert "cannot add element" warning to exception 2019-09-27 13:00:07 +02:00
Nikita Popov
a66c60cce3 Throw Error when writing property of non-object
This removes object auto-vivification support.

This also means that we can remove the corresponding special
handling for typed properites: We no longer need to check that a
property is convertible to stdClass if such a conversion might
take place indirectly due to a nested property write.

Additionally OBJ_W style operations now no longer modify the
object operand, and as such we no longer need to treat op1 as a
def in SSA form.

The next step would be to actually compile the whole LHS of OBJ_W
operations in R rather than W mode, but that causes issues with
SimpleXML, whose object handlers depend on the current compilation
structure.

Part of https://wiki.php.net/rfc/engine_warnings.
2019-09-27 10:11:47 +02:00
Christoph M. Becker
0c7124e6be Add check_only parameter to get_closure handler
`get_closure` handlers are called to check whether an object is
callable, and to actually get the closure, respectively.  The behavior
of the handler might differ for these two cases, particularly the
handler may throw in the latter case, but should not in the former.

Therefore we add a `check_only` parameter, to be able to distinguish
the desired purpose.
2019-09-24 16:08:42 +02:00
Nikita Popov
6276dd826b Use ZEND_TYPE_IS_SET() when checking for property types
Instead of a simple if or 0 comparison. This would no longer work
if zend_type is a struct.
2019-09-23 16:53:54 +02:00
Nikita Popov
d7ae123648 Canonicalize typed properties error message
We have lots of other typed properties related error messages of
the form "assign X to typed property Y::$z of type A", so use th
same format for the primary message as well. Special-casing things
like classes and nullability is not going to scale with future
type-system extensions, and I don't think it really adds clarity
either.
2019-09-23 15:48:49 +02:00
Nikita Popov
9e8ba7891e Change representation of zend_type from type code to MAY_BE_* mask
This switches zend_type from storing a single IS_* type code to
storing a MAY_BE_* type mask. Right now most code still assumes
that there is only a single type in the mask (or two together
with MAY_BE_NULL). But this will make it a lot simpler to introduce
union types.

An additional advantage (and why I'm doing this separately), is
that a number of special cases no longer need to be handled
separately: We can do a single mask & (1 << type) check to handle
all simple types, booleans (true|false) and null.
2019-09-23 15:31:35 +02:00
Nikita Popov
cdd4e591a4 Don't make argument nullable based on AST null initializer
Closes GH-4720.
2019-09-19 11:27:00 +02:00
Dmitry Stogov
cf4c4ee900 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78531 (Crash when using undefined variable as object
2019-09-13 01:43:40 +03:00