You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
PHP Warning: Undefined array key -1 in /home/daniil/repos/BaconQrCode/a.php on line 14
PHP Warning: Undefined array key -1 in /home/daniil/repos/BaconQrCode/a.php on line 14
@nielsdos@dstogov A thing that's been bothering me this bug in particular is that it could in theory be reproduced with an appropriate testcase, combined with the --repeat option of phpunit, but in practice it can only be reproduced if it's the only testcase, any idea of the cause/solution?
For example, adding the following testcase to EncoderTest.php:
I've been thinking of adding a --repeat to all phpunit calls in the community tests (and something similar in the unit tests ran by run-tests.php) to improve the chances of hitting a tracing JIT bug, but this weird behavior would make it all useless unless I also add manual per-testcase filtering and execution.
The issue seems to be related to the skipping of comparisons. If I remove the strict comparison and just use a boolean cast it works. Disabling the optimization with ZEND_SUB in the first case of zend_jit_may_skip_comparison also makes the code work.
Looking at the diff in assembly instructions between forcing skip_comparison to off and normal execution shows this:
So: in the working version there's an additional test instruction. It seems that the subtraction was implemented with a lea instruction, but lea does NOT set the flags register.
Ideas to fix this:
Either the skip comparison optimization must not be performed when emitting lea.
Or sub should be used when we can predict skip_comparison will be true
Activity
ndossche commentedon Oct 8, 2023
Reproducible only using tracing JIT, not e.g. function JIT.
danog commentedon Oct 8, 2023
Basic reproducer:
Emits
Only if tracing JIT is enabled.
danog commentedon Oct 8, 2023
@nielsdos @dstogov A thing that's been bothering me this bug in particular is that it could in theory be reproduced with an appropriate testcase, combined with the
--repeatoption of phpunit, but in practice it can only be reproduced if it's the only testcase, any idea of the cause/solution?For example, adding the following testcase to
EncoderTest.php:And running the entire testsuite with:
does not reproduce the issue, while running just that testcase with:
does.
I've been thinking of adding a
--repeatto all phpunit calls in the community tests (and something similar in the unit tests ran by run-tests.php) to improve the chances of hitting a tracing JIT bug, but this weird behavior would make it all useless unless I also add manual per-testcase filtering and execution.Any idea of the possible cause?
ndossche commentedon Oct 8, 2023
The issue seems to be related to the skipping of comparisons. If I remove the strict comparison and just use a boolean cast it works. Disabling the optimization with ZEND_SUB in the first case of
zend_jit_may_skip_comparisonalso makes the code work.Looking at the diff in assembly instructions between forcing skip_comparison to off and normal execution shows this:
So: in the working version there's an additional test instruction. It seems that the subtraction was implemented with a lea instruction, but lea does NOT set the flags register.
Ideas to fix this:
Bypass JIT bug php/php-src#12382
Merge branch 'PHP-8.1' into PHP-8.2
Merge branch 'PHP-8.2' into PHP-8.3
Merge branch 'PHP-8.3'
dstogov commentedon Oct 9, 2023
@danog thanks for the reproducible case
@nielsdos thanks for the analyses
Fixed phpGH-12382: JIT Index invalid or out of range error