diff mbox

[committed] Add diagnostics for aligned clause restrictions

Message ID 20131031191025.GX27813@tucnak.zalov.cz
State New
Headers show

Commit Message

Jakub Jelinek Oct. 31, 2013, 7:10 p.m. UTC
Hi!

I've noticed I have missed diagnostics for invalid aligned clause
arguments (the aligned clause support has been written before the
restrictions were added to the standard).

Tested on x86_64-linux, committed to trunk.

2013-10-31  Jakub Jelinek  <jakub@redhat.com>

	* c-typeck.c (c_finish_omp_clauses): Diagnose aligned clause
	with decl that is not pointer nor array.

	* semantics.c (finish_omp_clauses): Diagnose aligned clause
	with decl that is not pointer nor array nor reference to those.

	* g++.dg/gomp/simd-1.C: New test.
	* g++.dg/gomp/declare-simd-1.C (f32): Fix up aligned clause argument.
	* g++.dg/gomp/declare-simd-2.C (fn13, fn14): Add new tests.
	* gcc.dg/gomp/declare-simd-2.c (fn7, fn8, fn9, fn10, fn11): Likewise.
	* c-c++-common/gomp/simd6.c: New test.


	Jakub
diff mbox

Patch

--- gcc/c/c-typeck.c.jj	2013-10-30 08:15:33.000000000 +0100
+++ gcc/c/c-typeck.c	2013-10-31 17:06:51.085755997 +0100
@@ -11504,6 +11504,14 @@  c_finish_omp_clauses (tree clauses)
 			"%qE is not a variable in %<aligned%> clause", t);
 	      remove = true;
 	    }
+	  else if (!POINTER_TYPE_P (TREE_TYPE (t))
+		   && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE)
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qE in %<aligned%> clause is neither a pointer nor "
+			"an array", t);
+	      remove = true;
+	    }
 	  else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
 	    {
 	      error_at (OMP_CLAUSE_LOCATION (c),
--- gcc/cp/semantics.c.jj	2013-10-31 14:50:29.000000000 +0100
+++ gcc/cp/semantics.c	2013-10-31 17:08:00.527394011 +0100
@@ -5467,6 +5467,19 @@  finish_omp_clauses (tree clauses)
 		error ("%qE is not a variable in %<aligned%> clause", t);
 	      remove = true;
 	    }
+	  else if (!type_dependent_expression_p (t)
+		   && TREE_CODE (TREE_TYPE (t)) != POINTER_TYPE
+		   && TREE_CODE (TREE_TYPE (t)) != ARRAY_TYPE
+		   && (TREE_CODE (TREE_TYPE (t)) != REFERENCE_TYPE
+		       || (!POINTER_TYPE_P (TREE_TYPE (TREE_TYPE (t)))
+			   && (TREE_CODE (TREE_TYPE (TREE_TYPE (t)))
+			       != ARRAY_TYPE))))
+	    {
+	      error_at (OMP_CLAUSE_LOCATION (c),
+			"%qE in %<aligned%> clause is neither a pointer nor "
+			"an array nor a reference to pointer or array", t);
+	      remove = true;
+	    }
 	  else if (bitmap_bit_p (&aligned_head, DECL_UID (t)))
 	    {
 	      error ("%qD appears more than once in %<aligned%> clauses", t);
--- gcc/testsuite/g++.dg/gomp/simd-1.C.jj	2013-10-31 19:23:29.394801317 +0100
+++ gcc/testsuite/g++.dg/gomp/simd-1.C	2013-10-31 19:25:25.218210869 +0100
@@ -0,0 +1,31 @@ 
+// { dg-do compile }
+// { dg-options "-fopenmp" }
+
+extern int a[1024];
+int (&b)[1024] = a;
+
+struct S { int s; } s, &t = s;
+
+void
+f1 (int &x, float &f, int *&p)
+{
+  int i;
+  #pragma omp simd aligned(x : 32)	// { dg-error "neither a pointer nor an array" }
+  for (i = 0; i < 1024; i++)
+    a[i]++;
+  #pragma omp simd aligned(f)		// { dg-error "neither a pointer nor an array" }
+  for (i = 0; i < 1024; i++)
+    a[i]++;
+  #pragma omp simd aligned(t : 16)	// { dg-error "neither a pointer nor an array" }
+  for (i = 0; i < 1024; i++)
+    a[i]++;
+  #pragma omp simd aligned(a : 8)
+  for (i = 0; i < 1024; i++)
+    a[i]++;
+  #pragma omp simd aligned(b : 8)
+  for (i = 0; i < 1024; i++)
+    b[i]++;
+  #pragma omp simd aligned(p : 8)
+  for (i = 0; i < 1024; i++)
+    a[i]++;
+}
--- gcc/testsuite/g++.dg/gomp/declare-simd-1.C.jj	2013-10-11 11:23:59.000000000 +0200
+++ gcc/testsuite/g++.dg/gomp/declare-simd-1.C	2013-10-31 19:27:32.158559550 +0100
@@ -205,7 +205,7 @@  f30 (int x)
 template <int N>
 struct C
 {
-  #pragma omp declare simd simdlen (N) aligned (a : N * sizeof (int)) linear (c : N) notinbranch
+  #pragma omp declare simd simdlen (N) aligned (b : N * sizeof (int)) linear (c : N) notinbranch
   int f32 (int a, int *b, int c);
 };
 
--- gcc/testsuite/g++.dg/gomp/declare-simd-2.C.jj	2013-10-11 11:23:59.000000000 +0200
+++ gcc/testsuite/g++.dg/gomp/declare-simd-2.C	2013-10-31 19:31:36.812309117 +0100
@@ -64,4 +64,22 @@  struct D
   int e;
 };
 
+#pragma omp declare simd aligned (a, b, c, d)
+int fn13 (int *a, int b[64], int *&c, int (&d)[64]);
+
+#pragma omp declare simd aligned (a)	// { dg-error "neither a pointer nor an array" }
+int fn14 (int a);
+
+#pragma omp declare simd aligned (b)	// { dg-error "neither a pointer nor an array" }
+int fn14 (int &b);
+
+#pragma omp declare simd aligned (c)	// { dg-error "neither a pointer nor an array" }
+int fn14 (float c);
+
+#pragma omp declare simd aligned (d)	// { dg-error "neither a pointer nor an array" }
+int fn14 (double &d);
+
+#pragma omp declare simd aligned (e)	// { dg-error "neither a pointer nor an array" }
+int fn14 (D e);
+
 // { dg-error "has no member" "" { target *-*-* } 61 }
--- gcc/testsuite/gcc.dg/gomp/declare-simd-2.c.jj	2013-10-11 11:23:59.000000000 +0200
+++ gcc/testsuite/gcc.dg/gomp/declare-simd-2.c	2013-10-31 19:32:59.044886760 +0100
@@ -22,3 +22,20 @@  int fn5 (int a);
 
 #pragma omp declare simd inbranch notinbranch /* { dg-error "clause is incompatible with" } */
 int fn6 (int);
+
+#pragma omp declare simd aligned (a, b)
+int fn7 (int *a, int b[64]);
+
+#pragma omp declare simd aligned (a)    /* { dg-error "neither a pointer nor an array" } */
+int fn8 (int a);
+
+#pragma omp declare simd aligned (c)    /* { dg-error "neither a pointer nor an array" } */
+int fn9 (float c);
+
+#pragma omp declare simd aligned (d)    /* { dg-error "neither a pointer nor an array" } */
+int fn10 (double d);
+
+struct D { int d; };
+
+#pragma omp declare simd aligned (e)    /* { dg-error "neither a pointer nor an array" } */
+int fn11 (struct D e);   
--- gcc/testsuite/c-c++-common/gomp/simd6.c.jj	2013-10-31 17:32:56.000000000 +0100
+++ gcc/testsuite/c-c++-common/gomp/simd6.c	2013-10-31 17:52:27.587792500 +0100
@@ -0,0 +1,27 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+extern int a[1024];
+
+struct S { int i; } s;
+
+void
+f1 (int x, float f, int *p)
+{
+  int i;
+  #pragma omp simd aligned(x : 32)	/* { dg-error "neither a pointer nor an array" } */
+  for (i = 0; i < 1024; i++)
+    a[i]++;
+  #pragma omp simd aligned(f)		/* { dg-error "neither a pointer nor an array" } */
+  for (i = 0; i < 1024; i++)
+    a[i]++;
+  #pragma omp simd aligned(s : 16)	/* { dg-error "neither a pointer nor an array" } */
+  for (i = 0; i < 1024; i++)
+    a[i]++;
+  #pragma omp simd aligned(a : 8)
+  for (i = 0; i < 1024; i++)
+    a[i]++;
+  #pragma omp simd aligned(p : 8)
+  for (i = 0; i < 1024; i++)
+    a[i]++;
+}