1 2010-07-22 Jakub Jelinek <jakub@redhat.com>
3 * gimplify.c (enum gimplify_omp_var_data): Add
4 GOVD_THREADPRIVATE_WARNED.
5 (gimplify_bind_expr): Add GOVD_LOCAL | GOVD_SEEN even for global vars.
6 (omp_notice_threadprivate_variable): Note used threadprivate vars
7 with current function's context in shared clauses.
8 (gimplify_adjust_omp_clauses_1): Allow globals with current function's
9 context in taskreg shared clause.
10 * omp-low.c (lower_rec_input_clauses): For function-local is_global_var
11 VAR_DECLs in shared clauses add a decl copy with DECL_VALUE_EXPR
12 pointing to the original.
14 * trans-openmp.c (gfc_omp_private_debug_clause): Return false for
17 * gcc.dg/gomp/tls-3.c: New test.
19 --- gcc/fortran/trans-openmp.c.jj 2010-06-24 21:47:09.908230044 +0200
20 +++ gcc/fortran/trans-openmp.c 2010-07-26 10:45:15.830229443 +0200
21 @@ -351,6 +351,18 @@ gfc_omp_disregard_value_expr (tree decl,
23 gfc_omp_private_debug_clause (tree decl, bool shared)
25 + if (TREE_STATIC (decl) || DECL_EXTERNAL (decl))
27 + if (DECL_THREAD_LOCAL_P (decl))
29 + if (DECL_HAS_VALUE_EXPR_P (decl))
31 + tree value = get_base_address (DECL_VALUE_EXPR (decl));
32 + if (value && DECL_P (value) && DECL_THREAD_LOCAL_P (value))
37 if (GFC_DECL_CRAY_POINTEE (decl))
40 --- gcc/gimplify.c.jj 2010-07-09 09:01:37.049604412 +0200
41 +++ gcc/gimplify.c 2010-07-26 10:50:05.646291216 +0200
42 @@ -66,6 +66,7 @@ enum gimplify_omp_var_data
44 GOVD_DEBUG_PRIVATE = 256,
45 GOVD_PRIVATE_OUTER_REF = 512,
46 + GOVD_THREADPRIVATE_WARNED = 1024,
47 GOVD_DATA_SHARE_CLASS = (GOVD_SHARED | GOVD_PRIVATE | GOVD_FIRSTPRIVATE
48 | GOVD_LASTPRIVATE | GOVD_REDUCTION | GOVD_LOCAL)
50 @@ -1234,7 +1235,7 @@ gimplify_bind_expr (tree *expr_p, gimple
51 struct gimplify_omp_ctx *ctx = gimplify_omp_ctxp;
53 /* Mark variable as local. */
54 - if (ctx && !is_global_var (t)
56 && (! DECL_SEEN_IN_BIND_EXPR_P (t)
57 || splay_tree_lookup (ctx->variables,
58 (splay_tree_key) t) == NULL))
59 @@ -5339,18 +5340,36 @@ omp_notice_threadprivate_variable (struc
63 - if (ctx->region_type != ORT_UNTIED_TASK)
64 + while (ctx && ctx->region_type == ORT_WORKSHARE)
66 + n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
69 + gcc_assert (n->value & GOVD_LOCAL);
72 + ctx = ctx->outer_context;
77 n = splay_tree_lookup (ctx->variables, (splay_tree_key)decl);
79 + n = splay_tree_insert (ctx->variables, (splay_tree_key)decl,
80 + DECL_CONTEXT (decl) == current_function_decl
81 + ? GOVD_SHARED | GOVD_SEEN : 0);
82 + if (ctx->region_type == ORT_UNTIED_TASK
83 + && (n->value & GOVD_THREADPRIVATE_WARNED) == 0)
85 error ("threadprivate variable %qs used in untied task",
86 IDENTIFIER_POINTER (DECL_NAME (decl)));
87 error ("%Henclosing task", &ctx->location);
88 - splay_tree_insert (ctx->variables, (splay_tree_key)decl, 0);
89 + n->value |= GOVD_THREADPRIVATE_WARNED;
92 - splay_tree_insert (ctx->variables, (splay_tree_key)decl2, 0);
93 + splay_tree_insert (ctx->variables, (splay_tree_key)decl2,
94 + DECL_CONTEXT (decl2) == current_function_decl
95 + ? GOVD_SHARED | GOVD_SEEN : 0);
99 @@ -5779,7 +5798,9 @@ gimplify_adjust_omp_clauses_1 (splay_tre
101 ctx = ctx->outer_context;
105 + && (DECL_CONTEXT (decl) != current_function_decl
106 + || gimplify_omp_ctxp->region_type == ORT_WORKSHARE))
109 code = OMP_CLAUSE_SHARED;
110 --- gcc/omp-low.c.jj 2010-06-11 11:06:00.913659301 +0200
111 +++ gcc/omp-low.c 2010-07-26 10:45:15.866229447 +0200
112 @@ -2222,6 +2222,17 @@ lower_rec_input_clauses (tree clauses, g
115 case OMP_CLAUSE_SHARED:
117 + && is_global_var (OMP_CLAUSE_DECL (c))
118 + && (DECL_CONTEXT (OMP_CLAUSE_DECL (c))
119 + == current_function_decl)
120 + && is_taskreg_ctx (ctx)
121 + && !DECL_IGNORED_P (OMP_CLAUSE_DECL (c)))
123 + new_var = omp_copy_decl_1 (OMP_CLAUSE_DECL (c), ctx);
124 + SET_DECL_VALUE_EXPR (new_var, OMP_CLAUSE_DECL (c));
125 + DECL_HAS_VALUE_EXPR_P (new_var) = 1;
127 if (maybe_lookup_decl (OMP_CLAUSE_DECL (c), ctx) == NULL)
129 gcc_assert (is_global_var (OMP_CLAUSE_DECL (c)));
130 --- gcc/testsuite/gcc.dg/gomp/tls-3.c.jj 2010-07-26 10:45:15.868228753 +0200
131 +++ gcc/testsuite/gcc.dg/gomp/tls-3.c 2010-07-26 10:45:15.868228753 +0200
133 +/* { dg-do compile } */
134 +/* { dg-require-effective-target tls_native } */
137 +#pragma omp threadprivate(thr)
142 + #pragma omp task untied /* { dg-error "enclosing task" } */
145 + #pragma omp threadprivate(thr2)
147 + #pragma omp threadprivate(thr3)
148 + thr++; /* { dg-error "used in untied task" } */
149 + thr2++; /* { dg-error "used in untied task" } */