https://gcc.gnu.org/bugzilla/show_bug.cgi?id=116279

            Bug ID: 116279
           Summary: Branch coverage measure is reported in inconsistent
                    ways for comma operators
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: wentaoz5 at illinois dot edu
  Target Milestone: ---

How to reproduce:

$ gcc --version

gcc (GCC) 15.0.0 20240723 (experimental)
Copyright (C) 2024 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

$ cat << EOF > test.c
int x, y;

int main(int argc, char **argv) {
    if (
        x
        ,
        y
    )
        return 0;
    return 0;
}
EOF
$ gcc --coverage test.c -o test
$ ./test
$ gcov -b -c test
$ cat test.c.gcov

        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        -:    1:int x, y;
        -:    2:
function main called 1 returned 100% blocks executed 75%
        1:    3:int main(int argc, char **argv) {
        1:    4:    if (
        1:    5:        x
branch  0 taken 0 (fallthrough)
branch  1 taken 1
        -:    6:        ,
        -:    7:        y
        -:    8:    )
    #####:    9:        return 0;
        1:   10:    return 0;
        -:   11:}

With the same language construct, but this time we introduce some side effects,
branch coverage measure would be associated to different lines.

Variant 1:

        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        -:    1:int x, y;
        -:    2:
function main called 1 returned 100% blocks executed 75%
        1:    3:int main(int argc, char **argv) {
        1:    4:    if (
        -:    5:        x
        1:    6:        ,
branch  0 taken 0 (fallthrough)
branch  1 taken 1
        -:    7:        y++
        -:    8:    )
    #####:    9:        return 0;
        1:   10:    return 0;
        -:   11:}

Variant 2:

        -:    0:Source:test.c
        -:    0:Graph:test.gcno
        -:    0:Data:test.gcda
        -:    0:Runs:1
        -:    1:int x, y;
        -:    2:
function main called 1 returned 100% blocks executed 75%
        1:    3:int main(int argc, char **argv) {
        1:    4:    if (
        1:    5:        x++
        -:    6:        ,
        1:    7:        y++
branch  0 taken 0 (fallthrough)
branch  1 taken 1
        -:    8:    )
    #####:    9:        return 0;
        1:   10:    return 0;
        -:   11:}

Reply via email to