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] {first,last}private and statics


Hi folks.

{last,first}private on globals/statics do not work because we look for
the variable in the decl_map of the surrounding omp context.  And we
don't put the variable there in the first place because it's a global and
should be accesible from anywhere.

The patch below fixes the problem in build_outer_var_ref.

Tested on x86-linux.

OK for gomp?

	* omp-low.c (build_outer_var_ref): Handle globals.

	* testsuite/gcc.dg/gomp/static.c: New.

Index: omp-low.c
===================================================================
--- omp-low.c	(revision 108482)
+++ omp-low.c	(working copy)
@@ -306,7 +306,9 @@ build_outer_var_ref (tree var, omp_conte
 {
   tree x;
 
-  if (is_variable_sized (var))
+  if (is_global_var (var))
+    x = var;
+  else if (is_variable_sized (var))
     {
       x = TREE_OPERAND (DECL_VALUE_EXPR (var), 0);
       x = build_outer_var_ref (x, ctx);
@@ -320,7 +322,7 @@ build_outer_var_ref (tree var, omp_conte
   else if (ctx->outer)
     x = lookup_decl (var, ctx->outer);
   else
-    x = var;
+    gcc_unreachable ();
 
   if (is_reference (var))
     x = build_fold_indirect_ref (x);
Index: testsuite/gcc.dg/gomp/static.c
===================================================================
--- testsuite/gcc.dg/gomp/static.c	(revision 0)
+++ testsuite/gcc.dg/gomp/static.c	(revision 0)
@@ -0,0 +1,14 @@
+static int bork;
+
+void bar(void);
+
+void foobar (void)
+{
+#pragma omp parallel
+  {
+#pragma omp for lastprivate(bork)
+    for (bork = 0; bork < 100; bork++) {
+        bar();
+    }
+  }
+}


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