Uh oh!
There was an error while loading. Please reload this page.
Fix constant propagation for JMP_NULL - #11745
Conversation
ndossche
left a comment
There was a problem hiding this comment.
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. functiontest() {
switch (1?4:y) {
case1: return1;
case2: return2;
case3: return3;
case4: return4;
case5: return5;
}
}
var_dump(test());We should do the same for all these opcodes, propagating the constant but keeping the source. |
ndossche
commented
Jul 19, 2023
Nice test, makes sense to me. As a side note, it may make more sense for this optimization to live in SSA DFA? |
iluuu1994
commented
Jul 19, 2023
@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. |
iluuu1994
commented
Jul 21, 2023
@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
ndossche
commented
Jul 21, 2023
Okay this makes sense to me. Also, I fixed such a bug with follow blocks in the past (for ZEND_FREE) with a |
iluuu1994
commented
Jul 25, 2023
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