gnu.gcc.help
[Top] [All Lists]

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

Subject: Re: what does the "branch" mean in the gcov command?
From: asobou.tama@xxxxxxxxx
Date: Wed, 16 Jul 2008 23:02:20 -0700 (PDT)
Newsgroups: gnu.gcc.help


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.


<Prev in Thread] Current Thread [Next in Thread>