[php-src] Issue #25061: Opcache DFA: `$x = $x - 1` on a null ?int is rewritten to PRE_DEC, giving NULL (verifier failure in checking build)
| From: | waroad | Date: | Fri, 30 Oct 2026 19:05:50 +0000 |
| Subject: | [php-src] Issue #25061: Opcache DFA: `$x = $x - 1` on a null ?int is rewritten to PRE_DEC, giving NULL (verifier failure in checking build) | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-253942@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/25061
Author: waroad
> With opcache's default optimizer,
$x = $x - 1 on a þ”Ðà
> ö¸ãá×4ßs?int parameter that is null is rewritten to a pre-decrement, so the
> function returns NULL (plus a "Decrement on type null" warning) instead of
> int(-1).
```php
<?php
function d4(?int $x) { $x = $x - 1; return $x; }
var_dump(d4(null));
```
```
php -n -d opcache.enable_cli=1 -d opcache.file_update_protection=0 input.php
```
> Normal (release) build:
```
Warning: Decrement on type null has no effect, this will change in the next major version of PHP in
input.php on line 2
NULL
```
> Checking build (also run with -d opcache.protect_memory=1),
> exit code 139 (SIGSEGV):
```
Inference verification failed at 0001 op1_def (mask 0x30 missing type 1)
Warning: Decrement on type null has no effect, this will change in the next major version of PHP in
input.php on line 2
```
> I expected int(-1): null - 1 is
> -1, and the same script without opcache prints
> int(-1). With a different target variable ($y = $x -
> 1;) opcache also prints int(-1).
> Reproduces at 1a72e5f25423fa67c7ef6ff325a7c300e02b25a7 (latest upstream, 2026-10-30): the
> checking build fails the inference verification and crashes as shown above; the release build exits
> 0 with the wrong output shown above and does not crash.
> Looks like the $x = $x - 1 to
> ZEND_PRE_DEC rewrite in
> Zend/Optimizer/dfa_pass.c does not exclude
> MAY_BE_NULL/MAY_BE_UNDEF operands
> (--null is a no-op, null - 1 is
> -1); the nearby ASSIGN_OP SUB to
> PRE_DEC rule does exclude them. I have not patched or debugged this. Open PR #23383 (dfa_pass.c
> refactoring) touches nearby code; built at its head 3739cb5d, the release build still prints NULL
> with the warning. With open PR #24110 (range inference) applied on 82b01e22, the checking build
> still fails the same way. Closed #11759 and #10358 mention the same warning text and may be related.
Found with an LLM-based testing tool. As CONTRIBUTING.md asks, the paragraphs in > quotes were
written with Claude; I ran every command myself.