Blame SOURCES/gcc44-rh533181.patch

dc1507
2010-07-22  Jakub Jelinek  <jakub@redhat.com>
dc1507
dc1507
	* gimplify.c (enum gimplify_omp_var_data): Add
dc1507
	GOVD_THREADPRIVATE_WARNED.
dc1507
	(gimplify_bind_expr): Add GOVD_LOCAL | GOVD_SEEN even for global vars.
dc1507
	(omp_notice_threadprivate_variable): Note used threadprivate vars
dc1507
	with current function's context in shared clauses.
dc1507
	(gimplify_adjust_omp_clauses_1): Allow globals with current function's
dc1507
	context in taskreg shared clause.
dc1507
	* omp-low.c (lower_rec_input_clauses): For function-local is_global_var
dc1507
	VAR_DECLs in shared clauses add a decl copy with DECL_VALUE_EXPR
dc1507
	pointing to the original.
dc1507
dc1507
	* trans-openmp.c (gfc_omp_private_debug_clause): Return false for
dc1507
	threadprivate decls.
dc1507
dc1507
	* gcc.dg/gomp/tls-3.c: New test.
dc1507
dc1507
--- gcc/fortran/trans-openmp.c.jj	2010-06-24 21:47:09.908230044 +0200
dc1507
+++ gcc/fortran/trans-openmp.c	2010-07-26 10:45:15.830229443 +0200
dc1507
@@ -351,6 +351,18 @@ gfc_omp_disregard_value_expr (tree decl,
dc1507
 bool
dc1507
 gfc_omp_private_debug_clause (tree decl, bool shared)
dc1507
 {
dc1507
+  if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
dc1507
+    {
dc1507
+      if (DECL_THREAD_LOCAL_P (decl))
dc1507
+	return false;
dc1507
+      if (DECL_HAS_VALUE_EXPR_P (decl))
dc1507
+	{
dc1507
+	  tree value = get_base_address (DECL_VALUE_EXPR (decl));
dc1507
+	  if (value && DECL_P (value) && DECL_THREAD_LOCAL_P (value))
dc1507
+	    return false;
dc1507
+	}
dc1507
+    }
dc1507
+
dc1507
   if (GFC_DECL_CRAY_POINTEE (decl))
dc1507
     return true;
dc1507
 
dc1507
--- gcc/gimplify.c.jj	2010-07-09 09:01:37.049604412 +0200
dc1507
+++ gcc/gimplify.c	2010-07-26 10:50:05.646291216 +0200
dc1507
@@ -66,6 +66,7 @@ enum gimplify_omp_var_data
dc1507
   GOVD_LOCAL = 128,
dc1507
   GOVD_DEBUG_PRIVATE = 256,
dc1507
   GOVD_PRIVATE_OUTER_REF = 512,
dc1507
+  GOVD_THREADPRIVATE_WARNED = 1024,
dc1507
   GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE
dc1507
 			   | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LOCAL)
dc1507
 };
dc1507
@@ -1234,7 +1235,7 @@ gimplify_bind_expr (tree *expr_p, gimple
dc1507
 	  struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
dc1507
 
dc1507
 	  /* Mark variable as local.  */
dc1507
-	  if (ctx && !is_global_var (t)
dc1507
+	  if (ctx
dc1507
 	      && (! DECL_SEEN_IN_BIND_EXPR_P (t)
dc1507
 		  || splay_tree_lookup (ctx->variables,
dc1507
 					(splay_tree_key) t) == NULL))
dc1507
@@ -5339,18 +5340,36 @@ omp_notice_threadprivate_variable (struc
dc1507
 {
dc1507
   splay_tree_node n;
dc1507
 
dc1507
-  if (ctx->region_type != ORT_UNTIED_TASK)
dc1507
+  while (ctx && ctx->region_type == ORT_WORKSHARE)
dc1507
+    {
dc1507
+      n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
dc1507
+      if (n != NULL)
dc1507
+	{
dc1507
+	  gcc_assert (n->value & GOVD_LOCAL);
dc1507
+	  return false;
dc1507
+	}
dc1507
+      ctx = ctx->outer_context;
dc1507
+    }
dc1507
+  if (ctx == NULL)
dc1507
     return false;
dc1507
+
dc1507
   n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
dc1507
   if (n == NULL)
dc1507
+    n = splay_tree_insert (ctx->variables, (splay_tree_key)decl,
dc1507
+			   DECL_CONTEXT (decl) == current_function_decl
dc1507
+			   ? GOVD_SHARED | GOVD_SEEN : 0);
dc1507
+  if (ctx->region_type == ORT_UNTIED_TASK
dc1507
+      && (n->value & GOVD_THREADPRIVATE_WARNED) == 0)
dc1507
     {
dc1507
       error ("threadprivate variable %qs used in untied task",
dc1507
 	     IDENTIFIER_POINTER (DECL_NAME (decl)));
dc1507
       error ("%Henclosing task", &ctx->location);
dc1507
-      splay_tree_insert (ctx->variables, (splay_tree_key)decl, 0);
dc1507
+      n->value |= GOVD_THREADPRIVATE_WARNED;
dc1507
     }
dc1507
   if (decl2)
dc1507
-    splay_tree_insert (ctx->variables, (splay_tree_key)decl2, 0);
dc1507
+    splay_tree_insert (ctx->variables, (splay_tree_key)decl2,
dc1507
+		       DECL_CONTEXT (decl2) == current_function_decl
dc1507
+		       ? GOVD_SHARED | GOVD_SEEN : 0);
dc1507
   return false;
dc1507
 }
dc1507
 
dc1507
@@ -5779,7 +5798,9 @@ gimplify_adjust_omp_clauses_1 (splay_tre
dc1507
 		break;
dc1507
 	      ctx = ctx->outer_context;
dc1507
 	    }
dc1507
-	  if (ctx == NULL)
dc1507
+	  if (ctx == NULL
dc1507
+	      && (DECL_CONTEXT (decl) != current_function_decl
dc1507
+		  || gimplify_omp_ctxp->region_type == ORT_WORKSHARE))
dc1507
 	    return 0;
dc1507
 	}
dc1507
       code = OMP_CLAUSE_SHARED;
dc1507
--- gcc/omp-low.c.jj	2010-06-11 11:06:00.913659301 +0200
dc1507
+++ gcc/omp-low.c	2010-07-26 10:45:15.866229447 +0200
dc1507
@@ -2222,6 +2222,17 @@ lower_rec_input_clauses (tree clauses, g
dc1507
 		continue;
dc1507
 	      break;
dc1507
 	    case OMP_CLAUSE_SHARED:
dc1507
+	      if (pass == 0
dc1507
+		  && is_global_var (OMP_CLAUSE_DECL (c))
dc1507
+		  && (DECL_CONTEXT (OMP_CLAUSE_DECL (c))
dc1507
+		      == current_function_decl)
dc1507
+		  && is_taskreg_ctx (ctx)
dc1507
+		  && !DECL_IGNORED_P (OMP_CLAUSE_DECL (c)))
dc1507
+		{
dc1507
+		  new_var = omp_copy_decl_1 (OMP_CLAUSE_DECL (c), ctx);
dc1507
+		  SET_DECL_VALUE_EXPR (new_var, OMP_CLAUSE_DECL (c));
dc1507
+		  DECL_HAS_VALUE_EXPR_P (new_var) = 1;
dc1507
+		}
dc1507
 	      if (maybe_lookup_decl (OMP_CLAUSE_DECL (c), ctx) == NULL)
dc1507
 		{
dc1507
 		  gcc_assert (is_global_var (OMP_CLAUSE_DECL (c)));
dc1507
--- gcc/testsuite/gcc.dg/gomp/tls-3.c.jj	2010-07-26 10:45:15.868228753 +0200
dc1507
+++ gcc/testsuite/gcc.dg/gomp/tls-3.c	2010-07-26 10:45:15.868228753 +0200
dc1507
@@ -0,0 +1,21 @@
dc1507
+/* { dg-do compile } */
dc1507
+/* { dg-require-effective-target tls_native } */
dc1507
+
dc1507
+int thr;
dc1507
+#pragma omp threadprivate(thr)
dc1507
+
dc1507
+void
dc1507
+foo (void)
dc1507
+{
dc1507
+  #pragma omp task untied	/* { dg-error "enclosing task" } */
dc1507
+  {
dc1507
+    static int thr2;
dc1507
+    #pragma omp threadprivate(thr2)
dc1507
+    static int thr3;
dc1507
+    #pragma omp threadprivate(thr3)
dc1507
+    thr++;	/* { dg-error "used in untied task" } */
dc1507
+    thr2++;	/* { dg-error "used in untied task" } */
dc1507
+    thr++;
dc1507
+    thr2++;
dc1507
+  }
dc1507
+}