This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/7719: gcc with -O2 generates wrong code
- From: Petr dot Savicky at cuni dot cz
- To: gcc-gnats at gcc dot gnu dot org
- Date: Mon, 26 Aug 2002 02:30:02 +0200
- Subject: optimization/7719: gcc with -O2 generates wrong code
>Number: 7719
>Category: optimization
>Synopsis: gcc with -O2 generates wrong code
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Sun Aug 25 17:36:00 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Petr Savicky
>Release: 3.0.4 (SuSE), also 2.95.3 (SuSE) and 2.91.66 (RedHat)
>Organization:
>Environment:
System: Linux linux 2.4.18-4GB #1 Fri Apr 5 15:14:39 UTC 2002 i686 unknown
Architecture: i686
host: i486-suse-linux-gnu
build: i486-suse-linux-gnu
target: i486-suse-linux-gnu
configured with: ../configure --enable-threads=posix --enable-long-long --prefix=/opt/experimental --with-local-prefix=/usr/local --enable-languages=c,c++,f77,objc,java --disable-nls --enable-shared i486-suse-linux
The exact set of compile options used is:
gcc -I$RBASE/include
-I/usr/local/include
-D__NO_MATH_INLINES
-mieee-fp
-fPIC
-g
-O2
-c grow.c -o grow.o
I tested the problem on three different computers (all PCs with linux).
The above info is from one of them.
>Description:
If compiled with -O2, then at some step of the computation,
line 3284 of grow.i (line 400 of grow.c), i.e.
if (val >= devtarget || val >= *bval) return;
does not perform the return command, although all the
variables val, *bval, devtarget are equal.
The commands at lines 3285-3290 in grow.i print
GROW: 5.924155689933546576 val
GROW: 5.924155689933546576 devtarget
GROW: 5.924155689933546576 *bval
GROW: 0.000000e+00 *bval-val
This behaviour is fully deterministic.
If compiled without -O2, these lines do not occur in the output.
>How-To-Repeat:
The preprocessed source code is http://www.cs.cas.cz/~savicky/R_tree/grow.i
If you need to run the program in the situation, when the
error appears, it is necessary to install R-1.5.1
(www.r-project.org) with the default settings, i.e. with -O2
in gcc and g++ options. Then, perform the following steps:
1. put http://www.cs.cas.cz/~savicky/R_tree/tree_o2_error-3.tar.gz
and http://www.cs.cas.cz/~savicky/R_tree/corrupt_tree_o2-2.tar.gz
into a work directory and cd to this directory.
2. tar -zxf tree_o2_error-3.tar.gz
tar -zxf corrupt_tree_o2-2.tar.gz
3. R CMD INSTALL tree/
4. cd corrupt_tree
5. R (this should give you the R prompt)
6. source("script.R") (in the R prompt)
This should produce the lines with "GROW" copied above.
The problem is indeed in a wrong compilation of grow.c.
If this file alone is compiled without -O2, linked
together with treefix.o into tree.so and copied to
$RBASE/library/tree/libs/, the problem disappears.
(The script tree/src/recompile.sh, which I used for
this recompilation on my computer is included in the
tar package).
>Fix:
Don't use optimization.
>Release-Note:
>Audit-Trail:
>Unformatted: