Bug 233941 - Complex arithmetic statement produces wrong result
Summary: Complex arithmetic statement produces wrong result
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 4
Classification: Red Hat
Component: gcc
Version: 4.4
Hardware: All
OS: Linux
medium
high
Target Milestone: ---
: ---
Assignee: Jakub Jelinek
QA Contact:
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2007-03-26 07:51 UTC by Peter Wainwright
Modified: 2007-11-17 01:14 UTC (History)
0 users

Fixed In Version: RHBA-2007-0803
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2007-11-15 16:08:43 UTC
Target Upstream Version:
Embargoed:


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


Links
System ID Private Priority Status Summary Last Updated
Red Hat Product Errata RHBA-2007:0803 0 normal SHIPPED_LIVE gcc bug fix update 2007-11-14 17:44:01 UTC

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



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