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] Fix combined parallel loops with shared variables


When building a combined parallel loop call, we need to build the list of 
arguments for GOMP_parallel_loop_XXX_start before we scan any clauses in 
the loop.  Otherwise, we add the DECLs created for the child thread (which 
then gets expanded to the receiving data structure dereference).


	* omp-low.c (scan_omp_for): Call scan_sharing_clauses after
	building list of additional arguments to pass to combined
	parallel loop call.


testsuite/

	* gcc.dg/gomp/sharing-3.c: New test.

Index: omp-low.c
===================================================================
--- omp-low.c	(revision 106352)
+++ omp-low.c	(working copy)
@@ -955,7 +955,6 @@ scan_omp_for (tree *stmt_p, omp_context 
   tree stmt = *stmt_p;
 
   ctx = new_omp_context (stmt, outer_ctx);
-  scan_sharing_clauses (OMP_FOR_CLAUSES (stmt), ctx);
 
   /* If this is a combined parallel loop directive, we need to extract
      the bounds, step and chunk size for the loop so that we can build
@@ -984,6 +983,8 @@ scan_omp_for (tree *stmt_p, omp_context 
       outer_ctx->parallel_start_additional_args = additional_args;
     }
 
+  scan_sharing_clauses (OMP_FOR_CLAUSES (stmt), ctx);
+
   /* FIXME.  When expanding into a combined parallel loop, we may not
      need to map some of the variables in the loop header (in
      particular, FD.N1 and FD.N2 for dynamic loops).  */
Index: testsuite/gcc.dg/gomp/sharing-3.c
===================================================================
--- testsuite/gcc.dg/gomp/sharing-3.c	(revision 0)
+++ testsuite/gcc.dg/gomp/sharing-3.c	(revision 0)
@@ -0,0 +1,17 @@
+/* { dg-do compile } */
+
+#define N       50
+#define CHUNKSIZE   5
+
+main ()
+{
+  int i, chunk;
+  float c[N];
+
+  chunk = CHUNKSIZE;
+#pragma omp parallel for shared (c, chunk) schedule (dynamic, chunk)
+  for (i = 0; i < N; i++)
+    c[i] = i;
+
+  return 0;
+}


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