Bug 233941

Summary: Complex arithmetic statement produces wrong result
Product: Red Hat Enterprise Linux 4 Reporter: Peter Wainwright <peter.wainwright>
Component: gccAssignee: Jakub Jelinek <jakub>
Status: CLOSED ERRATA QA Contact:
Severity: high Docs Contact:
Priority: medium    
Version: 4.4   
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: RHBA-2007-0803 Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2007-11-15 16:08:43 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
gcc34-rh233941.patch none

Description Peter Wainwright 2007-03-26 07:51:39 UTC
Description of problem:

A complex arithmetic statement is compiled wrongly and produces the
wrong result


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

gcc-g77-3.4.6-3.1

How to reproduce:

      program bugtest
      implicit none
      complex*16 z
      z = dcmplx(1.0, 2.0)
      call sub(z)
      stop
      end program bugtest

      subroutine sub(z)
      implicit none
      complex*16 z
      z = dcmplx(-dimag(z), dreal(z))
      write (6, *) z
      return
      end subroutine sub

If you compile this without optimization (g77 bugtest.f -o bugtest)
and run it you get the output (-2.,-2.) instead of (-2.,1.)

It is pretty obvious what is happening: the important line
(which implements z := iz) is being compiled as

x := -y
y := x

which is pretty stupid.  This problem does NOT occur for the more
modern gfortran compiler, nor does it occur if you use any
optimization flags (-O2, -O3 etc.)

Examination of the machine code shows that indeed the result of
x := -y overwrites x before the value is read for the calculation
of y.

Comment 1 Jakub Jelinek 2007-04-02 11:38:02 UTC
Created attachment 151415 [details]
gcc34-rh233941.patch

So far very lightly tested fix.

Comment 2 RHEL Program Management 2007-05-09 05:19:06 UTC
This request was evaluated by Red Hat Product Management for inclusion in a Red
Hat Enterprise Linux maintenance release.  Product Management has requested
further review of this request by Red Hat Engineering, for potential
inclusion in a Red Hat Enterprise Linux Update release for currently deployed
products.  This request is not yet committed for inclusion in an Update
release.

Comment 8 errata-xmlrpc 2007-11-15 16:08:43 UTC
An advisory has been issued which should help the problem
described in this bug report. This report is therefore being
closed with a resolution of ERRATA. For more information
on the solution and/or where to find the updated files,
please follow the link below. You may reopen this bug report
if the solution does not work for you.

http://rhn.redhat.com/errata/RHBA-2007-0803.html