]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Backport "Fix condition folding in c_parser_omp_for_loop"
authorTom de Vries <tom@codesourcery.com>
Sun, 10 Dec 2017 21:37:08 +0000 (21:37 +0000)
committerTom de Vries <vries@gcc.gnu.org>
Sun, 10 Dec 2017 21:37:08 +0000 (21:37 +0000)
2017-12-10  Tom de Vries  <tom@codesourcery.com>

backport from trunk:
2017-09-16  Tom de Vries  <tom@codesourcery.com>

PR c/81875
* c-parser.c (c_parser_omp_for_loop): Fold only operands of cond, not
cond itself.

* testsuite/libgomp.c/pr81875.c: New test.

From-SVN: r255532

gcc/c/ChangeLog
gcc/c/c-parser.c
libgomp/ChangeLog
libgomp/testsuite/libgomp.c/pr81875.c [new file with mode: 0644]

index ee10fbeb25fb0b18ab383f10e39bb3fc31f57e7a..1a9c04045a6fa19f6fe20cc7e70a7e4aa45f7a09 100644 (file)
@@ -1,3 +1,12 @@
+2017-12-10  Tom de Vries  <tom@codesourcery.com>
+
+       backport from trunk:
+       PR c/81875
+       2017-09-16  Tom de Vries  <tom@codesourcery.com>
+
+       * c-parser.c (c_parser_omp_for_loop): Fold only operands of cond, not
+       cond itself.
+
 2017-07-04  Release Manager
 
        * GCC 6.4.0 released.
index 4044bb58c8763c9de8f80038735fdc6950ed2f53..fc20bad8d9926ac513a1908d848292aa7702de6e 100644 (file)
@@ -14767,7 +14767,14 @@ c_parser_omp_for_loop (location_t loc, c_parser *parser, enum tree_code code,
 
          cond = cond_expr.value;
          cond = c_objc_common_truthvalue_conversion (cond_loc, cond);
-         cond = c_fully_fold (cond, false, NULL);
+         if (COMPARISON_CLASS_P (cond))
+           {
+             tree op0 = TREE_OPERAND (cond, 0), op1 = TREE_OPERAND (cond, 1);
+             op0 = c_fully_fold (op0, false, NULL);
+             op1 = c_fully_fold (op1, false, NULL);
+             TREE_OPERAND (cond, 0) = op0;
+             TREE_OPERAND (cond, 1) = op1;
+           }
          switch (cond_expr.original_code)
            {
            case GT_EXPR:
index a8db5f768343afa3ad013620a3338baa3558425a..a5e99d38a5efe3399c8fd713e2719ae51cf243a0 100644 (file)
@@ -1,3 +1,11 @@
+2017-12-10  Tom de Vries  <tom@codesourcery.com>
+
+       backport from trunk:
+       PR c/81875
+       2017-09-16  Tom de Vries  <tom@codesourcery.com>
+
+       * testsuite/libgomp.c/pr81875.c: New test.
+
 2017-09-15  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
diff --git a/libgomp/testsuite/libgomp.c/pr81875.c b/libgomp/testsuite/libgomp.c/pr81875.c
new file mode 100644 (file)
index 0000000..3067d49
--- /dev/null
@@ -0,0 +1,46 @@
+/* { dg-do run } */
+
+extern
+#ifdef __cplusplus
+"C"
+#endif
+void abort (void);
+
+#define N 32ULL
+int a[N];
+
+const unsigned long long c = 0x7fffffffffffffffULL;
+
+void
+f2_tpf_static32 (void)
+{
+  unsigned long long i;
+  #pragma omp for
+  for (i = c + N; i > c; i -= 1ULL)
+    a[i - 1ULL - c] -= 4;
+}
+
+__attribute__((noinline, noclone)) int
+test_tpf_static32 (void)
+{
+  int i, j, k;
+  for (i = 0; i < N; i++)
+    a[i] = i - 25;
+
+  f2_tpf_static32 ();
+
+  for (i = 0; i < N; i++)
+    if (a[i] != i - 29)
+      return 1;
+
+  return 0;
+}
+
+int
+main ()
+{
+  if (test_tpf_static32 ())
+    abort ();
+
+  return 0;
+}