https://gcc.gnu.org/g:32bbd8849a550ad6f936636476c3ab9be8a58807
commit r17-1387-g32bbd8849a550ad6f936636476c3ab9be8a58807 Author: Sandra Loosemore <[email protected]> Date: Wed Mar 4 18:44:55 2026 +0000 openmp: Remove warning about unused iterator variable in map clauses The gimplifier currently issues a warning about unused iterator variables in map clauses, implemented by doing a code walk to search for uses. Unfortunately this is too late; the front ends can optimize away explicit references to variables, for example by using fold_build* expression constructors. This leads to false positives. Additionally the Fortran front end constructs implicit map clauses for array descriptors that may be associated with iterators but don't reference the iterator variable. Warning about these is just confusing. Probably, if we are going to warn about this, it should happen in the front ends. But it's probably not important enough to justify the amount of work required, so for now, let's just remove it from the gimplifier. gcc/ChangeLog * gimplify.cc (remove_unused_omp_iterator_vars): Don't warn about possibly-unused iterator variables. Simplify control flow of remaining code. gcc/testsuite/ChangeLog * c-c++-common/gomp/target-map-iterators-2.c: Don't expect warnings about unused iterator variables. * c-c++-common/gomp/target-update-iterators-2.c: Likewise. Diff: --- gcc/gimplify.cc | 14 ++------------ gcc/testsuite/c-c++-common/gomp/target-map-iterators-2.c | 7 ++----- .../c-c++-common/gomp/target-update-iterators-2.c | 7 ++----- 3 files changed, 6 insertions(+), 22 deletions(-) diff --git a/gcc/gimplify.cc b/gcc/gimplify.cc index 185f2152ee4d..0bd1df640f85 100644 --- a/gcc/gimplify.cc +++ b/gcc/gimplify.cc @@ -9930,23 +9930,13 @@ remove_unused_omp_iterator_vars (tree *list_p) if (t == NULL_TREE) t = walk_tree (&OMP_CLAUSE_SIZE (c), find_var_decl, var, NULL); if (t == NULL_TREE) - { - need_new_iterators = true; - if ((OMP_CLAUSE_CODE (c) == OMP_CLAUSE_MAP - && (OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_TO - || OMP_CLAUSE_MAP_KIND (c) == GOMP_MAP_FROM)) - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_TO - || OMP_CLAUSE_CODE (c) == OMP_CLAUSE_FROM) - warning_at (OMP_CLAUSE_LOCATION (c), OPT_Wopenmp, - "iterator variable %qE not used in clause " - "expression", DECL_NAME (var)); - } + need_new_iterators = true; else vars.safe_push (var); } if (!need_new_iterators) continue; - if (need_new_iterators && vars.is_empty ()) + if (vars.is_empty ()) { /* No iteration variables are used in the clause - remove the iterator from the clause. */ diff --git a/gcc/testsuite/c-c++-common/gomp/target-map-iterators-2.c b/gcc/testsuite/c-c++-common/gomp/target-map-iterators-2.c index 42c6d75bc057..325e19595bc9 100644 --- a/gcc/testsuite/c-c++-common/gomp/target-map-iterators-2.c +++ b/gcc/testsuite/c-c++-common/gomp/target-map-iterators-2.c @@ -3,18 +3,15 @@ void f (int *x, float *y, double *z) { - #pragma omp target map(iterator(i=0:10), to: x) /* { dg-warning "iterator variable 'i' not used in clause expression" } */ + #pragma omp target map(iterator(i=0:10), to: x) /* Add a reference to x to ensure that the 'to' clause does not get dropped. */ x[0] = 0; - #pragma omp target map(iterator(i2=0:10, j2=0:20), from: x[i2]) /* { dg-warning "iterator variable 'j2' not used in clause expression" } */ + #pragma omp target map(iterator(i2=0:10, j2=0:20), from: x[i2]) ; #pragma omp target map(iterator(i3=0:10, j3=0:20, k3=0:30), to: x[i3+j3], y[j3+k3], z[k3+i3]) - /* { dg-warning "iterator variable 'i3' not used in clause expression" "" { target *-*-* } .-1 } */ - /* { dg-warning "iterator variable 'j3' not used in clause expression" "" { target *-*-* } .-2 } */ - /* { dg-warning "iterator variable 'k3' not used in clause expression" "" { target *-*-* } .-3 } */ ; /* Test iterator with zero iterations. */ diff --git a/gcc/testsuite/c-c++-common/gomp/target-update-iterators-2.c b/gcc/testsuite/c-c++-common/gomp/target-update-iterators-2.c index dbd43e0f30c8..12ca794d7723 100644 --- a/gcc/testsuite/c-c++-common/gomp/target-update-iterators-2.c +++ b/gcc/testsuite/c-c++-common/gomp/target-update-iterators-2.c @@ -3,16 +3,13 @@ void f (int *x, float *y, double *z) { - #pragma omp target update to(iterator(i=0:10): x) /* { dg-warning "iterator variable 'i' not used in clause expression" }*/ + #pragma omp target update to(iterator(i=0:10): x) ; - #pragma omp target update from(iterator(i2=0:10, j2=0:20): x[i2]) /* { dg-warning "iterator variable 'j2' not used in clause expression" }*/ + #pragma omp target update from(iterator(i2=0:10, j2=0:20): x[i2]) ; #pragma omp target update to(iterator(i3=0:10, j3=0:20, k3=0:30): x[i3+j3], y[j3+k3], z[k3+i3]) - /* { dg-warning "iterator variable 'i3' not used in clause expression" "" { target *-*-* } .-1 } */ - /* { dg-warning "iterator variable 'j3' not used in clause expression" "" { target *-*-* } .-2 } */ - /* { dg-warning "iterator variable 'k3' not used in clause expression" "" { target *-*-* } .-3 } */ ; }
