public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug gcov-profile/110561] New: gcov counts closing bracket in a function as executable, lowering coverage statistics
@ 2023-07-05 14:53 carlosgalvezp at gmail dot com
  2023-07-05 15:58 ` [Bug gcov-profile/110561] " vanyacpp at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: carlosgalvezp at gmail dot com @ 2023-07-05 14:53 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 110561
           Summary: gcov counts closing bracket in a function as
                    executable, lowering coverage statistics
           Product: gcc
           Version: 14.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: gcov-profile
          Assignee: unassigned at gcc dot gnu.org
          Reporter: carlosgalvezp at gmail dot com
                CC: marxin at gcc dot gnu.org
  Target Milestone: ---

Created attachment 55481
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55481&action=edit
Line 18 wrongly reported as lacking code coverage

Hi!

We are using GCC trunk on Ubuntu 22.04
(d08f2e4f74583e27002368989bba197f8eb7f6d2).

Consider the following code example:

#include <vector>
#include <string>

std::string joinPath(std::vector<std::string> const& path_parts)
{
    std::string path{};
    for (auto const& path_part : path_parts)
    {
        if (!path.empty())
        {
            path += "/";
        }

        path += path_part;
    }

    return path;
}

int main()
{
  std::vector<std::string> strings = {"foo", "bar"};
  joinPath(strings);
}

Following this process (taken from here:
https://medium.com/@xianpeng.shen/use-gcov-and-lcov-to-perform-code-coverage-testing-for-c-c-projects-c85708b91c78)
to compute coverage:

$ g++ main.cpp --coverage -o main
$ ./main
$ gcov main.cpp
$ lcov --capture --directory . --output-file coverage.info
$ genhtml coverage.info --output-directory out

Leads to a coverage report that says that line 18 is missing code coverage,
which is incorrect since it's just the closing bracket of the function (see
attached picture).

I can see that things go wrong already at the gcov output, so it's not a
rendering/LCOV issue:

$ cat main.cpp.gcov 
        -:    0:Source:main.cpp
        -:    0:Graph:main.gcno
        -:    0:Data:main.gcda
        -:    0:Runs:1
        -:    1:#include <vector>
        -:    2:#include <string>
        -:    3:
        1:    4:std::string joinPath(std::vector<std::string> const&
path_parts)
        -:    5:{
        1:    6:    std::string path{};
        3:    7:    for (auto const& path_part : path_parts)
        -:    8:    {
        2:    9:        if (!path.empty())
        -:   10:        {
        1:   11:            path += "/";
        -:   12:        }
        -:   13:
        2:   14:        path += path_part;
        -:   15:    }
        -:   16:
        1:   17:    return path;
    =====:   18:}
        -:   19:
        1:   20:int main()
        -:   21:{
        2:   22:  std::vector<std::string> strings = {"foo", "bar"};
        1:   23:  joinPath(strings);
        1:   24:}

This problem does not happen always, just on particular cases (I haven't been
able to establish a pattern).

Do you know what could be the problem? Thanks!

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2023-07-18 15:13 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-05 14:53 [Bug gcov-profile/110561] New: gcov counts closing bracket in a function as executable, lowering coverage statistics carlosgalvezp at gmail dot com
2023-07-05 15:58 ` [Bug gcov-profile/110561] " vanyacpp at gmail dot com
2023-07-05 16:00 ` pinskia at gcc dot gnu.org
2023-07-05 16:22 ` carlosgalvezp at gmail dot com
2023-07-05 19:41 ` carlosgalvezp at gmail dot com
2023-07-18 15:13 ` carlosgalvezp at gmail dot com

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).