Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what does the "branch" mean in the gcov command?

1,652 views
Skip to first unread message

Dan

unread,
Jul 1, 2008, 10:02:40 PM7/1/08
to
I am using the gcov command of gcc and have some puzzles on it.

For an if-statement contain two expressions such as "if(a>b && c>d)",
there will be three branches: branch 0, branch 1, and branch 2 in the
corresponding .gcov file. What do these branches mean?

For a switch-statement, if there are 5 case-statement and 1 default-
statement, then there will be 7 (not 6) branches. Why?

Could you please help me figure out the meaning of these branches?
Thanks a lot!

asobo...@gmail.com

unread,
Jul 17, 2008, 2:02:20 AM7/17/08
to

Hi, Dan.
Did you get answer of your question?

I use GCC coverage system and GCOV report for my job. I hope my
mention helps you. At first, my GCC version is "gcc version 3.4.6
20060404 (Red Hat 3.4.6-3)". And GCOV is "gcov (GCC) 3.4.6 20060404
(Red Hat 3.4.6-3)". Please remain the versions.

I try to your code as "if(a>b && c>d)". And I got GCOV report as
below:

| 1: 32: a=1;b=0;c=1;d=0;
| 1: 33: if( a>b && c>d ) {
| branch 0 taken 100% (fallthrough)
| branch 1 taken 0%
| branch 2 taken 100% (fallthrough)
| branch 3 taken 0%
| 1: 34: printf("hit\n");
| call 0 returned 100%
| -: 35: }

In your report, you got only 3 branches. But I got 4 branches. I can
explain you of my case. The statement "if( a>b && c>d )" will generate
4 branches. Because GCC may compile to following program flow.

| [1] compare a>b, if true branch to [2] else branch to [4]
| [2] compare c>d, if true branch to [3] else branch to [4]
| [3] call printf()
| [4] next statement

There are 4 branches. if statement seems only 2 branches, just true or
false. But compiler will resolve conditional expressions. Therefore
the condisinal expression makes more complexed branches.

0 new messages