This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

different code behaviour with -fprofile-arcs -ftest-coverage


Hi,

I have a problem with gcc on Red hat Linux 9

lothar@janus$ gcc --version
gcc (GCC) 3.2.2 20030222 (Red Hat Linux 3.2.2-5)
Copyright (C) 2002 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.  There is
NO warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR
PURPOSE.

The code behaviour is different if I compile with -fprofile-arcs
-ftest-coverage or not. In both cases I compiled with -O0 (no
optimizations). I noticed it, as some of my cppunit tests failed. Here
is one of the tests: It basically only stores a value in a class which
acts as a wrapper to the GNU MP library and get's the same value back.
To my surprise the value I get back is both, the same and not the same
as I put in (at least according to the C++ comparison operators
available).

void testvalueUnsignedLong()
{
    unsigned long const c_v(5);
    RawInteger i(c_v);
    unsigned long const c_v2(i.valueUnsignedLong());
    
    std::cout << "unsigned long " << std::endl
              << c_v2 << " "
              << c_v  << " "
              << (c_v2 > c_v)  << " "
              << (c_v2 >= c_v) << " "
              << (c_v2 < c_v)  << " "
              << (c_v2 <= c_v) << " "
              << (c_v2 == c_v) << " "
              << (c_v2 != c_v) << " "
              << std::endl;
    
    CPPUNIT_ASSERT(i.valueUnsignedLong() == c_v);
}
 
void testvalueDouble()
{
    double const c_v(5.0);
    RawInteger i(c_v);
    double const c_v2(i.valueDouble());
    
    std::cout << "double " << std::endl
              << c_v2 << " "
              << c_v  << " "
              << (c_v2 > c_v)  << " "
              << (c_v2 >= c_v) << " "
              << (c_v2 < c_v)  << " "
              << (c_v2 <= c_v) << " "
              << (c_v2 == c_v) << " "
              << (c_v2 != c_v) << " "
              << std::endl;
              
    CPPUNIT_ASSERT(i.valueDouble() == c_v);
}
 

Here's the output of this code fragment:
  without code coverage:
unsigned long 
5 5 0 1 0 1 1 0 
double 
5 5 0 1 0 1 1 0 

  with code coverage:
unsigned long 
5 5 0 1 0 1 1 0 
double 
5 5 0 1 0 1 0 1 


How can the comparison operators claim the value is both, the same and
different? And why does it affect only the double type?

Has anyone an idea how this can happen? Is there a way to get correct
results even with code coverage analysis?

If there is need, I can provide the code for the RawInteger class.


P.S.
I was much amused when I modified my test code to

    std::cout << "double " << std::endl;
    for (int var = 0; var < 10; ++var)
    {
      double const c_v((double)var);
      RawInteger i(c_v);
      double const c_v2(i.valueDouble());
      if ((c_v2 == c_v) != 0)
      {
        bool r = (c_v2 == c_v);
        std::cout << " " << var << " " << (c_v2 == c_v) << " " << r;
      } /* end of if */
    } /* end of for */
    std::cout << std::endl;

and got

double 
 0 0 0 1 0 0 2 0 0 3 0 0 4 0 0 5 0 0 6 0 0 7 0 0 8 0 0 9 0 0

If the value of (c_v2 == c_v) IS zero, then why has the if being
executed?

Thanks in advance,

Lothar
-- 
Lothar Werzinger Dipl.-Ing. Univ.
framework & platform architect
Xcerla Corporation
275 Tennent Avenue, Suite 202
Morgan Hill, Ca 95037
email: lothar@xcerla.com
phone: +1-408-776-9018


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]