This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gomp4.5] Diagnose linear IV on #pragma omp for


Hi!

linear clause is allowed on omp for, but the IV can only be private or
lastprivate, not linear.  We weren't diagnosing this.
Fixed thusly, regtested on x86_64-linux.

2015-10-26  Jakub Jelinek  <jakub@redhat.com>

	* gimplify.c (omp_is_private): Diagnose linear iteration variables
	on non-simd constructs.

	* gcc.dg/gomp/linear-1.c: New test.
	* g++.dg/gomp/linear-2.C: New test.

--- gcc/gimplify.c.jj	2015-10-26 15:38:20.000000000 +0100
+++ gcc/gimplify.c	2015-10-26 18:25:58.860633072 +0100
@@ -6090,6 +6090,9 @@ omp_is_private (struct gimplify_omp_ctx
 	  else if ((n->value & GOVD_REDUCTION) != 0)
 	    error ("iteration variable %qE should not be reduction",
 		   DECL_NAME (decl));
+	  else if (simd == 0 && (n->value & GOVD_LINEAR) != 0)
+	    error ("iteration variable %qE should not be linear",
+		   DECL_NAME (decl));
 	  else if (simd == 1 && (n->value & GOVD_LASTPRIVATE) != 0)
 	    error ("iteration variable %qE should not be lastprivate",
 		   DECL_NAME (decl));
--- gcc/testsuite/gcc.dg/gomp/linear-1.c.jj	2015-10-26 18:32:57.721611756 +0100
+++ gcc/testsuite/gcc.dg/gomp/linear-1.c	2015-10-26 18:36:53.373224158 +0100
@@ -0,0 +1,57 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+int i, j;
+
+void
+f1 (void)
+{
+  #pragma omp for linear (i:1)	/* { dg-error "iteration variable .i. should not be linear" } */
+  for (i = 0; i < 32; i++)
+    ;
+}
+
+void
+f2 (void)
+{
+  #pragma omp distribute parallel for linear (i:1)	/* { dg-error ".linear. is not valid for .#pragma omp distribute parallel for." } */
+  for (i = 0; i < 32; i++)
+    ;
+}
+
+void
+f3 (void)
+{
+  #pragma omp parallel for linear (i:1) collapse(1)	/* { dg-error "iteration variable .i. should not be linear" } */
+  for (i = 0; i < 32; i++)
+    ;
+}
+
+void
+f4 (void)
+{
+  #pragma omp for linear (i:1) linear (j:2) collapse(2)	/* { dg-error "iteration variable .i. should not be linear" } */
+  for (i = 0; i < 32; i++)				/* { dg-error "iteration variable .j. should not be linear" "" { target *-*-* } 33 } */
+    for (j = 0; j < 32; j+=2)
+      ;
+}
+
+void
+f5 (void)
+{
+  #pragma omp target teams distribute parallel for linear (i:1) linear (j:2) collapse(2)	/* { dg-error ".linear. is not valid for .#pragma omp target teams distribute parallel for." } */
+  for (i = 0; i < 32; i++)
+    for (j = 0; j < 32; j+=2)
+      ;
+}
+
+void
+f6 (void)
+{
+  #pragma omp parallel for linear (i:1) collapse(2) linear (j:2)	/* { dg-error "iteration variable .i. should not be linear" } */
+  for (i = 0; i < 32; i++)						/* { dg-error "iteration variable .j. should not be linear" "" { target *-*-* } 51 } */
+    for (j = 0; j < 32; j+=2)
+      ;
+}
+
+#pragma omp declare target to (i, j, f2)
--- gcc/testsuite/g++.dg/gomp/linear-2.C.jj	2015-10-26 18:33:32.352113927 +0100
+++ gcc/testsuite/g++.dg/gomp/linear-2.C	2015-10-26 18:54:30.869022177 +0100
@@ -0,0 +1,128 @@
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+#pragma omp declare target
+
+int i, j;
+
+void
+f1 ()
+{
+  #pragma omp for linear (i:1)	// { dg-error "iteration variable .i. should not be linear" }
+  for (i = 0; i < 32; i++)
+    ;
+}
+
+void
+f2 ()
+{
+  #pragma omp distribute parallel for linear (i:1)	// { dg-error ".linear. is not valid for .#pragma omp distribute parallel for." }
+  for (i = 0; i < 32; i++)
+    ;
+}
+
+void
+f3 ()
+{
+  #pragma omp parallel for linear (i:1) collapse(1)
+  for (i = 0; i < 32; i++)				// { dg-error "iteration variable .i. should not be linear" }
+    ;
+}
+
+void
+f4 ()
+{
+  #pragma omp for linear (i:1) linear (j:2) collapse(2)	// { dg-error "iteration variable .i. should not be linear" }
+  for (i = 0; i < 32; i++)				// { dg-error "iteration variable .j. should not be linear" "" { target *-*-* } 35 }
+    for (j = 0; j < 32; j+=2)
+      ;
+}
+
+void
+f5 ()
+{
+  #pragma omp target teams distribute parallel for linear (i:1) linear (j:2) collapse(2)	// { dg-error ".linear. is not valid for .#pragma omp target teams distribute parallel for." }
+  for (i = 0; i < 32; i++)
+    for (j = 0; j < 32; j+=2)
+      ;
+}
+
+void
+f6 ()
+{
+  #pragma omp parallel for linear (i:1) collapse(2) linear (j:2)	// { dg-error "iteration variable .i. should not be linear" "" { target *-*-* } 54 }
+  for (i = 0; i < 32; i++)						// { dg-error "iteration variable .j. should not be linear" }
+    for (j = 0; j < 32; j+=2)
+      ;
+}
+
+template <int N>
+void
+f7 ()
+{
+  #pragma omp for linear (i:1)	// { dg-error "iteration variable .i. should not be linear" }
+  for (i = 0; i < 32; i++)
+    ;
+}
+
+template <int N>
+void
+f8 ()
+{
+  #pragma omp distribute parallel for linear (i:1)	// { dg-error ".linear. is not valid for .#pragma omp distribute parallel for." }
+  for (i = 0; i < 32; i++)
+    ;
+}
+
+template <int N>
+void
+f9 ()
+{
+  #pragma omp parallel for linear (i:1) collapse(1)
+  for (i = 0; i < 32; i++)				// { dg-error "iteration variable .i. should not be linear" }
+    ;
+}
+
+template <int N>
+void
+f10 ()
+{
+  #pragma omp for linear (i:1) linear (j:2) collapse(2)	// { dg-error "iteration variable .i. should not be linear" }
+  for (i = 0; i < 32; i++)				// { dg-error "iteration variable .j. should not be linear" "" { target *-*-* } 90 }
+    for (j = 0; j < 32; j+=2)
+      ;
+}
+
+template <int N>
+void
+f11 ()
+{
+  #pragma omp target teams distribute parallel for linear (i:1) linear (j:2) collapse(2)	// { dg-error ".linear. is not valid for .#pragma omp target teams distribute parallel for." }
+  for (i = 0; i < 32; i++)
+    for (j = 0; j < 32; j+=2)
+      ;
+}
+
+template <int N>
+void
+f12 ()
+{
+  #pragma omp parallel for linear (i:1) collapse(2) linear (j:2)	// { dg-error "iteration variable .i. should not be linear" "" { target *-*-* } 111 }
+  for (i = 0; i < 32; i++)						// { dg-error "iteration variable .j. should not be linear" }
+    for (j = 0; j < 32; j+=2)
+      ;
+}
+
+#pragma omp end declare target
+
+void
+f13 ()
+{
+  f7 <0> ();
+  #pragma omp target teams
+  f8 <1> ();
+  f9 <2> ();
+  f10 <3> ();
+  f11 <4> ();
+  f12 <5> ();
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]