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

            Bug ID: 117415
           Summary: Bogus execution count for assignment to *func()
           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: ---

I hit the issue when dealing with
https://github.com/apache/httpd/blob/2.4.62/server/mpm_unix.c#L901. After
reduction, I ended up with two variants with slightly different triggering
conditions. See comments in code for details.

How to reproduce:

$ gcc --version

gcc (GCC) 15.0.0 20240923 (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 > test.c << 'EOF'
int arr[10];

int *foo() {
    return arr;
}

int bar() {
    return 0;
}

int main(void) {
    int *a = arr;
    int zero = 0;

    if (zero) {} else {
        // Variant 1 triggering conditions:
        //
        // 1. RHS of assignment is a function call
        // 2. The first function name and assignment are put in one line;
        //    the second function name is put in the other line
        // 3. Inside if(){...}, else{...}, for(){...} etc
        *foo()=
            bar();
    }

    // Variant 2 triggering conditions:
    //
    // 1. RHS of assignment is a dereference
    // 2. The function name and assignment are put in one line; the second
    //    dereference is put in the other line
    // 3. The operand of dereference is referenced elsewhere
    *foo()=
        *a;
    &a;

    return 0;
}
EOF
$ gcc --coverage test.c -o test
$ ./test
$ gcov test
$ cat test.c.gcov
...
        2:   22:        *foo()=
        1:   23:            bar();
...
        2:   32:    *foo()=
        1:   33:        *a;
...

Line 22 and 32 are reported to executed twice, which is hard to interpret.

Reply via email to