Fix fortran/openmp.c collapsed loop analysis (PR fortran/85313)

Message ID 20180410140713.GI8577@tucnak
State New
Headers show
Series
  • Fix fortran/openmp.c collapsed loop analysis (PR fortran/85313)
Related show

Commit Message

Jakub Jelinek April 10, 2018, 2:07 p.m.
Hi!

Dunno what I was thinking when adding this if (j < i) break;, with it we
never verify whether second and following loop iterators aren't used in
third and following loops in collapse(3) and above loops.

Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux,
committed to trunk.

2018-04-10  Jakub Jelinek  <jakub@redhat.com>

	PR fortran/85313
	* openmp.c (resolve_omp_do): Remove bogus if (j < i) break;.
	(resolve_oacc_nested_loops): Likewise.  Formatting fix.

	* gfortran.dg/gomp/pr85313.f90: New test.


	Jakub

Patch

--- gcc/fortran/openmp.c.jj	2018-01-31 21:47:18.774155978 +0100
+++ gcc/fortran/openmp.c	2018-04-10 12:21:38.371945086 +0200
@@ -5600,8 +5600,6 @@  resolve_omp_do (gfc_code *code)
 			     "iteration space at %L", name, &do_code->loc);
 		  break;
 		}
-	      if (j < i)
-		break;
 	      do_code2 = do_code2->block->next;
 	    }
 	}
@@ -5765,12 +5763,10 @@  resolve_oacc_nested_loops (gfc_code *cod
 		  || gfc_find_sym_in_expr (ivar, do_code->ext.iterator->end)
 		  || gfc_find_sym_in_expr (ivar, do_code->ext.iterator->step))
 		{
-		  gfc_error ("!$ACC LOOP %s loops don't form rectangular iteration space at %L",
-			     clause, &do_code->loc);
+		  gfc_error ("!$ACC LOOP %s loops don't form rectangular "
+			     "iteration space at %L", clause, &do_code->loc);
 		  break;
 		}
-	      if (j < i)
-		break;
 	      do_code2 = do_code2->block->next;
 	    }
 	}
--- gcc/testsuite/gfortran.dg/gomp/pr85313.f90.jj	2018-04-10 12:14:54.438779463 +0200
+++ gcc/testsuite/gfortran.dg/gomp/pr85313.f90	2018-04-10 12:13:46.975751804 +0200
@@ -0,0 +1,25 @@ 
+! PR fortran/85313
+! { dg-do compile }
+
+!$omp do collapse(3)
+  do i = 1, 10
+    do j = i, 20	! { dg-error "form rectangular iteration space" }
+      do k = 1, 2
+      end do
+    end do
+  end do
+!$omp do collapse(3)
+  do i = 1, 10
+    do j = 1, 5
+      do k = i, 20	! { dg-error "form rectangular iteration space" }
+      end do
+    end do
+  end do
+!$omp do collapse(3)
+  do i = 1, 10
+    do j = 1, 5
+      do k = j, 20	! { dg-error "form rectangular iteration space" }
+      end do
+    end do
+  end do
+end