Bug 60443 - Improper optimization in g++ in some cases that work in gcc
Summary: Improper optimization in g++ in some cases that work in gcc
Keywords:
Status: CLOSED DUPLICATE of bug 58746
Alias: None
Product: Red Hat Linux
Classification: Retired
Component: gcc
Version: 7.1
Hardware: alpha
OS: Linux
medium
medium
Target Milestone: ---
Assignee: Jakub Jelinek
QA Contact: Brian Brock
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2002-02-27 20:22 UTC by mach1
Modified: 2007-04-18 16:40 UTC (History)
0 users

Fixed In Version:
Clone Of:
Environment:
Last Closed: 2002-02-27 20:23:37 UTC
Embargoed:


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

Description mach1 2002-02-27 20:22:14 UTC
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:
Always

Steps to Reproduce:
1.gcc test.c
2../a.out
3.g++ test.c
4../a.out


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 20:23:32 UTC
Created attachment 46840 [details]
Test program that demonstrates the problem.

Comment 2 Jakub Jelinek 2002-03-04 14:24:17 UTC

*** 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.