Skip to content

Commit a5e89c5

Browse files
committed
Fix trailing if element JMP lineno
Having this lineno on the same last compiled element can lead to an incorrectly covered line number. if (true) { if (false) { echo 'Never executed'; } } else { } The echo will be reported as covered because the JMP from the if (true) branch to the end of the else branch has the same lineno as the echo. This is lacking a test because zend_dump.c does not have access to ctx->debug_level and I don't think it's worth adjusting all the cases. Closes GH-11598
1 parent 80153c9 commit a5e89c5

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

NEWS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ PHP NEWS
1111
- Core:
1212
. Fixed oss-fuzz #60011 (Mis-compilation of by-reference nullsafe operator).
1313
(ilutov)
14+
. Fixed line number of JMP instruction over else block. (ilutov)
1415

1516
- Date:
1617
. Fixed bug GH-11368 (Date modify returns invalid datetime). (Derick)

Zend/zend_compile.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5420,6 +5420,9 @@ static void zend_compile_if(zend_ast *ast) /* {{{ */
54205420
zend_compile_stmt(stmt_ast);
54215421

54225422
if (i != list->children - 1) {
5423+
/* Set the lineno of JMP to the position of the if keyword, as we don't want to
5424+
* report the last line in the if branch as covered if it hasn't actually executed. */
5425+
CG(zend_lineno) = elem_ast->lineno;
54235426
jmp_opnums[i] = zend_emit_jump(0);
54245427
}
54255428
zend_update_jump_target_to_next(opnum_jmpz);

0 commit comments

Comments
 (0)