https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97923
--- Comment #6 from Xionghu Luo (luoxhu at gcc dot gnu.org) <yinyuefengyi at gmail dot com> --- below changes could fix the incorrect location diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 96845154a92..2dc8608dedf 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -3915,7 +3915,8 @@ shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p, false_label_p = &local_label; /* Keep the original source location on the first 'if'. */ - t = shortcut_cond_r (TREE_OPERAND (pred, 0), NULL, false_label_p, locus); + tree op0 = TREE_OPERAND (pred, 0); + t = shortcut_cond_r (op0, NULL, false_label_p, EXPR_LOCATION (op0)); append_to_statement_list (t, &expr); /* Set the source location of the && on the second 'if'. */ @@ -3938,7 +3939,8 @@ shortcut_cond_r (tree pred, tree *true_label_p, tree *false_label_p, true_label_p = &local_label; /* Keep the original source location on the first 'if'. */ - t = shortcut_cond_r (TREE_OPERAND (pred, 0), true_label_p, NULL, locus); + tree op0 = TREE_OPERAND (pred, 0); + t = shortcut_cond_r (op0, true_label_p, NULL, EXPR_LOCATION (op0)); append_to_statement_list (t, &expr); That produce expected block line info and coverage: gcov-dump test.gcno -lp: test.gcno: 583: 01450000: 35:LINES test.gcno: 595: block 2:`test.c':1, 3 <= change from 5 to 3 test.gcno: 626: 01450000: 31:LINES test.gcno: 638: block 3:`test.c':3 test.gcno: 665: 01450000: 31:LINES test.gcno: 677: block 4:`test.c':4 test.gcno: 704: 01450000: 31:LINES test.gcno: 716: block 5:`test.c':4 test.gcno: 743: 01450000: 31:LINES test.gcno: 755: block 6:`test.c':5 test.gcno: 782: 01450000: 31:LINES test.gcno: 794: block 7:`test.c':5 test.gcno: 821: 01450000: 31:LINES test.gcno: 833: block 8:`test.c':5 test.gcno: 860: 01450000: 31:LINES test.gcno: 872: block 9:`test.c':5 test.gcno: 899: 01450000: 31:LINES test.gcno: 911: block 10:`test.c':5 test.gcno: 938: 01450000: 31:LINES test.gcno: 950: block 11:`test.c':5 cat test.c.gcov: -: 0:Source:test.c -: 0:Graph:test.gcno -: 0:Data:test.gcda -: 0:Runs:1 1: 1:int foo(char c) -: 2:{ 1*: 3: return ((c >= 'A' && c <= 'Z') 1*: 4: || (c >= 'a' && c <= 'z') 1*: 5: || (c >= '0' && c <= '0')); -: 6:} -: 7: 1: 8:int main() { return foo('0'); }