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

            Bug ID: 121066
           Summary: [GCOV] Strange coverage statistics logic about
                    statement expressions and ternary operators
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: njuwy at smail dot nju.edu.cn
  Target Milestone: ---

gcc version:
gcc version 16.0.0 20250704 (experimental) (GCC) 

option:
--coverage -std=c2x

$ cat test.c
#include <stdio.h>
int main() {
    volatile int a = 0, b = 0;
    int result = (a = 1, a)+ 
               ((b = 2, b)
                ?(a = 8, a)
                :(b = 4, b));
    printf("a=%d,b=%d,result=%d\n",a,b,result);
    return 0;
}

output:
a=8,b=2,result=16

$ cat test.c.gcov
        -:    1:#include <stdio.h>
        1:    2:int main() {
        1:    3:    volatile int a = 0, b = 0;
        2:    4:    int result = (a = 1, a)+ 
        1:    5:               ((b = 2, b)
        2:    6:                ?(a = 8, a)
       1*:    7:                :(b = 4, b));
        1:    8:    printf("a=%d,b=%d,result=%d\n",a,b,result);
        1:    9:    return 0;
        -:   10:}


coverage statistics of line 4,5,6 should be consistent, and line 7 was not
executed.

Reply via email to