branches within C++ destructors

Rohit Gupta rohit.guptakec@gmail.com
Thu Feb 25 10:23:00 GMT 2010


HI all,

  I have another query related to virtual destructor in gcc.
In present gcc version 4.4.3 for class for sample program:-
------------------------
class A
{
public:
         A()
         {
         }

         virtual ~A();
};
         A::~A()
         {
         }

int main(int argc, char ** argv)
{

         A a;

         return 0;
}
--------------------------
we have only two branches as:-
-------------------------------------------------------
        -:    8:        virtual ~A();
         -:    9:};
function A::~A() called 1 returned 100% blocks executed 75%
function A::~A() called 0 returned 0% blocks executed 0%
         1:   10:        A::~A()
         -:   11:        {
         1:   12:        }
branch  0 taken 0% (fallthrough)
branch  1 taken 100%
call    2 never executed
call    3 never executed
call    4 never executed
------------------------------------------------------------------
which I has interpreted as :
In virtual destructor there are actually two destructors in which one 
takes care about base classes and other about the same class.(am I 
correct ??) So to have two branches looks OK

But for same program the result are different in gcc version 4.1.2.The 
result contains 6 branches and the output is as :

----------------
8:        virtual ~A();
         -:    9:};
function A::~A() called 0 returned 0% blocks executed 0%
function A::~A() called 1 returned 100% blocks executed 75%
function A::~A() called 0 returned 0% blocks executed 0%
         1:   10:        A::~A()
         -:   11:        {
         1:   12:        }
branch  0 never executed
branch  1 never executed
call    2 never executed
branch  3 taken 0% (fallthrough)
branch  4 taken 100%
call    5 never executed
branch  6 never executed
branch  7 never executed
call    8 never executed
         -:   13
---------------
Can someone tell me the logic about these branches and what  optimizer 
improvements were done in newer version.

======================

Also in the gcov branch coverage we have something like at end of code :-

------------------------------------

function __static_initialization_and_destruction_0(int, int) called 1 
returned 100% blocks executed 100%
function global constructors keyed to main called 1 returned 100% blocks 
executed 100%
         3:   54:}
branch  0 taken 100% (fallthrough)
branch  1 taken 0%
branch  2 taken 100% (fallthrough)
branch  3 taken 0%
call    4 returned 100%
------------------------------------------------


It is not the part of actual code, why do we have it and what its 
significance in terms of branches . Can we omit it from the coverage??

Thanks,
ROHIT



More information about the Gcc mailing list