Bug 11767 - [3.3/3.4/4.0 Regression] different code behaviour with -fnon-call-exceptions -fprofile-arcs
Summary: [3.3/3.4/4.0 Regression] different code behaviour with -fnon-call-exceptions ...
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: middle-end (show other bugs)
Version: 3.2.2
: P2 normal
Target Milestone: 3.4.0
Assignee: Richard Henderson
URL:
Keywords: wrong-code
Depends on:
Blocks:
 
Reported: 2003-08-01 20:33 UTC by Lothar Werzinger
Modified: 2004-09-13 14:15 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work: 3.0.4
Known to fail:
Last reconfirmed: 2004-01-01 00:56:17


Attachments
the preprocessed file that causes the bug to show (92.75 KB, application/octet-stream)
2003-08-01 20:45 UTC, Lothar Werzinger
Details
new test case with long instead of double (87.51 KB, text/plain)
2003-08-04 21:39 UTC, Lothar Werzinger
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Lothar Werzinger 2003-08-01 20:33:57 UTC
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 Lothar Werzinger 2003-08-01 20:45:51 UTC
Created attachment 4548 [details]
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 Andrew Pinski 2003-08-01 21:59:32 UTC
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 Andrew Pinski 2003-08-03 14:14:28 UTC
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 Lothar Werzinger 2003-08-04 17:01:51 UTC
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 Lothar Werzinger 2003-08-04 17:10:07 UTC
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 Andrew Pinski 2003-08-04 18:18:35 UTC
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 Lothar Werzinger 2003-08-04 21:37:30 UTC
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 Lothar Werzinger 2003-08-04 21:39:55 UTC
Created attachment 4562 [details]
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 Lothar Werzinger 2003-08-04 21:40:27 UTC
reopened due to new testcase 
Comment 10 Andrew Pinski 2003-08-04 23:37:02 UTC
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 Andrew Pinski 2003-08-05 00:43:32 UTC
Changing this to target as I could not reproduce this on powerpc-apple-darwin6.6 with 
the mainline.
Comment 12 Lothar Werzinger 2003-08-05 01:51:33 UTC
I removed -fnon-call-exceptions when building my code and it works as a workaround for me. 
Thanks. 
Comment 13 Andrew Pinski 2003-08-28 16:21:02 UTC
Most likely related to bug 11975.
Comment 14 Andrew Pinski 2004-01-01 00:56:17 UTC
I just looked and 3.0.4 does not produce the wrong code for the simplified test case.
Comment 15 Richard Henderson 2004-03-02 23:39:46 UTC
Working on a patch.
Comment 16 GCC Commits 2004-03-03 00:45:12 UTC
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 GCC Commits 2004-03-03 00:46:09 UTC
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 GCC Commits 2004-03-03 00:48:56 UTC
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 Richard Henderson 2004-03-03 00:54:02 UTC
http://gcc.gnu.org/ml/gcc-patches/2004-03/msg00229.html
Comment 20 GCC Commits 2004-03-04 07:49:53 UTC
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