Skip to content

Commit c5eb8c3

Browse files
committed
Do not const evaluate ++/-- in SCCP
Yes, now there are memory leaks and bugs but this is too much black magic for me
1 parent 702a69e commit c5eb8c3

File tree

7 files changed

+20
-14
lines changed

7 files changed

+20
-14
lines changed

Zend/Optimizer/sccp.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,15 @@ static inline zend_result ct_eval_assign_obj(zval *result, zval *value, const zv
664664
}
665665

666666
static inline zend_result ct_eval_incdec(zval *result, uint8_t opcode, zval *op1) {
667+
/* As of PHP 8.3 with the warning/deprecation notices any type other than int/double/null will emit a diagnostic
667668
if (Z_TYPE_P(op1) == IS_ARRAY || IS_PARTIAL_ARRAY(op1)) {
668669
return FAILURE;
669670
}
671+
*/
672+
/* Decrement on null emits a deprecation notice */
673+
if (Z_TYPE_P(op1) != IS_LONG && Z_TYPE_P(op1) != IS_DOUBLE /* && Z_TYPE_P(op1) != IS_NULL */) {
674+
return FAILURE;
675+
}
670676

671677
ZVAL_COPY(result, op1);
672678
if (opcode == ZEND_PRE_INC
@@ -2109,7 +2115,7 @@ static int try_remove_definition(sccp_ctx *ctx, int var_num, zend_ssa_var *var,
21092115
break;
21102116
default:
21112117
break;
2112-
}
2118+
}
21132119
}
21142120
/* we cannot remove instruction that defines other variables */
21152121
return 0;

ext/opcache/tests/jit/inc_017.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ function foo() {
1717
}
1818
var_dump(foo());
1919
?>
20-
--EXPECT--
21-
Warning: Increment on type bool has no effect, this will change in the next major version of PHP in Unknown on line 0
20+
--EXPECTF--
21+
Warning: Increment on type bool has no effect, this will change in the next major version of PHP in %sinc_017.php on line 4
2222
bool(true)

ext/opcache/tests/jit/inc_018.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ function foo() {
1717
}
1818
var_dump(foo());
1919
?>
20-
--EXPECT--
21-
Warning: Increment on type bool has no effect, this will change in the next major version of PHP in Unknown on line 0
20+
--EXPECTF--
21+
Warning: Increment on type bool has no effect, this will change in the next major version of PHP in %sinc_018.php on line 4
2222
bool(false)

ext/opcache/tests/opt/inference_016.phpt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ function test() {
1313
}
1414
}
1515
try {
16-
@test();
16+
test();
1717
} catch (Throwable $e) {
1818
echo $e->getMessage(), "\n";
1919
}
2020
?>
21-
--EXPECT--
22-
Warning: Decrement on type null has no effect, this will change in the next major version of PHP in Unknown on line 0
21+
--EXPECTF--
2322
NULL
23+
24+
Warning: Decrement on type null has no effect, this will change in the next major version of PHP in %sinference_016.php on line %d
2425
Modulo by zero

ext/opcache/tests/opt/inference_019.phpt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ test();
1919
?>
2020
DONE
2121
--EXPECTF--
22-
Warning: Decrement on type null has no effect, this will change in the next major version of PHP in Unknown on line 0
2322

24-
Warning: Decrement on type null has no effect, this will change in the next major version of PHP in %s on line %d
23+
Warning: Decrement on type null has no effect, this will change in the next major version of PHP in %sinference_019.php on line %d
2524
DONE

ext/opcache/tests/opt/sccp_035.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@ function test() {
1313
}
1414
?>
1515
DONE
16-
--EXPECT--
17-
Deprecated: Decrement on empty string is deprecated as non-numeric in Unknown on line 0
16+
--EXPECTF--
17+
Deprecated: Decrement on empty string is deprecated as non-numeric in %ssccp_035.php on line 5
1818
DONE

ext/opcache/tests/opt/sccp_038.phpt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@ function foo() {
1414
foo();
1515
?>
1616
DONE
17-
--EXPECT--
18-
Deprecated: Increment on non-alphanumeric string is deprecated in Unknown on line 0
17+
--EXPECTF--
18+
Deprecated: Increment on non-alphanumeric string is deprecated in %ssccp_038.php on line 5
1919
DONE

0 commit comments

Comments
 (0)