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

            Bug ID: 123124
           Summary: [Gcov] always_inline attribute leads to incorrect
                    coverage
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: iamanonymous.cs at gmail dot com
  Target Milestone: ---

$ gcc-trunk -v
Using built-in specs.
COLLECT_GCC=gcc-trunk
COLLECT_LTO_WRAPPER=/compiler/gcc-trunk/libexec/gcc/x86_64-pc-linux-gnu/16.0.0/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: ../configure --disable-multilib --disable-bootstrap
--enable-languages=c,c++ --prefix=/compiler/gcc-trunk --enable-coverage
Thread model: posix
Supported LTO compression algorithms: zlib
gcc version 16.0.0 20251204 (experimental) (GCC)

$ cat small.c
int a;
__attribute__((always_inline)) int b () {
  return 0;
}
int main () {
  a - b () ;
}

$ gcc-trunk -w -O0 -fprofile-arcs -ftest-coverage small.c -o small && ./small
&& /compiler/gcc-trunk/bin/gcov small.c && cat small.c.gcov
File 'small.c'
Lines executed:75.00% of 4
Creating 'small.c.gcov'

Lines executed:75.00% of 4
        -:    0:Source:small.c
        -:    0:Graph:small.gcno
        -:    0:Data:small.gcda
        -:    0:Runs:1
        -:    1:int a;
    #####:    2:__attribute__((always_inline)) int b () {
       1*:    3:  return 0;
        -:    4:}
        1:    5:int main () {
        2:    6:  a - b () ;
        -:    7:}

Line #6 is wrongly marked as executed twice.
If I use lcov, the result I get is as follows:
$ clang-trunk -w -O0 -fcoverage-mapping
-fprofile-instr-generate=small.c.profraw small.c -o small && ./small &&
/compiler/llvm-trunk/bin/llvm-profdata merge small.c.profraw -o
small.c.profdata && /compiler/llvm-trunk/bin/llvm
-cov show small -instr-profile=small.c.profdata small.c
    1|       |int a;
    2|      1|__attribute__((always_inline)) int b () {
    3|      1|  return 0;
    4|      1|}
    5|      1|int main () {
    6|      1|  a - b () ;
    7|      1|}

Line #6 is marked as executed once.

Reply via email to