Bug 60443 - Improper optimization in g++ in some cases that work in gcc
Improper optimization in g++ in some cases that work in gcc
Status: CLOSED DUPLICATE of bug 58746
Product: Red Hat Linux
Classification: Retired
Component: gcc (Show other bugs)
alpha Linux
medium Severity medium
: ---
: ---
Assigned To: Jakub Jelinek
Brian Brock
Depends On:
  Show dependency treegraph
Reported: 2002-02-27 15:22 EST by mach1
Modified: 2007-04-18 12:40 EDT (History)
0 users

See Also:
Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2002-02-27 15:23:37 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
Test program that demonstrates the problem. (447 bytes, text/plain)
2002-02-27 15:23 EST, mach1
no flags Details

  None (edit)
Description mach1 2002-02-27 15:22:14 EST
From Bugzilla Helper:
User-Agent: Mozilla/5.0 (X11; U; Linux alpha; en-US; rv:0.9.8+) Gecko/20020203

Description of problem:
In some cases g++ (version 2.96) impoperly optimizes expressions when they
contain constants and several implied type coersions. The same expressions
compiled with gcc (version 2.96) do not exhibit the problem. I will attach a
simple test program that demonstrates the problem. The program contains four
equivalent versions of the same expression, two with an variable replaced with a
const variable of the same type. All four expressions should compute the same
value and do when compiled with gcc, but do not when compiled with g++.

An examination of the generated assemply code reveals that when the const
variable is used, the compiler ignores the effects the implied type coersions
have on the computation and overeagerly optimizes the expression code. The same
result occurs when the const variable is replaced with an actual constant.

Version-Release number of selected component (if applicable): 2.96

How reproducible:

Steps to Reproduce:
1.gcc test.c
3.g++ test.c

Actual Results:  Each time the program is run it prints four lines showing the
expression and its resultant value. The first time the program is run (the
version compiled with gcc), the four resultant values are the same. The second
time the program is run (the version compiled with g++), the first and third
resultant values are the same and match the results from the first run. The
second and fourth resultant values are the same, but do not match the values
from the first run.

Expected Results:  It is expected that the second run would produce exactly the
same results as the first run.

Additional info:
Comment 1 mach1 2002-02-27 15:23:32 EST
Created attachment 46840 [details]
Test program that demonstrates the problem.
Comment 2 Jakub Jelinek 2002-03-04 09:24:17 EST

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

Note You need to log in before you can comment on or make changes to this bug.