* [committed] openmp: Diagnose threadprivate OpenMP loop iterators
@ 2021-10-30 7:06 Jakub Jelinek
0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2021-10-30 7:06 UTC (permalink / raw)
To: gcc-patches; +Cc: Tobias Burnus
Hi!
We weren't diagnosing the
The loop iteration variable may not appear in a threadprivate directive.
restriction which used to be in 5.0 just among the Worksharing-Loop
restrictions but in 5.1 it is among Canonical Loop Nest Form restrictions.
This patch diagnoses those.
Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk.
2021-10-30 Jakub Jelinek <jakub@redhat.com>
* gimplify.c (gimplify_omp_for): Diagnose threadprivate iterators.
* c-c++-common/gomp/loop-10.c: New test.
--- gcc/gimplify.c.jj 2021-10-07 12:52:35.195909331 +0200
+++ gcc/gimplify.c 2021-10-29 19:42:34.343358109 +0200
@@ -12298,6 +12298,24 @@ gimplify_omp_for (tree *expr_p, gimple_s
gimplify_omp_ctxp->loop_iter_var.quick_push (decl);
}
+ if (for_stmt == orig_for_stmt)
+ {
+ tree orig_decl = decl;
+ if (OMP_FOR_ORIG_DECLS (for_stmt))
+ {
+ tree orig_decl = TREE_VEC_ELT (OMP_FOR_ORIG_DECLS (for_stmt), i);
+ if (TREE_CODE (orig_decl) == TREE_LIST)
+ {
+ orig_decl = TREE_PURPOSE (orig_decl);
+ if (!orig_decl)
+ orig_decl = decl;
+ }
+ }
+ if (is_global_var (orig_decl) && DECL_THREAD_LOCAL_P (orig_decl))
+ error_at (EXPR_LOCATION (for_stmt),
+ "threadprivate iteration variable %qD", orig_decl);
+ }
+
/* Make sure the iteration variable is private. */
tree c = NULL_TREE;
tree c2 = NULL_TREE;
--- gcc/testsuite/c-c++-common/gomp/loop-10.c.jj 2021-10-29 20:38:28.971214355 +0200
+++ gcc/testsuite/c-c++-common/gomp/loop-10.c 2021-10-29 20:42:40.637710320 +0200
@@ -0,0 +1,35 @@
+int a, b;
+#pragma omp threadprivate (a, b)
+
+void
+foo (void)
+{
+ #pragma omp for /* { dg-error "threadprivate iteration variable 'a'" } */
+ for (a = 0; a < 32; a++)
+ ;
+ #pragma omp parallel for collapse(2) /* { dg-error "threadprivate iteration variable 'a'" "" { target c } } */
+ for (a = 0; a < 32; a++) /* { dg-error "threadprivate iteration variable 'b'" "" { target c } .-1 } */
+ for (b = 0; b < 32; b++) /* { dg-error "threadprivate iteration variable 'a'" "" { target c++ } .-1 } */
+ ; /* { dg-error "threadprivate iteration variable 'b'" "" { target c++ } .-2 } */
+ #pragma omp simd /* { dg-error "threadprivate iteration variable 'a'" } */
+ for (a = 0; a < 32; a++)
+ ;
+ #pragma omp taskloop /* { dg-error "threadprivate iteration variable 'a'" } */
+ for (a = 0; a < 32; a++)
+ ;
+ #pragma omp loop bind(thread) /* { dg-error "threadprivate iteration variable 'a'" } */
+ for (a = 0; a < 32; a++)
+ ;
+}
+
+void
+bar (void)
+{
+ #pragma omp distribute collapse(2) /* { dg-error "threadprivate iteration variable 'a'" } */
+ for (a = 0; a < 32; a++) /* { dg-error "threadprivate iteration variable 'b'" "" { target *-*-* } .-1 } */
+ for (b = 0; b < a; b++)
+ ;
+ #pragma omp distribute parallel for simd /* { dg-error "threadprivate iteration variable 'a'" "" { target c } } */
+ for (a = 0; a < 32; a++) /* { dg-error "threadprivate iteration variable 'a'" "" { target c++ } } */
+ ;
+}
Jakub
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2021-10-30 7:07 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-30 7:06 [committed] openmp: Diagnose threadprivate OpenMP loop iterators Jakub Jelinek
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).