Hi!

This is even more controversial testcase (and even more if the vars are
defined in the loop, then we still ICE on it :( ).  At least for the latter
case, I'd be in favour of just erroring out.

Bootstrapped/regtested on x86_64-linux and i686-linux, committed to trunk
and 5 branch.

2015-09-10  Jakub Jelinek  <ja...@redhat.com>

        PR middle-end/67521
        * gimplify.c (gimplify_omp_for): Don't call omp_add_variable
        if decl is already in outer->variables.

        * c-c++-common/gomp/pr67521.c: New test.

--- gcc/gimplify.c.jj   2015-09-09 14:20:59.000000000 +0200
+++ gcc/gimplify.c      2015-09-09 16:23:24.039714056 +0200
@@ -7163,10 +7163,16 @@ gimplify_omp_for (tree *expr_p, gimple_s
                    outer = NULL;
                  if (outer)
                    {
-                     omp_add_variable (outer, decl,
-                                       GOVD_LASTPRIVATE | GOVD_SEEN);
-                     if (outer->outer_context)
-                       omp_notice_variable (outer->outer_context, decl, true);
+                     n = splay_tree_lookup (outer->variables,
+                                            (splay_tree_key)decl);
+                     if (n == NULL || (n->value & GOVD_DATA_SHARE_CLASS) == 0)
+                       {
+                         omp_add_variable (outer, decl,
+                                           GOVD_LASTPRIVATE | GOVD_SEEN);
+                         if (outer->outer_context)
+                           omp_notice_variable (outer->outer_context, decl,
+                                                true);
+                       }
                    }
                }
            }
@@ -7201,10 +7207,16 @@ gimplify_omp_for (tree *expr_p, gimple_s
                    outer = NULL;
                  if (outer)
                    {
-                     omp_add_variable (outer, decl,
-                                       GOVD_LASTPRIVATE | GOVD_SEEN);
-                     if (outer->outer_context)
-                       omp_notice_variable (outer->outer_context, decl, true);
+                     n = splay_tree_lookup (outer->variables,
+                                            (splay_tree_key)decl);
+                     if (n == NULL || (n->value & GOVD_DATA_SHARE_CLASS) == 0)
+                       {
+                         omp_add_variable (outer, decl,
+                                           GOVD_LASTPRIVATE | GOVD_SEEN);
+                         if (outer->outer_context)
+                           omp_notice_variable (outer->outer_context, decl,
+                                                true);
+                       }
                    }
                }
 
--- gcc/testsuite/c-c++-common/gomp/pr67521.c.jj        2015-09-09 
17:06:25.488039749 +0200
+++ gcc/testsuite/c-c++-common/gomp/pr67521.c   2015-09-09 17:05:52.000000000 
+0200
@@ -0,0 +1,20 @@
+/* PR middle-end/67521 */
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+void
+foo (int x)
+{
+  int i = 0;
+  #pragma omp parallel for simd
+  for (i = (i & x); i < 10; i = i + 2)
+    ;
+  i = 0;
+  #pragma omp parallel for simd
+  for (i = 0; i < (i & x) + 10; i = i + 2)
+    ;
+  i = 0;
+  #pragma omp parallel for simd
+  for (i = 0; i < 10; i = i + ((i & x) + 2))
+    ;
+}

        Jakub

Reply via email to