From: Andrew Pinski Date: Sat, 24 Jan 2026 01:06:14 +0000 (-0800) Subject: openmp: Fix omp for static schedule loop with pointers [PR97898] X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=9438c98dca4397b0c3b8bed985a6d434d5fb76fa;p=thirdparty%2Fgcc.git 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 --- 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); +} +