View Issue Details

IDProjectCategoryView StatusLast Update
0001567XdebugCode Coveragepublic2018-08-09 09:03
Reporterwankata Assigned Toderick  
PrioritynormalSeverityminorReproducibilityalways
Status resolvedResolutionno change required 
OSUbuntuOS Version16.04.4 LTS 
Product Version2.6.0 
Summary0001567: Return statement in conditional causes xdebug to report the closing parenthesis as not covered
Description

When 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 Reproduce

Run 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

Activities

wankata

2018-07-27 05:17

reporter   ~0004686

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.

derick

2018-08-09 09:01

administrator   ~0004692

Last edited: 2018-08-09 09: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 22:03 wankata New Issue
2018-07-27 05:17 wankata Note Added: 0004686
2018-08-09 09:01 derick Note Added: 0004692
2018-08-09 09:01 derick Status new => resolved
2018-08-09 09:01 derick Resolution open => no change required
2018-08-09 09:01 derick Assigned To => derick
2018-08-09 09:02 derick Note Edited: 0004692
2018-08-09 09:03 derick Note Edited: 0004692