I compiled the following program with “gcc -fprofile-arcs -ftest-coverage test.c”:
int main() {
int a = 1;
int b = 1;
a && b;
}
After running the program, an invocation of “gcov -bc test.c” reports that 50% of 4 branches were taken at least once. Why does gcov say the program has four branches, instead of two? After running the following program, gcov correctly reports that 50% of 2 branches were taken at least once:
int main() {
int a = 1;
if (a)
a = 0;
else
a = 1;
}
Apparently
gcovis consideringa&&bto be the following:Though I’m fairly certain the actual CPU instructions will translate to a single branch.