[php-src] Issue #24088: Range inference optimizer bug
| From: | ndossche | Date: | Sat, 03 Oct 2026 09:38:24 +0000 |
| Subject: | [php-src] Issue #24088: Range inference optimizer bug | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-252890@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/24088
Author: ndossche
### Description
The following code:
```php
<?php
function f($x) {
if ($x > 5 && $x < 7) {
return match ((int) $x) { 6 => "six", default => "not six" };
}
}
echo f(5.5);
```
Resulted in this output:
```
six // under opcache/optimizations
not six // without
```
Obviously "not six" is the right answer.
The problem can be seen in range inference:
```
#3.CV0($x) [any] RANGE[6..++] = Pi(#1.CV0($x) & RANGE[6 .. ++]) // $x > 5
#5.CV0($x) [any] RANGE[6..6] = Pi(#3.CV0($x) & RANGE[-- .. 6]) // $x < 7
#6.T3 [long] RANGE[6..6] = CAST (long) #5.CV0($x) [any] RANGE[6..6]
```
So each comparisons narrows the range, but
(int)5.5 equals 5. Then SCCP performs
folding and we end up with the wrong result. The problem is that the range inference is only valid
on int inputs.
I'm unsure how to fix this. We could track whether the range is definitely for an int, but
that's painful.
### PHP Version
```plain
8.4+
```
### Operating System
_No response_