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]

[gomp] Diagnose #pragma omp threadprivate on automatic vars or on vars with incomplete type


Hi!

2.8.2 has for C/C++:
"where list is a comma-separated list of file-scope, namespace-scope, or
static block-scope variables that do not have incomplete types".
So, I think we ought to diagnose automatic variables or incomplete types.

Ok for gomp?

2005-11-02  Jakub Jelinek  <jakub@redhat.com>

	* c-parser.c (c_parser_omp_threadprivate): Error if V is automatic
	variable or has incomplete type.
cp/
	* semantics.c (finish_omp_threadprivate): Error if V is automatic
	variable or has incomplete type.
testsuite/
	* gcc.dg/gomp/tls-2.c: New test.
	* g++.dg/gomp/tls-2.C: New test.

--- gcc/c-parser.c.jj	2005-11-02 08:38:00.000000000 +0100
+++ gcc/c-parser.c	2005-11-02 09:06:49.000000000 +0100
@@ -7705,6 +7705,10 @@ c_parser_omp_threadprivate (c_parser *pa
 	 whether it had been used prior to this point.  */
       if (TREE_USED (v) && !C_DECL_THREADPRIVATE_P (v))
 	error ("%qE declared %<threadprivate%> after first use", v);
+      else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
+	error ("automatic variable %qE cannot be %<threadprivate%>", v);
+      else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
+	error ("%<threadprivate%> %qE has incomplete type", v);
       else
 	{
 	  if (! DECL_THREAD_LOCAL_P (v))
--- gcc/cp/semantics.c.jj	2005-10-31 09:43:12.000000000 +0100
+++ gcc/cp/semantics.c	2005-11-02 09:14:24.000000000 +0100
@@ -3616,6 +3616,10 @@ finish_omp_threadprivate (tree vars)
 	  && (DECL_LANG_SPECIFIC (v) == NULL
 	      || !CP_DECL_THREADPRIVATE_P (v)))
 	error ("%qE declared %<threadprivate%> after first use", v);
+      else if (! TREE_STATIC (v) && ! DECL_EXTERNAL (v))
+	error ("automatic variable %qE cannot be %<threadprivate%>", v);
+      else if (! COMPLETE_TYPE_P (TREE_TYPE (v)))
+	error ("%<threadprivate%> %qE has incomplete type", v);
       else
 	{
 	  /* Allocate a LANG_SPECIFIC structure for V, if needed.  */
--- gcc/testsuite/gcc.dg/gomp/tls-2.c.jj	2005-11-02 09:11:37.000000000 +0100
+++ gcc/testsuite/gcc.dg/gomp/tls-2.c	2005-11-02 09:11:11.000000000 +0100
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+extern char buf[];
+#pragma omp threadprivate (buf)	/* { dg-error "has incomplete type" } */
+
+void
+foo (void)
+{
+  int i;
+#pragma omp threadprivate (i) /* { dg-error "automatic variable" } */
+  i = 0;
+}
--- gcc/testsuite/g++.dg/gomp/tls-2.C.jj	2005-11-02 09:12:30.000000000 +0100
+++ gcc/testsuite/g++.dg/gomp/tls-2.C	2005-11-02 09:11:11.000000000 +0100
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+
+extern char buf[];
+#pragma omp threadprivate (buf)	/* { dg-error "has incomplete type" } */
+
+void
+foo (void)
+{
+  int i;
+#pragma omp threadprivate (i) /* { dg-error "automatic variable" } */
+  i = 0;
+}

	Jakub


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