https://gcc.gnu.org/g:9438c98dca4397b0c3b8bed985a6d434d5fb76fa

commit r16-7079-g9438c98dca4397b0c3b8bed985a6d434d5fb76fa
Author: Andrew Pinski <[email protected]>
Date:   Fri Jan 23 17:06:14 2026 -0800

    openmp: Fix omp for static schedule loop with pointers [PR97898]
    
    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]>

Diff:
---
 gcc/omp-expand.cc                           |  7 ++++---
 gcc/testsuite/c-c++-common/gomp/pr97898-1.c | 12 ++++++++++++
 2 files changed, 16 insertions(+), 3 deletions(-)

diff --git a/gcc/omp-expand.cc b/gcc/omp-expand.cc
index 9864ce402197..2b4467cab820 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 000000000000..f0d5c46c78e3
--- /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);
+}
+

Reply via email to