[Bug fortran/70198] simple test floating point sequence gives incorrect values-- optimizer changes them

2016-03-14 Thread scott.b.dorsey at nasa dot gov
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70198

--- Comment #7 from scott.b.dorsey at nasa dot gov ---
Oh, that is lovely.  Many many thanks.

This code is from the "Numerical Recipes in Fortran" book and has been used
around here as a standard
test for the past 40 years without anyone noticing this.
--scott


From: dominiq at lps dot ens.fr [gcc-bugzi...@gcc.gnu.org]
Sent: Saturday, March 12, 2016 4:32 AM
To: s.b.dor...@larc.nasa.gov
Subject: [Bug fortran/70198] simple test floating point sequence gives
incorrect values-- optimizer changes them

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70198

--- Comment #6 from Dominique d'Humieres  ---
> If the code is compiled with the -fno-automatic option,
> one generates the desired result.  Note I said desired,
> not correct, because the code has a significant bug.
> When m=2 (see comment #4), the computed goto jumps to
> label 4.  The do-loop with the label 6 is executed.
> The variable 'a' is undefined.  It appears that this
> subroutine needs a SAVE statement.

Same problem with the array q. The code gives the "desired"
result with the following patch

--- pr70198.f   2016-03-11 22:10:39.0 +0100
+++ pr70198_db_1.f  2016-03-12 10:26:36.0 +0100
@@ -164,6 +164,7 @@ C
 C  This routine performs Runge-Kutta calculation by Gills Method
 C
   dimension y(10),f(10),q(10)
+  save a, q
   m=m+1
   go to (1,4,5,3,7), m
 1 do 2 i=1,n

--
You are receiving this mail because:
You reported the bug.

[Bug fortran/70198] simple test floating point sequence gives incorrect values-- optimizer changes them

2016-03-12 Thread dominiq at lps dot ens.fr
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70198

--- Comment #6 from Dominique d'Humieres  ---
> If the code is compiled with the -fno-automatic option,
> one generates the desired result.  Note I said desired,
> not correct, because the code has a significant bug.
> When m=2 (see comment #4), the computed goto jumps to
> label 4.  The do-loop with the label 6 is executed.
> The variable 'a' is undefined.  It appears that this
> subroutine needs a SAVE statement.

Same problem with the array q. The code gives the "desired"
result with the following patch

--- pr70198.f   2016-03-11 22:10:39.0 +0100
+++ pr70198_db_1.f  2016-03-12 10:26:36.0 +0100
@@ -164,6 +164,7 @@ C
 C  This routine performs Runge-Kutta calculation by Gills Method
 C
   dimension y(10),f(10),q(10)
+  save a, q
   m=m+1
   go to (1,4,5,3,7), m
 1 do 2 i=1,n

[Bug fortran/70198] simple test floating point sequence gives incorrect values-- optimizer changes them

2016-03-11 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70198

kargl at gcc dot gnu.org changed:

   What|Removed |Added

 Status|WAITING |RESOLVED
 Resolution|--- |INVALID

--- Comment #5 from kargl at gcc dot gnu.org ---
If the code is compiled with the -fno-automatic option,
one generates the desired result.  Note I said desired,
not correct, because the code has a significant bug.
When m=2 (see comment #4), the computed goto jumps to
label 4.  The do-loop with the label 6 is executed.
The variable 'a' is undefined.  It appears that this
subroutine needs a SAVE statement.

  subroutine runge(n,y,f,x,h,m,k)
C  This routine performs Runge-Kutta calculation by Gills Method
C
  dimension y(10),f(10),q(10)
  m=m+1
  go to (1,4,5,3,7), m
1 do 2 i=1,n
2 q(i)=0
  a=.5
  go to 9
3 a=1.7071067811865475244
4 x=x+.5*h
5 do 6 i=1,n
  y(i)=y(i)+a*(f(i)*h-q(i))
6 q(i)=2.*a*h*f(i)+(1.-3.*a)*q(i)
  a=.2928932188134524756
  go to 9
7 do 8 i=1,n
8 y(i)=y(i)+h*f(i)/6.-q(i)/3.
  m=0
  k=2
  go to 10
9 k=1
   10 return
  end

[Bug fortran/70198] simple test floating point sequence gives incorrect values-- optimizer changes them

2016-03-11 Thread kargl at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70198

kargl at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |WAITING
   Last reconfirmed||2016-03-11
 CC||kargl at gcc dot gnu.org
 Ever confirmed|0   |1

--- Comment #4 from kargl at gcc dot gnu.org ---
Seems that the code may be broken.

% gfc6 -g -finit-real=ZERO -ffpe-trap=invalid -o z a.f
% ./z

Minf=   3.50  Shock angle(deg)=17.664  Cone half-angle(deg)=12.41

  ***Soln only valid for ThetaC

[Bug fortran/70198] simple test floating point sequence gives incorrect values-- optimizer changes them

2016-03-11 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70198

--- Comment #3 from Andrew Pinski  ---
(In reply to Andrew Pinski from comment #2)
> Can you add -ffloat-store as a gcc option and try again?

If that works then it is a dup of bug 323.

>It's clear what is going on is not a precision problem

No it is not clear yet.

[Bug fortran/70198] simple test floating point sequence gives incorrect values-- optimizer changes them

2016-03-11 Thread pinskia at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70198

--- Comment #2 from Andrew Pinski  ---
Can you add -ffloat-store as a gcc option and try again?

[Bug fortran/70198] simple test floating point sequence gives incorrect values-- optimizer changes them

2016-03-11 Thread s.b.dorsey at larc dot nasa.gov
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=70198

--- Comment #1 from Scott (Kludge) Dorsey  ---
Created attachment 37943
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=37943=edit
correct output sample (run on vax)