https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120492
Bug ID: 120492
Summary: Wrong line coverage for C++ push_back() of a char
pointer into string vector
Product: gcc
Version: 16.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: ---
Hit the issue when measuring coverage for
https://sources.debian.org/src/lzma/9.22-2.2/CPP/7zip/Bundles/LzmaCon/lzmp.cpp/#L657
The original report includes
10: 654: stdoutput = true;
-: 655:
-: 656: /* FIXME: get rid of this */
20: 657: filenames.push_back("-");
Line coverage at line 657 is wrong and should be 10 to match line 654.
The triggering condition is invoking "push_back()" onto a string vector
with a char pointer.
I will provide a reproducible reduced example soon.
--- Comment #1 from Wentao Zhang <wentaoz5 at illinois dot edu> ---
Here is a reduced program:
$ gcc --version | head -1
gcc (GCC) 16.0.0 20250511 (experimental)
$ cat > test.cc << 'EOF'
#include <vector>
#include <string>
int main() {
int one = 1;
std::vector<std::string> v;
std::string s = "hello";
if (one)
v.push_back("hello");
if (one)
v.push_back(s);
if (1)
v.push_back("hello");
return 0;
}
EOF
$ g++ --coverage test.cc -o test; ./test; gcov test
$ grep 'if (one)' -A4 test.cc.gcov
1: 9: if (one)
2: 10: v.push_back("hello");
-: 11:
1: 12: if (one)
1: 13: v.push_back(s);
-: 14:
-: 15: if (1)
1: 16: v.push_back("hello");
All push_back() instances at line 10, 13 and 16 should have be executed
only once, but when (1) it is within a conditional branch (2) the argument
is a string literal (line 10), the line coverage is wrongly "2".