This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug fortran/11251] New: g77 complex number program produces wrong code when optimising
- From: "jfb at npl dot co dot uk" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 19 Jun 2003 14:51:11 -0000
- Subject: [Bug fortran/11251] New: g77 complex number program produces wrong code when optimising
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
PLEASE REPLY TO gcc-bugzilla@gcc.gnu.org ONLY, *NOT* gcc-bugs@gcc.gnu.org.
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=11251
Summary: g77 complex number program produces wrong code when
optimising
Product: gcc
Version: 3.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: fortran
AssignedTo: unassigned@gcc.gnu.org
ReportedBy: jfb@npl.co.uk
CC: gcc-bugs@gcc.gnu.org
The following program (complete) works correctly when I use a simple compile
g77 -o test.exe test.f
It produces the answer
(-8.,0.) (-10.,0.) (4.,0.)
(-38.,0.) (20.,0.) (-26.,0.)
However, when I compile the same program with optimisation
g77 -O -o test.exe test.f
It gives the wrong answer:
(-8.,0.) (-10.,0.) (4.,0.)
(-38.,0.) (110.,0.) (-86.,0.) <<< this is wrong!
However, the -O2, -O3 and -O4 flags give the right answer!
Program listing follows:
-------------------------
program test
c ----------------------------------------------------------------------
c This program demonstrates a bug in g77. When compiled with
c optimiser flag -O, it produces incorrect code and the second
c result c is wrong. -O2,3 and 4 work ok! (and no optimisation).
c ----------------------------------------------------------------------
complex a(3),b(3),c(3)
a(1)=1
a(2)=2
a(3)=7
b(1)=-1
b(2)=2
b(3)=3
call cross(c,a,b)
write (*,*) c
call cross(c,c,b)
write (*,*) c
end
c ######################################################################
subroutine cross(c,a,b)
c ----------------------------------------------------------------------
c complex cross product
c c=||a1 a2 a3||
c ||b1 b2 b3||
c ----------------------------------------------------------------------
complex a(3),b(3),c(3),r(3)
r(1)=a(2)*b(3)-a(3)*b(2)
r(2)=a(3)*b(1)-a(1)*b(3)
r(3)=a(1)*b(2)-a(2)*b(1)
c(1)=r(1)
c(2)=r(2)
c(3)=r(3)
end