Skip to content

Fix GH-14873: PHP 8.4 min function fails on typed integer - #14876

Closed
ndossche wants to merge 1 commit into
php:masterfrom
ndossche:flf-result-null
Closed

ndossche wants to merge 1 commit into
php:masterfrom
ndossche:flf-result-null

Conversation

@ndossche

@ndossche ndossche commented Jul 8, 2024

Copy link
Copy Markdown
Member

The DFA pass may cause the op1 and result argument to be equal to each other. In the VM we always use ZVAL_NULL(result) first, which will also destroy the first argument. Use a temporary result to fix the issue.

@ndossche ndossche linked an issue Jul 8, 2024 that may be closed by this pull request
@ndossche
ndossche force-pushed the flf-result-null branch 2 times, most recently from bdb8a03 to 4354ce4 Compare July 8, 2024 14:27
@ndossche
ndossche force-pushed the flf-result-null branch 2 times, most recently from e6ff7b4 to 7fb919a Compare July 8, 2024 19:45
The DFA pass may cause the op1 and result argument to be equal to each
other. In the VM we always use ZVAL_NULL(result) first, which will also
destroy the first argument. Use a temporary result to fix the issue.
@iluuu1994

Copy link
Copy Markdown
Member

I wonder if it might be easier to adjust the DFA pass instead, by special casing frameless calls. This would also avoid the copy in the VM.

@ndossche

ndossche commented Jul 9, 2024

Copy link
Copy Markdown
Member Author

Maybe. Then you do have an extra copy opline though from the temporary return value to the CV AFAIK

@iluuu1994

Copy link
Copy Markdown
Member

@nielsdos Not having looked at this yet, it seems that was mostly the case anyway, given we haven't seen any other failures, right?

@ndossche

ndossche commented Jul 9, 2024

Copy link
Copy Markdown
Member Author

@nielsdos Not having looked at this yet, it seems that was mostly the case anyway, given we haven't seen any other failures, right?

That is true.

@Alkarex

Alkarex commented Jul 10, 2024

Copy link
Copy Markdown

max() does not seem to be affected. I am not familiar with the code, but maybe the same logic could be done to min()?

@ndossche

Copy link
Copy Markdown
Member Author

max() does not seem to be affected. I am not familiar with the code, but maybe the same logic could be done to min()?

max() is in fact affected. The bug is not in the min/max implementation but either in the optimizer of the VM/JIT depending on the PoV.

ndossche added a commit to ndossche/php-src that referenced this pull request Jul 10, 2024
The problem is that this line in the VM: `ZVAL_NULL(result);` changes the type
of arg1 as well, because after the DFA pass the result and input both use
CV0($result).
We should not contract assignments with CVs in frameless calls with
arguments.
An older attempt is found at phpGH-14876 that tried to modify the VM/JIT.
ndossche added a commit that referenced this pull request Jul 12, 2024
The problem is that this line in the VM: `ZVAL_NULL(result);` changes the type
of arg1 as well, because after the DFA pass the result and input both use
CV0($result).
We should not contract assignments with CVs in frameless calls with
arguments.
An older attempt is found at GH-14876 that tried to modify the VM/JIT.

Closes GH-14903.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

PHP 8.4 min function fails on typed integer

3 participants