-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Fix constant propagation for JMP_NULL #11745
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code looks correct, I checked the opcodes before optimizer & after optimizer and it looks correct.
Now I do have a question: why isn't the zend_optimizer_update_op1_const
call unconditional? I guess it's because SCCP would take care of the constant propagation anyway during SSA optimizations if we don't do it here for the disallowed opcodes? (Disallowed opcodes being ZEND_CASE, ZEND_CASE_STRICT, ...)
Looking at the disallowed opcodes they do indeed look handled in SCCP. Just wanted to make sure :-).
@nielsdos Good point. I think all of those opcodes don't consume op1. I guess the idea was that we're skipping propagating the constant as removing the source would make it unavailable for the following instructions. However, this can't work because the last instruction will still remove the source, leaving the leading instructions referencing an undeclared variable. This demonstrates the problem. function test() {
switch (1?4:y) {
case 1: return 1;
case 2: return 2;
case 3: return 3;
case 4: return 4;
case 5: return 5;
}
}
var_dump(test());
We should do the same for all these opcodes, propagating the constant but keeping the source. |
Nice test, makes sense to me. As a side note, it may make more sense for this optimization to live in SSA DFA? |
@nielsdos Wait, I messed up. I had some local changes that broke this. 🙂 The relevant code is not triggered for the switch example, I'll need to examine more closely how to do that. |
af01255
to
5e7a1c4
Compare
@nielsdos I had another look. There was another issue where we propagated constants to "follow" blocks even if the variable was later used in a different block. Apparently this scenario just doesn't appear often in our opcodes. I checked and only 5 existing tests were affected. |
Don't propagate to JMP_NULL because it doesn't consume OP1. Also don't propagate variables that were declared in other blocks. Fixes oss-fuzz #60736
5e7a1c4
to
81626fa
Compare
Okay this makes sense to me. Also, I fixed such a bug with follow blocks in the past (for ZEND_FREE) with a |
Heh, Dmitry already committed it in 9fc0eab. |
Don't propagate to JMP_NULL because it doesn't consume OP1. Also don't propagate
variables that were declared in other blocks.
Fixes oss-fuzz #60736