]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR c/45784 (gcc OpenMP - error: invalid controlling predicate)
authorJakub Jelinek <jakub@redhat.com>
Sat, 16 Sep 2017 18:36:03 +0000 (20:36 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Sat, 16 Sep 2017 18:36:03 +0000 (20:36 +0200)
Backported from mainline
2017-07-27  Jakub Jelinek  <jakub@redhat.com>

PR c/45784
* c-omp.c (c_finish_omp_for): If the condition is wrapped in
rhs of COMPOUND_EXPR(s), skip them and readd their lhs into
new COMPOUND_EXPRs around the rhs of the comparison.

* testsuite/libgomp.c/pr45784.c: New test.
* testsuite/libgomp.c++/pr45784.C: New test.

From-SVN: r252882

gcc/c-family/ChangeLog
gcc/c-family/c-omp.c
libgomp/ChangeLog
libgomp/testsuite/libgomp.c++/pr45784.C [new file with mode: 0644]
libgomp/testsuite/libgomp.c/pr45784.c [new file with mode: 0644]

index 8c0e796f568ae590a3e3f6c3b2a70d4f4df2f7e7..bbe467d3adfee5b11da99f11fc01e5e7e30419fe 100644 (file)
@@ -1,3 +1,13 @@
+2017-09-16  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2017-07-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/45784
+       * c-omp.c (c_finish_omp_for): If the condition is wrapped in
+       rhs of COMPOUND_EXPR(s), skip them and readd their lhs into
+       new COMPOUND_EXPRs around the rhs of the comparison.
+
 2017-09-15  Martin Liska  <mliska@suse.cz>
 
        Backport from mainline
index 987845ba2ce091e4fe473eb9719a865ff7d1821a..15df985836644716b6c0507c139674685579a072 100644 (file)
@@ -511,6 +511,12 @@ c_finish_omp_for (location_t locus, enum tree_code code, tree declv,
        {
          bool cond_ok = false;
 
+         /* E.g. C sizeof (vla) could add COMPOUND_EXPRs with
+            evaluation of the vla VAR_DECL.  We need to readd
+            them to the non-decl operand.  See PR45784.  */
+         while (TREE_CODE (cond) == COMPOUND_EXPR)
+           cond = TREE_OPERAND (cond, 1);
+
          if (EXPR_HAS_LOCATION (cond))
            elocus = EXPR_LOCATION (cond);
 
@@ -585,6 +591,21 @@ c_finish_omp_for (location_t locus, enum tree_code code, tree declv,
                  else if (code != CILK_SIMD && code != CILK_FOR)
                    cond_ok = false;
                }
+
+             if (cond_ok && TREE_VEC_ELT (condv, i) != cond)
+               {
+                 tree ce = NULL_TREE, *pce = &ce;
+                 tree type = TREE_TYPE (TREE_OPERAND (cond, 1));
+                 for (tree c = TREE_VEC_ELT (condv, i); c != cond;
+                      c = TREE_OPERAND (c, 1))
+                   {
+                     *pce = build2 (COMPOUND_EXPR, type, TREE_OPERAND (c, 0),
+                                    TREE_OPERAND (cond, 1));
+                     pce = &TREE_OPERAND (*pce, 1);
+                   }
+                 TREE_OPERAND (cond, 1) = ce;
+                 TREE_VEC_ELT (condv, i) = cond;
+               }
            }
 
          if (!cond_ok)
index b602cf16998e57302781880041e3c4be13017f8d..8304dda7fbbad85f88e6b0d02c45f8c053e32dc5 100644 (file)
@@ -1,3 +1,12 @@
+2017-09-16  Jakub Jelinek  <jakub@redhat.com>
+
+       Backported from mainline
+       2017-07-27  Jakub Jelinek  <jakub@redhat.com>
+
+       PR c/45784
+       * testsuite/libgomp.c/pr45784.c: New test.
+       * testsuite/libgomp.c++/pr45784.C: New test.
+
 2017-05-30  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
diff --git a/libgomp/testsuite/libgomp.c++/pr45784.C b/libgomp/testsuite/libgomp.c++/pr45784.C
new file mode 100644 (file)
index 0000000..306246c
--- /dev/null
@@ -0,0 +1,5 @@
+// PR c/45784
+// { dg-do run }
+
+#include "../libgomp.c/pr45784.c"
+
diff --git a/libgomp/testsuite/libgomp.c/pr45784.c b/libgomp/testsuite/libgomp.c/pr45784.c
new file mode 100644 (file)
index 0000000..7861210
--- /dev/null
@@ -0,0 +1,41 @@
+/* PR c/45784 */
+/* { dg-do run } */
+
+void
+foo (int n)
+{
+  char *p, vla[2 * n];
+  int i;
+  #pragma omp parallel for
+  for (p = vla; p < vla + (sizeof (vla) / sizeof (vla[0])); p++)
+    *p = ' ';
+  #pragma omp parallel for
+  for (i = 0; i < 2 * n; i++)
+    if (vla[i] != ' ')
+      __builtin_abort ();
+}
+
+void
+bar (int n)
+{
+  char *p, vla1[n], vla2[n * 2], vla3[n * 3], vla4[n * 4];
+  int i;
+  __builtin_memset (vla4, ' ', n * 4);
+  #pragma omp parallel for
+  for (p = vla4 + sizeof (vla1); p < vla4 + sizeof (vla3) - sizeof (vla2) + sizeof (vla1); p += sizeof (vla4) / sizeof (vla4))
+    p[0] = '!';
+  #pragma omp parallel for
+  for (i = 0; i < n * 4; i++)
+    if (vla4[i] != ((i >= n && i < 2 * n) ? '!' : ' '))
+      __builtin_abort ();
+}
+
+int
+main ()
+{
+  volatile int n;
+  n = 128;
+  foo (n);
+  bar (n);
+  return 0;
+}