Commit graph

1697 commits

Author SHA1 Message Date
Máté Kocsis
960318ed95
Change argument error message format
Closes GH-5211
2020-02-26 15:00:08 +01:00
Nikita Popov
d594fba3ac Reorder checks in object ref assignment
First check for IS_INDIRECT and de-indirect it directly there.
Handle the error cases later.
2020-02-25 17:30:54 +01:00
Máté Kocsis
ac0853eb26
Make type error messages more consistent
Closes GH-5092
2020-02-17 14:22:17 +01:00
Nikita Popov
43443857b7 Add static return type
RFC: https://wiki.php.net/rfc/static_return_type

The "static" type is represented as MAY_BE_STATIC, rather than
a class type like "self" and "parent", as it has special
resolution semantics, and cannot be cached in the runtime cache.

Closes GH-5062.
2020-02-17 11:51:09 +01:00
Nikita Popov
bc6bab6cb4 Basic JIT support for verify return 2020-02-07 12:59:48 +03:00
Dmitry Stogov
b53445422a Merge branch 'PHP-7.4'
* PHP-7.4:
  Make opcodes to return de-refereced values of typed references (in the same was as for non-typed)
2020-02-06 15:57:29 +03:00
Dmitry Stogov
5d0ef4c239 Make opcodes to return de-refereced values of typed references (in the same was as for non-typed) 2020-02-06 15:48:54 +03:00
George Peter Banyard
c343c1bcae Fix some -Wold-style-declaration compiler warnings 2020-02-05 17:39:29 +01:00
Nikita Popov
169805777c Merge branch 'PHP-7.4'
* PHP-7.4:
  Apply tidy formatting
2020-02-03 13:42:08 +01:00
Dmitry Stogov
2b279b428f We don't need "safe" destruction anymore 2020-01-31 16:01:09 +03:00
Dmitry Stogov
7ebf1d44ed Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79094 (Crashing when running recursion function)
2020-01-31 10:34:28 +03:00
Dmitry Stogov
db7193f31e Fixed bug #79094 (Crashing when running recursion function) 2020-01-31 10:34:04 +03:00
Nikita Popov
9ec1ee5976 Add support for deprecating constants
Internal constants can be marked as CONST_DEPRECATED, in which
case accessing them will throw a deprecation warning.

For now this is only supported on global constants, not class
constants. Complain to me if you need to deprecate a class
constant...

Closes GH-5072.
2020-01-17 10:05:06 +01:00
Nikita Popov
bd1977282c Use zend_type inside type lists
Instead of having a completely independent encoding for type list
entries. This is going to use more memory, but I'm not particularly
concerned about that, as type unions that contain multiple classes
should be uncommon. On the other hand, this allows us to treat
top-level types and types inside lists mostly the same.

A new ZEND_TYPE_FOREACH macros allows to transparently treat list
and non-list types the same way. I'm not using it everywhere it could be
used for now, just the places that seemed most obvious.

Of course, this will make any future type system changes much simpler,
as it will not be necessary to duplicate all logic two times.
2020-01-17 09:37:54 +01:00
Nikita Popov
d0d1654a34 Fix #49555: Improve "function must be a string" error message
Be more specific for the individual cases and provide relevant
type information.
2020-01-08 14:32:11 +01:00
George Peter Banyard
bfe3f934a3 Add warning and convert to exception in string offset assignment:
Convert the empty string assignment to an Error as per RFC [1]
Add a warning that only the first byte will be assigned to the offset if provided
a needle that is longer than one byte.

[1] https://wiki.php.net/rfc/engine_warnings
2020-01-07 21:54:42 +01:00
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