Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug
Bug#: 11767
Product:  
Component:  
Status: RESOLVED
Resolution: FIXED
Assigned To: Richard Henderson <rth@gcc.gnu.org>
Host:
Reported against  
Priority:  
Severity:  
Target Milestone:  
 
 
Target:
Reporter: Lothar Werzinger <lothar@xcerla.com>
Add CC:
CC:
Remove selected CCs
Build:
URL:
Summary:
Keywords:
Known to work:
Known to fail:

Attachment Description Type Created Size Actions
gccbug.ii the preprocessed file that causes the bug to show application/octet-stream 2003-08-01 20:45 92.75 KB Edit
GccTest.ii new test case with long instead of double text/plain 2003-08-04 21:39 87.51 KB Edit
Create a New Attachment (proposed patch, testcase, etc.) View All

Bug 11767 depends on: Show dependency tree
Show dependency graph
Bug 11767 blocks:

Additional Comments:






View Bug Activity   |   Format For Printing   |   Clone This Bug


Description:   Last confirmed: 2004-01-01 00:56 Opened: 2003-08-01 20:33
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 gccbug ( void )
  {
    {
      signed long const c_v(5);
      RawInteger i(c_v);
      signed long const c_v2(i.valueSignedLong());
      
      std::cout << "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;
    }
    {
      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;
    }
  }


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

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

------- Comment #1 From Lothar Werzinger 2003-08-01 20:45 -------
Created an attachment (id=4548) [edit]
the preprocessed file that causes the bug to show

here is the cmdline of the compile and run with and without code coverage
analysis.

lothar@janus$ c++ -DGCCBUG -save-temps -fPIC -W -Wall -Wpointer-arith
-Wno-uninitialized -Woverloaded-virtual -march=pentiumpro -fPIC
-fnon-call-exceptions -D__XRS_INLINE__ -g -fprofile-arcs -ftest-coverage -O0
-fstack-check -I. -I../.. -o gccbug gccbug.cpp -lgmp
gccbug.cpp: In function `int main(int, char**)':
gccbug.cpp:48: warning: unused parameter `int argc'
gccbug.cpp:48: warning: unused parameter `char**argv'
<~/workspace/XRS/src/cxx/math/test>
lothar@janus$ ./gccbug
long
5 5 0 1 0 1 1 0
double
5 5 0 1 0 1 0 1


lothar@janus$ c++ -DGCCBUG -save-temps -fPIC -W -Wall -Wpointer-arith
-Wno-uninitialized -Woverloaded-virtual -march=pentiumpro -fPIC
-fnon-call-exceptions -D__XRS_INLINE__ -g -O0 -fstack-check -I. -I../.. -o
gccbug gccbug.cpp -lgmp
gccbug.cpp: In function `int main(int, char**)':
gccbug.cpp:48: warning: unused parameter `int argc'
gccbug.cpp:48: warning: unused parameter `char**argv'
<~/workspace/XRS/src/cxx/math/test>
lothar@janus$ ./gccbug
long
5 5 0 1 0 1 1 0
double
5 5 0 1 0 1 1 0

------- Comment #2 From Andrew Pinski 2003-08-01 21:59 -------
I cannot reproduce this on 3.2.2, 3.2.3 or 3.3.1 (20030707).
I also cannot reproduce this on `gcc version 3.2.1 20021207 (Red Hat Linux 8.0 3.2.1-2)'.

------- Comment #3 From Andrew Pinski 2003-08-03 14:14 -------
I could reproduce it under 3.3.1 (20030707) but the problem is that gcc is
using 
excessive precission for the floating point so this is not a bug (actually this
is a dup of bug 
323).

*** This bug has been marked as a duplicate of 323 ***

------- Comment #4 From Lothar Werzinger 2003-08-04 17:01 -------
Is this really a duplicate? I read the description to 323 and it seemed it is
due to optimization 
switched on. I used -O0, therefore there should be NO optimization at all. And
it shoes up 
ONLY with the -fprofile-arcs -ftest-coverage switch. Is this really the same
origin? 

Lothar 

------- Comment #5 From Lothar Werzinger 2003-08-04 17:10 -------
I tried to compile the code with -ffloat-store as suggested in bug 323. It has
NO effect on this 
bug. Therefore I reopen the bug. 

Lothar 

------- Comment #6 From Andrew Pinski 2003-08-04 18:18 -------
It still is a dup of 323 because the problem is that the store happens so that
5.0 does not equal to 
5.0 and the options -fprofile-arcs -ftest-coverage just force the store to
happen that would not 
over-wise happen.  Also you are comparing by using equals which is never going
to be the same 
with floating point.

*** This bug has been marked as a duplicate of 323 ***

------- Comment #7 From Lothar Werzinger 2003-08-04 21:37 -------
I prepared an additional case, this time with unsigned long rather than double.
This should 
make clear that the bug is with -fprofile-arcs -ftest-coverage and not floating
point related. 
I will attach the preprocessed file like for the first case. 


lothar@janus$ c++ -save-temps -DGCCTEST -fPIC -W -Wall -Wpointer-arith
-Wno-uninitialized  
-Woverloaded-virtual -march=pentiumpro -fPIC -fnon-call-exceptions -g -O0
-fstack-check -o  
gcctest GccTest.cpp  
GccTest.cpp: In function `int main(int, char**)':  
GccTest.cpp:123: warning: unused parameter `int argc'  
GccTest.cpp:123: warning: unused parameter `char**argv'  
<~/workspace/XRS/src/cxx/utility/test>  
lothar@janus$ ./gcctest  
mc_isoValue=10000 msc_maxCurrencyID=9999  
mc_isoValue > msc_maxCurrencyID=1  
isGreater=1  
hurray  
mc_isoValue=10000 msc_maxCurrencyID=9999  
mc_isoValue > msc_maxCurrencyID=1  
isGreater=1  
hurray  

lothar@janus$ c++ -save-temps -DGCCTEST -fPIC -W -Wall -Wpointer-arith
-Wno-uninitialized  
-Woverloaded-virtual -march=pentiumpro -fPIC -fnon-call-exceptions -g
-fprofile-arcs  
-ftest-coverage -O0 -fstack-check -o gcctest GccTest.cpp  
GccTest.cpp: In function `int main(int, char**)':  
GccTest.cpp:123: warning: unused parameter `int argc'  
GccTest.cpp:123: warning: unused parameter `char**argv'  
<~/workspace/XRS/src/cxx/utility/test>  
lothar@janus$ ./gcctest  
mc_isoValue=10000 msc_maxCurrencyID=9999  
mc_isoValue > msc_maxCurrencyID=1  
isGreater=1  
hurray  
mc_isoValue=10000 msc_maxCurrencyID=9999  
mc_isoValue > msc_maxCurrencyID=0  
isGreater=0  
uhuh  


------- Comment #8 From Lothar Werzinger 2003-08-04 21:39 -------
Created an attachment (id=4562) [edit]
new test case with long instead of double

lothar@janus$ c++ -save-temps -DGCCTEST -fPIC -W -Wall -Wpointer-arith
-Wno-uninitialized -Woverloaded-virtual -march=pentiumpro -fPIC
-fnon-call-exceptions -g -fprofile-arcs -ftest-coverage -O0 -fstack-check -o
gcctest GccTest.cpp
GccTest.cpp: In function `int main(int, char**)':
GccTest.cpp:123: warning: unused parameter `int argc'
GccTest.cpp:123: warning: unused parameter `char**argv'
<~/workspace/XRS/src/cxx/utility/test>
lothar@janus$ ./gcctest
mc_isoValue=10000 msc_maxCurrencyID=9999
mc_isoValue > msc_maxCurrencyID=1
isGreater=1
hurray
mc_isoValue=10000 msc_maxCurrencyID=9999
mc_isoValue > msc_maxCurrencyID=0
isGreater=0
uhuh

------- Comment #9 From Lothar Werzinger 2003-08-04 21:40 -------
reopened due to new testcase 

------- Comment #10 From Andrew Pinski 2003-08-04 23:37 -------
Okay the problem is not per say with -fprofile-arcs -ftest-coverage but with 
-fnon-call-
exceptions and -fprofile-arcs.
I can confirm this on the mainline (20030804) Here is the reduced source but I
could not 
remove the dependent on string:
#include <string>
typedef unsigned long ACE_UINT32;
extern "C" void abort();

static ACE_UINT32 const msc_maxCurrencyID = 9999;

class ResourceBalanceType2
{
  public:
   explicit ResourceBalanceType2(
      ACE_UINT32 resourceBalanceTypeID,
      ACE_UINT32 isoValue,
      const std::string& rc_shortName,
      const std::string& rc_symbol
    );
  public:
    const ACE_UINT32 mc_resBalTypeID;
    const ACE_UINT32 mc_isoValue;
    const std::string mc_shortName;
    const std::string mc_symbol;
};
void f(){}
ResourceBalanceType2::ResourceBalanceType2(
  ACE_UINT32 resourceBalanceTypeID,
  ACE_UINT32 isoValue,
  const std::string& rc_shortName,
  const std::string& rc_symbol
):  mc_resBalTypeID(resourceBalanceTypeID),
  mc_isoValue(isoValue),
  mc_shortName(rc_shortName),
  mc_symbol(rc_symbol)
{
  bool isGreater = (mc_isoValue > msc_maxCurrencyID);
  f();
  bool temp = mc_isoValue > msc_maxCurrencyID;
  if(!isGreater) abort();
  if(!temp) abort();
}
int main ( int argc, char * argv[] )
{
    ACE_UINT32 const mc_isoValue = 10000;
    ResourceBalanceType2 rbResourceBalanceType2(3, mc_isoValue, "ATM", "M");
}

------- Comment #11 From Andrew Pinski 2003-08-05 00:43 -------
Changing this to target as I could not reproduce this on
powerpc-apple-darwin6.6 with 
the mainline.

------- Comment #12 From Lothar Werzinger 2003-08-05 01:51 -------
I removed -fnon-call-exceptions when building my code and it works as a
workaround for me. 
Thanks. 

------- Comment #13 From Andrew Pinski 2003-08-28 16:21 -------
Most likely related to bug 11975.

------- Comment #14 From Andrew Pinski 2004-01-01 00:56 -------
I just looked and 3.0.4 does not produce the wrong code for the simplified test
case.

------- Comment #15 From Richard Henderson 2004-03-02 23:39 -------
Working on a patch.

------- Comment #16 From CVS Commits 2004-03-03 00:45 -------
Subject: Bug 11767

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_4-branch
Changes by:	rth@gcc.gnu.org	2004-03-03 00:45:07

Modified files:
	gcc            : ChangeLog coverage.c optabs.c 
Added files:
	gcc/testsuite/g++.dg/other: profile1.C 

Log message:
	PR middle-end/11767
	* coverage.c (coverage_counter_ref): Set MEM_NOTRAP_P.
	* optabs.c (prepare_cmp_insn): Force trapping memories to registers
	before the compare, if flag_non_call_exceptions.
	* g++.dg/other/profile1.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=2.2326.2.280&r2=2.2326.2.281
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/coverage.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.27.4.1&r2=1.27.4.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/optabs.c.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=1.204.4.1&r2=1.204.4.2
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/other/profile1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_4-branch&r1=NONE&r2=1.1.2.1


------- Comment #17 From CVS Commits 2004-03-03 00:46 -------
Subject: Bug 11767

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	rth@gcc.gnu.org	2004-03-03 00:46:07

Modified files:
	gcc            : ChangeLog coverage.c optabs.c 

Log message:
	PR middle-end/11767
	* coverage.c (coverage_counter_ref): Set MEM_NOTRAP_P.
	* optabs.c (prepare_cmp_insn): Force trapping memories to registers
	before the compare, if flag_non_call_exceptions.
	* g++.dg/other/profile1.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&r1=2.3008&r2=2.3009
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/coverage.c.diff?cvsroot=gcc&r1=1.29&r2=1.30
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/optabs.c.diff?cvsroot=gcc&r1=1.208&r2=1.209


------- Comment #18 From CVS Commits 2004-03-03 00:48 -------
Subject: Bug 11767

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	gcc-3_3-branch
Changes by:	rth@gcc.gnu.org	2004-03-03 00:48:54

Modified files:
	gcc            : ChangeLog optabs.c 
Added files:
	gcc/testsuite/g++.dg/other: profile1.C 

Log message:
	PR middle-end/11767
	* optabs.c (prepare_cmp_insn): Force trapping memories to registers
	before the compare, if flag_non_call_exceptions.
	* g++.dg/other/profile1.C: New.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.16114.2.917&r2=1.16114.2.918
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/optabs.c.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=1.153.2.5&r2=1.153.2.6
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/other/profile1.C.diff?cvsroot=gcc&only_with_tag=gcc-3_3-branch&r1=NONE&r2=1.2.2.1


------- Comment #19 From Richard Henderson 2004-03-03 00:54 -------
http://gcc.gnu.org/ml/gcc-patches/2004-03/msg00229.html

------- Comment #20 From CVS Commits 2004-03-04 07:49 -------
Subject: Bug 11767

CVSROOT:	/cvs/gcc
Module name:	gcc
Branch: 	hammer-3_3-branch
Changes by:	steven@gcc.gnu.org	2004-03-04 07:49:47

Modified files:
	gcc            : ChangeLog.hammer optabs.c stmt.c 
	gcc/testsuite  : ChangeLog.hammer 
Added files:
	gcc/testsuite/g++.dg/other: profile1.C 
	gcc/testsuite/gcc.c-torture/execute: 20040302-1.c 

Log message:
	PR middle-end/11767
	* optabs.c (prepare_cmp_insn): Force trapping memories to registers
	before the compare, if flag_non_call_exceptions.
	
	PR middle-end/14327
	* stmt.c (expand_computed_goto): Do do_pending_stack_adjust before
	emitting the label, not after.
	
	testsuite/
	* g++.dg/other/profile1.C: New test for PR11767.
	* gcc.c-torture/execute/20040302-1.c: New test for PR14327.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/ChangeLog.hammer.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.1.2.351&r2=1.1.2.352
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/optabs.c.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.150.2.10&r2=1.150.2.11
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/stmt.c.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.273.2.13&r2=1.273.2.14
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/ChangeLog.hammer.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=1.1.2.13&r2=1.1.2.14
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/g++.dg/other/profile1.C.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=NONE&r2=1.2.6.1
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/testsuite/gcc.c-torture/execute/20040302-1.c.diff?cvsroot=gcc&only_with_tag=hammer-3_3-branch&r1=NONE&r2=1.1.8.1


Bug List: (This bug is not in your last search results)   Show last search results      Search page      Enter new bug