This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
optimization/7175: Calculation yields different results for version optimized with -O2
- From: weber at informatik dot uni-kl dot de
- To: gcc-gnats at gcc dot gnu dot org
- Date: 1 Jul 2002 11:48:13 -0000
- Subject: optimization/7175: Calculation yields different results for version optimized with -O2
- Reply-to: weber at informatik dot uni-kl dot de
>Number: 7175
>Category: optimization
>Synopsis: Calculation yields different results for version optimized with -O2
>Confidential: no
>Severity: serious
>Priority: medium
>Responsible: unassigned
>State: open
>Class: wrong-code
>Submitter-Id: net
>Arrival-Date: Mon Jul 01 04:56:01 PDT 2002
>Closed-Date:
>Last-Modified:
>Originator: Gunther Weber
>Release: gcc version 3.1
>Organization:
>Environment:
RedHat Linux 7.3 running on a 800 MHz Celeron (Coppermine) processor. Problem also occurs on an AMD Athlon(tm) XP 1700+ system.
GCC Build option:
Reading specs from /usr/global/lib/gcc-lib/i586-pc-linux-gnu/3.1/specs
Configured with: ./configure --prefix=/usr/global --enable-threads=posix
Thread model: posix
gcc version 3.1
>Description:
A program that calculates an expression yields different results when compiled with -O2 option as compared to -O1 or no optimization. The file attachment contains code with everything but the necessary code to reproduce the bug was removed. Note that trying to print variable conntents for debugging purposes gets rid of the bug. A complete log of compiling the program and its results is listed under How-To-Reperat.
>How-To-Repeat:
[weber@stella TestGCC]$ g++3.1 test.cc
[weber@stella TestGCC]$ ./a.out
Using second solution t=0
0.131997, 0.69765
[weber@stella TestGCC]$ g++3.1 -O1 test.cc
[weber@stella TestGCC]$ ./a.out
Using second solution t=0
0.131997, 0.69765
[weber@stella TestGCC]$ g++3.1 -O2 test.cc
[weber@stella TestGCC]$ ./a.out
Using second solution t=4.14165e-17
0.568462, -0.302107
[weber@stella TestGCC]$ g++3.1 -O2 -DPRINT_T test.cc
[weber@stella TestGCC]$ ./a.out
t1=2 t2=0
Using second solution t=0
0.131997, 0.69765
>Fix:
None that I know of except not to use -O2 option.
>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: application/octet-stream; name="test.cc"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="test.cc"
I2luY2x1ZGUgPGNtYXRoPgojaW5jbHVkZSA8aW9zdHJlYW0+Cgp2b2lkIGNvbXB1dGUoZG91Ymxl
IFJbMl0sIGRvdWJsZSB2MCwgZG91YmxlIHYxLCBkb3VibGUgdjIsIGRvdWJsZSB2MywgZG91Ymxl
IGlzb3ZhbCwgZG91YmxlIHBbMl0sIGRvdWJsZSBxWzJdKQp7CiAgZG91YmxlIGEgPSB2MSAtIHYw
OwogIGRvdWJsZSBiID0gdjMgLSB2MDsKICBkb3VibGUgYyA9IHYwICsgdjIgLSB2MSAtIHYzOwog
IGRvdWJsZSBkID0gdjAgLSBpc292YWw7CgogIGRvdWJsZSB4TSA9IChwWzBdICsgcVswXSkgLyAy
LjA7CiAgZG91YmxlIHlNID0gKHBbMV0gKyBxWzFdKSAvIDIuMDsKCiAgaWYgKGMgIT0gMCkgewog
ICAgZG91YmxlIHhTID0gKHYwIC0gdjMpIC8gYzsKICAgIGRvdWJsZSB5UyA9ICh2MCAtIHYxKSAv
IGM7CiAgICBkb3VibGUgYWxwaGEgPSB4UyAtIHhNOwogICAgZG91YmxlIGJldGEgPSB5UyAtIHlN
OwogICAgaWYgKGMqYWxwaGEqYmV0YSAhPSAwKSB7CiAgICAgIGRvdWJsZSBwID0gKGEqYWxwaGEg
KyBiKmJldGEgKyBjKih4TSpiZXRhICsgeU0qYWxwaGEpKSAvIChjKmFscGhhKmJldGEpOwogICAg
ICBkb3VibGUgcSA9IChhKnhNICsgYip5TSArIGMqeE0qeU0gKyBkKSAvIChjKmFscGhhKmJldGEp
OwogICAgICBkb3VibGUgZCA9IDAuMjUqcCpwLXE7CiAgICAgIGlmIChkID49IDApIHsKCWRvdWJs
ZSB0MSA9IC0wLjUqcCArIHN0ZDo6c3FydChkKTsKCWRvdWJsZSB0MiA9IC0wLjUqcCAtIHN0ZDo6
c3FydChkKTsKI2lmZGV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