Skip to content

Commit 0007c68

Browse files
committed
Merge branch 'PHP-8.1'
* PHP-8.1: Fix JIT typed property inc/dec
2 parents 62e0200 + 560dafb commit 0007c68

File tree

2 files changed

+28
-56
lines changed

2 files changed

+28
-56
lines changed

ext/opcache/jit/zend_jit_helpers.c

Lines changed: 4 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2265,64 +2265,14 @@ static void ZEND_FASTCALL zend_jit_dec_typed_prop(zval *var_ptr, zend_property_i
22652265

22662266
static void ZEND_FASTCALL zend_jit_pre_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
22672267
{
2268-
zend_execute_data *execute_data = EG(current_execute_data);
2269-
zval tmp;
2270-
2271-
if (!result) {
2272-
result = &tmp;
2273-
}
2274-
2275-
ZVAL_DEREF(var_ptr);
2268+
zend_jit_inc_typed_prop(var_ptr, prop_info);
22762269
ZVAL_COPY(result, var_ptr);
2277-
2278-
increment_function(var_ptr);
2279-
2280-
if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(result) == IS_LONG) {
2281-
if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
2282-
zend_long val = _zend_jit_throw_inc_prop_error(prop_info);
2283-
ZVAL_LONG(var_ptr, val);
2284-
}
2285-
} else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
2286-
zval_ptr_dtor(var_ptr);
2287-
ZVAL_COPY_VALUE(var_ptr, result);
2288-
ZVAL_UNDEF(result);
2289-
} else if (result == &tmp) {
2290-
zval_ptr_dtor(&tmp);
2291-
}
2292-
if (UNEXPECTED(result)) {
2293-
ZVAL_COPY(result, var_ptr);
2294-
}
22952270
}
22962271

22972272
static void ZEND_FASTCALL zend_jit_pre_dec_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
22982273
{
2299-
zend_execute_data *execute_data = EG(current_execute_data);
2300-
zval tmp;
2301-
2302-
if (!result) {
2303-
result = &tmp;
2304-
}
2305-
2306-
ZVAL_DEREF(var_ptr);
2274+
zend_jit_dec_typed_prop(var_ptr, prop_info);
23072275
ZVAL_COPY(result, var_ptr);
2308-
2309-
decrement_function(var_ptr);
2310-
2311-
if (UNEXPECTED(Z_TYPE_P(var_ptr) == IS_DOUBLE) && Z_TYPE_P(result) == IS_LONG) {
2312-
if (!(ZEND_TYPE_FULL_MASK(prop_info->type) & MAY_BE_DOUBLE)) {
2313-
zend_long val = _zend_jit_throw_dec_prop_error(prop_info);
2314-
ZVAL_LONG(var_ptr, val);
2315-
}
2316-
} else if (UNEXPECTED(!zend_verify_property_type(prop_info, var_ptr, EX_USES_STRICT_TYPES()))) {
2317-
zval_ptr_dtor(var_ptr);
2318-
ZVAL_COPY_VALUE(var_ptr, result);
2319-
ZVAL_UNDEF(result);
2320-
} else if (result == &tmp) {
2321-
zval_ptr_dtor(&tmp);
2322-
}
2323-
if (UNEXPECTED(result)) {
2324-
ZVAL_COPY(result, var_ptr);
2325-
}
23262276
}
23272277

23282278
static void ZEND_FASTCALL zend_jit_post_inc_typed_prop(zval *var_ptr, zend_property_info *prop_info, zval *result)
@@ -2398,8 +2348,7 @@ static void ZEND_FASTCALL zend_jit_pre_inc_obj_helper(zend_object *zobj, zend_st
23982348
}
23992349

24002350
if (UNEXPECTED(prop_info)) {
2401-
zend_jit_pre_inc_typed_prop(prop, prop_info, result);
2402-
return;
2351+
zend_jit_inc_typed_prop(prop, prop_info);
24032352
} else {
24042353
increment_function(prop);
24052354
}
@@ -2469,8 +2418,7 @@ static void ZEND_FASTCALL zend_jit_pre_dec_obj_helper(zend_object *zobj, zend_st
24692418
}
24702419

24712420
if (UNEXPECTED(prop_info)) {
2472-
zend_jit_pre_dec_typed_prop(prop, prop_info, result);
2473-
return;
2421+
zend_jit_dec_typed_prop(prop, prop_info);
24742422
} else {
24752423
decrement_function(prop);
24762424
}

ext/opcache/tests/jit/inc_023.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
PRE_INC/DEC refcounted typed property
3+
--INI--
4+
opcache.enable=1
5+
opcache.enable_cli=1
6+
opcache.file_update_protection=0
7+
opcache.jit_buffer_size=1M
8+
opcache.protect_memory=1
9+
--FILE--
10+
<?php
11+
class Test {
12+
public string $prop;
13+
}
14+
15+
$test = new Test;
16+
$test->prop = "a";
17+
++$test->prop;
18+
--$test->prop;
19+
var_dump(++$test->prop);
20+
var_dump(--$test->prop);
21+
?>
22+
--EXPECT--
23+
string(1) "c"
24+
string(1) "c"

0 commit comments

Comments
 (0)