When r0-122699-gea3a0fdefa353d was done to fix up handling of
gimple statements in openmp expand, there was one spot which did:
```
if (DECL_P (vback) && TREE_ADDRESSABLE (vback))
  t = force_gimple_operand_gsi (&gsi t, true
```
While other locations did:
```
t = force_gimple_operand_gsi (&gsi t, DECL_P (vback) && TREE_ADDRESSABLE 
(vback) ...
```

This fixes that one location which fixes up openmp for static scheduling with
a pointer as the induction variable.
Basically with a pointer type, we need to convert the rhs of the POINTER_PLUS
to be the same as size_type and with that conversion, the POINTER_PLUS becomes
an invalid gimple.

I don't think this is a regression but this is a small fix up which has now
shown up twice.

Bootstrapped and tested on x86_64-linux-gnu.

        PR middle-end/97898

gcc/ChangeLog:

        * omp-expand.cc (expand_omp_for_static_chunk): Don't
        conditionalize the call to force_gimple_operand_gsi on 
DECL_P/TREE_ADDRESSABLE
        but rather pass that as the 3rd argument.

gcc/testsuite/ChangeLog:

        * c-c++-common/gomp/pr97898-1.c: New test.

Signed-off-by: Andrew Pinski <[email protected]>
---
 gcc/omp-expand.cc                           |  7 ++++---
 gcc/testsuite/c-c++-common/gomp/pr97898-1.c | 12 ++++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/c-c++-common/gomp/pr97898-1.c

diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc
index 9864ce40219..2b4467cab82 100644
--- a/gcc/omp-expand.cc
+++ b/gcc/omp-expand.cc
@@ -6245,9 +6245,10 @@ expand_omp_for_static_chunk (struct omp_region *region,
            t = fold_build_pointer_plus (vmain, step);
          else
            t = fold_build2 (PLUS_EXPR, type, vmain, step);
-         if (DECL_P (vback) && TREE_ADDRESSABLE (vback))
-           t = force_gimple_operand_gsi (&gsi, t, true, NULL_TREE,
-                                         true, GSI_SAME_STMT);
+         t = force_gimple_operand_gsi (&gsi, t,
+                                       DECL_P (vback)
+                                        && TREE_ADDRESSABLE (vback), NULL_TREE,
+                                       true, GSI_SAME_STMT);
          assign_stmt = gimple_build_assign (vback, t);
          gsi_insert_before (&gsi, assign_stmt, GSI_SAME_STMT);
 
diff --git a/gcc/testsuite/c-c++-common/gomp/pr97898-1.c 
b/gcc/testsuite/c-c++-common/gomp/pr97898-1.c
new file mode 100644
index 00000000000..f0d5c46c78e
--- /dev/null
+++ b/gcc/testsuite/c-c++-common/gomp/pr97898-1.c
@@ -0,0 +1,12 @@
+/* { dg-do compile } */
+/* { dg-options "-fopenmp" } */
+
+/* PR middle-end/97898 */
+
+void f (int n, int *s, int *e)
+{
+  int *i;
+#pragma omp for schedule(static, 2)
+  for (i = s; i < e; i += n);
+}
+
-- 
2.43.0

Reply via email to