Red Hat Bugzilla – Bug 60443
Improper optimization in g++ in some cases that work in gcc
Last modified: 2007-04-18 12:40:39 EDT
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
Steps to Reproduce:
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.
Created attachment 46840 [details]
Test program that demonstrates the problem.
*** This bug has been marked as a duplicate of 58746 ***