re PR fortran/85387 (incorrect output with optimization /= 0)
authorThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 14 Apr 2018 13:38:41 +0000 (13:38 +0000)
committerThomas Koenig <tkoenig@gcc.gnu.org>
Sat, 14 Apr 2018 13:38:41 +0000 (13:38 +0000)
2018-04-14  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/85387
* frontend-passes.c (traverse_io_block): Check for start, end or
stride being defined by an outer implied DO loop.

2018-04-14  Thomas Koenig  <tkoenig@gcc.gnu.org>

PR fortran/85387
* gfortran.dg/implied_do_io_5.f90: New test.

From-SVN: r259384

gcc/fortran/ChangeLog
gcc/fortran/frontend-passes.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/implied_do_io_5.f90 [new file with mode: 0644]

index 3064ab6e9214d4ea6c702d29590a54861184f365..c6ec69e86c0c7f73daf799de09780592582c8327 100644 (file)
@@ -1,3 +1,9 @@
+2018-04-14  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/85387
+       * frontend-passes.c (traverse_io_block): Check for start, end or
+       stride being defined by an outer implied DO loop.
+
 2018-04-12  Thomas Koenig  <tkoenig@gcc.gnu.org>
 
        PR fortran/83064
index 6888224cd8111169a6e1ced08d3fd53a06d09eb8..40e88b1a7d4263415360049fb4d5705f865ef47c 100644 (file)
@@ -1237,6 +1237,23 @@ traverse_io_block (gfc_code *code, bool *has_reached, gfc_code *prev)
        }
     }
 
+  /* Check for cases like ((a(i, j), i=1, j), j=1, 2). */
+  for (int i = 1; i < ref->u.ar.dimen; i++)
+    {
+      if (iters[i])
+       {
+         gfc_expr *var = iters[i]->var;
+         for (int j = i - 1; j < i; j++)
+           {
+             if (iters[j]
+                 && (gfc_check_dependency (var, iters[j]->start, true)
+                     || gfc_check_dependency (var, iters[j]->end, true)
+                     || gfc_check_dependency (var, iters[j]->step, true)))
+                 return false;
+           }             
+       }
+    }
+
   /* Create new expr.  */
   new_e = gfc_copy_expr (curr->expr1);
   new_e->expr_type = EXPR_VARIABLE;
index 13bb25b5b2a5796c22513070c9be5d585ddbda9a..4c9fdf7bac7f73e5c062ddf6a8d26492372061f3 100644 (file)
@@ -1,3 +1,8 @@
+2018-04-14  Thomas Koenig  <tkoenig@gcc.gnu.org>
+
+       PR fortran/85387
+       * gfortran.dg/implied_do_io_5.f90: New test.
+
 2018-04-13  Paul A. Clarke  <pc@us.ibm.com>
 
        PR target/83402
diff --git a/gcc/testsuite/gfortran.dg/implied_do_io_5.f90 b/gcc/testsuite/gfortran.dg/implied_do_io_5.f90
new file mode 100644 (file)
index 0000000..988d004
--- /dev/null
@@ -0,0 +1,15 @@
+! { dg-do  run }
+! { dg-additional-options "-ffrontend-optimize" }
+! PR fortran/85387 - incorrect output
+! Original test case by Vittorio Zecca
+program main
+  real :: efg_pw(2,2)
+  character (len=80) :: c1, c2
+  efg_pw(1,1)=1
+  efg_pw(2,1)=2
+  efg_pw(1,2)=3
+  efg_pw(2,2)=4
+  write (unit=c1,fmt='(3F12.5)') ((efg_pw(i, j), i=1, j), j=1, 2)
+  write (unit=c2,fmt='(3F12.5)') 1.0, 3.0, 4.0
+  if (c1 /= c2) stop 1
+end