This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[gomp] Diagnose #pragma omp threadprivate on automatic vars or on vars with incomplete type
- From: Jakub Jelinek <jakub at redhat dot com>
- To: Richard Henderson <rth at redhat dot com>, Diego Novillo <dnovillo at redhat dot com>
- Cc: gcc-patches at gcc dot gnu dot org
- Date: Wed, 2 Nov 2005 03:20:11 -0500
- Subject: [gomp] Diagnose #pragma omp threadprivate on automatic vars or on vars with incomplete type
- Reply-to: Jakub Jelinek <jakub at redhat dot com>
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