Bug 60443

Summary: Improper optimization in g++ in some cases that work in gcc
Product: [Retired] Red Hat Linux Reporter: mach1
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED DUPLICATE QA Contact: Brian Brock <bbrock>
Severity: medium Docs Contact:
Priority: medium    
Version: 7.1   
Target Milestone: ---   
Target Release: ---   
Hardware: alpha   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2002-02-27 20:23:37 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:
Attachments:
Description Flags
Test program that demonstrates the problem. none

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