Bug 233941 - Complex arithmetic statement produces wrong result
Complex arithmetic statement produces wrong result
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: gcc (Show other bugs)
All Linux
medium Severity high
: ---
: ---
Assigned To: Jakub Jelinek
Depends On:
  Show dependency treegraph
Reported: 2007-03-26 03:51 EDT by Peter Wainwright
Modified: 2007-11-16 20:14 EST (History)
0 users

See Also:
Fixed In Version: RHBA-2007-0803
Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of:
Last Closed: 2007-11-15 11:08:43 EST
Type: ---
Regression: ---
Mount Type: ---
Documentation: ---
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---

Attachments (Terms of Use)
gcc34-rh233941.patch (1.22 KB, patch)
2007-04-02 07:38 EDT, Jakub Jelinek
no flags Details | Diff

  None (edit)
Description Peter Wainwright 2007-03-26 03:51:39 EDT
Description of problem:

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

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


How to reproduce:

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

      subroutine sub(z)
      implicit none
      complex*16 z
      z = dcmplx(-dimag(z), dreal(z))
      write (6, *) z
      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 07:38:02 EDT
Created attachment 151415 [details]

So far very lightly tested fix.
Comment 2 RHEL Product and Program Management 2007-05-09 01:19:06 EDT
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
Comment 8 errata-xmlrpc 2007-11-15 11:08:43 EST
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.


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