Skip to content

Emit EXT_STMT for each 'elseif' clause #8574

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

Merged
merged 1 commit into from
May 20, 2022

Conversation

derickr
Copy link
Member

@derickr derickr commented May 17, 2022

This tiny change emits an extra EXT_STMT opcode for each elseif child in an AST_IF list.

The reason why I am proposing this, is as follows:

A user reported a bug #2095 with Xdebug's code coverage, which complains that lines with elseif on them do not get "counted" as being it, where else if lines do.

The generated opcodes are for the elseif version:

   12     0  E >   EXT_STMT                                                 
          1        ASSIGN                                                   !0, 'bar'
   13     2        EXT_STMT                                                 
          3      > JMPZ                                                     <false>, ->7
   14     4    >   EXT_STMT                                                 
          5        ECHO                                                     'hello+1'
          6      > JMP                                                      ->11
   15     7    >   IN_ARRAY                                                 !0, <array>
          8      > JMPZ                                                     ~2, ->11
   16     9    >   EXT_STMT                                                 
         10        ECHO                                                     'hello+2'
   18    11    >   EXT_STMT                                                 
         12      > RETURN                                                   null

And for the else if version:

    3     0  E >   EXT_STMT                                                 
          1        ASSIGN                                                   !0, 'bar'
    4     2        EXT_STMT                                                 
          3      > JMPZ                                                     <false>, ->7
    5     4    >   EXT_STMT                                                 
          5        ECHO                                                     'hello+1'
          6      > JMP                                                      ->12
    6     7    >   EXT_STMT                                                 
          8        IN_ARRAY                                                 !0, <array>
          9      > JMPZ                                                     ~2, ->12
    7    10    >   EXT_STMT                                                 
         11        ECHO                                                     'hello+2'
    9    12    >   EXT_STMT                                                 
         13      > RETURN                                                   null

In the elseif variant, the EXT_STMT (opcode 7) is indeed missing.

Xdebug uses this opcode for both code coverage analysis, as well as single stepping. The step debugger would also not have stopped at the elseif line.

The reason here is that with else if it is really seen as two different things, with the if being a new statement (and hence creating its own EXT_STMT), where with elseif it is a continuation of the original if, which does not emit an EXT_STMT for each separate condition. This patch equalizes the behaviour.

@derickr derickr requested review from nikic, iluuu1994, bwoebi and Girgias May 17, 2022 17:22
@derickr derickr self-assigned this May 17, 2022
@derickr derickr force-pushed the xdebug-2095-elseif-ext-stmt branch from eb5c8f2 to 6fc3907 Compare May 18, 2022 09:28
@derickr derickr requested a review from iluuu1994 May 18, 2022 09:29
@cmb69
Copy link
Member

cmb69 commented May 18, 2022

Can we reasonably be sure that this additional OPcode won't cause issues with other zend_extensions which have a statement_handler? Otherwise it would be better to target master only.

@derickr
Copy link
Member Author

derickr commented May 20, 2022

@cmb69 I am not aware of any open source Zend extensions, so I can't check to make sure. However, I'm confident that it will not cause issues, as it would also rather just fix bugs for these. Opcache doesn't use the handler, either.

@derickr derickr force-pushed the xdebug-2095-elseif-ext-stmt branch from 6fc3907 to c06e1ab Compare May 20, 2022 09:52
@derickr derickr merged commit 33850fb into php:PHP-8.0 May 20, 2022
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.

4 participants