MantisBT

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0001567XdebugCode Coveragepublic2018-07-26 23:032018-08-09 10:03
Reporterwankata 
Assigned Toderick 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionno change required 
PlatformOSUbuntuOS Version16.04.4 LTS
Product Version2.6.0 
Target VersionFixed in Version 
Summary0001567: Return statement in conditional causes xdebug to report the closing parenthesis as not covered
DescriptionWhen using return inside if's body, xdebug reports the closing parenthesis as not covered. It should be marked as dead code instead.

As you may see in the reproduce script, lines 5 and 6 are marked as executed and line 8 is marked as not executed, but line 7 isn't there at all. This causes PHPUnit to report the line as not covered.

This seems to be very similar to https://bugs.xdebug.org/view.php?id=1192 [^]
Steps To ReproduceRun this script:
<?php

function xdebug($x)
{
    if ($x == 1) {
        return true;
    }
}

xdebug_start_code_coverage(XDEBUG_CC_DEAD_CODE|XDEBUG_CC_UNUSED);
xdebug(1);
print_r(xdebug_get_code_coverage());
xdebug_stop_code_coverage();
Additional Information# aptitude show php-xdebug
Package: php-xdebug
State: installed
Version: 2.6.0+2.5.5-1+ubuntu16.04.1+deb.sury.org+1
Maintainer: Debian PHP PECL Maintainers <pkg-php-pecl@lists.alioth.debian.org>
Architecture: amd64


$ php --version
PHP 7.2.7-1+ubuntu16.04.1+deb.sury.org+1 (cli) (built: Jun 22 2018 08:44:50) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.2.0, Copyright (c) 1998-2018 Zend Technologies
    with Zend OPcache v7.2.7-1+ubuntu16.04.1+deb.sury.org+1, Copyright (c) 1999-2018, by Zend Technologies
    with Xdebug v2.6.0, Copyright (c) 2002-2018, by Derick Rethans
TagsNo tags attached.
Operating System
PHP Version7.2.0-7.2.4
Attached Files

- Relationships

-  Notes
(0004686)
wankata (reporter)
2018-07-27 06:17

I did some more tests this morning and I realized that the problem is not really there, where I've described it.
I've tried the following:
function xdebug($x)
{
    if ($x == 1) {
        $result = 1;
    }
    return $result;
}

and realized that the last closing bracket is now marked with -2 (not executable) while it was marked with -1 before. And the conditional's closing bracket isn't there again (which is obviously normal).

So actually not the closing bracket of the condition, but the one of the function is marked falsely as not executed instead of not executable.
(0004692)
derick (administrator)
2018-08-09 10:01
edited on: 2018-08-09 10:03

This is the correct behaviour. Your original test case does not cover the situation where $x != 1, and hence, the end of the function is never reached. Each function in PHP ends with an implicit "return NULL;":

function name:  xdebug
number of ops:  9
compiled vars:  !0 = $x
line     #* E I O op                           fetch          ext  return  operands
-------------------------------------------------------------------------------------
   3     0  E >   EXT_NOP                                                  
         1        RECV                                             !0      
   5     2        EXT_STMT                                                 
         3        IS_EQUAL                                         0000002:0000001      !0, 1
         4      > JMPZ                                                     0000002:0000001, ->7
   6     5    >   EXT_STMT                                                 
         6      > RETURN                                                   <true>
   8     7    >   EXT_STMT                                                 
         8      > RETURN                                                   null

branch: #  0; line:     3-    5; sop:     0; eop:     4; out0:   5; out1:   7
branch: #  5; line:     6-    6; sop:     5; eop:     6; out0:  -2
branch: #  7; line:     8-    8; sop:     7; eop:     8; out0:  -2
path #1: 0, 5, 
path 0000002: 0, 7, 
End of function xdebug


From this VLD output, you can see there is a branch instruction on line 4 (the JMPZ), which starts the branches at 5 and 7.
Your tests makes it execute the first branch (with the return true;), but not the second one starting at 7. As your code never touches the implicit "return null;" at the end of the script (op 8), it gets correctly marked as "not executed".


- Issue History
Date Modified Username Field Change
2018-07-26 23:03 wankata New Issue
2018-07-27 06:17 wankata Note Added: 0004686
2018-08-09 10:01 derick Note Added: 0004692
2018-08-09 10:01 derick Status new => resolved
2018-08-09 10:01 derick Resolution open => no change required
2018-08-09 10:01 derick Assigned To => derick
2018-08-09 10:02 derick Note Edited: 0004692 View Revisions
2018-08-09 10:03 derick Note Edited: 0004692 View Revisions


Copyright © 2000 - 2018 MantisBT Team
Powered by Mantis Bugtracker