]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Mark type-spec iterators referenced.
authorJerry DeLisle <jvdelisle@gcc.gnu.org>
Thu, 13 Nov 2025 00:03:34 +0000 (16:03 -0800)
committerJerry DeLisle <jvdelisle@gcc.gnu.org>
Thu, 13 Nov 2025 00:10:57 +0000 (16:10 -0800)
Mark DO CONCURRENT iterators created via a type-spec as referenced so that
generated shadow names are not warned about under -Wall.

PR fortran/96255

gcc/fortran/ChangeLog:

* match.cc (apply_typespec_to_iterator): Call gfc_set_sym_referenced
for both new and shadow iterator symbols.

gcc/testsuite/ChangeLog:

* gfortran.dg/do_concurrent_typespec_1.f90: Update testcase to check
for bugus warnings.

gcc/fortran/match.cc
gcc/testsuite/gfortran.dg/do_concurrent_typespec_1.f90

index 60434c14ee27cb986ee53f969c43608e8437b6d4..e009c82b0bd049dc27998e9d13a7374c02e6b0f4 100644 (file)
@@ -2630,6 +2630,7 @@ apply_typespec_to_iterator (gfc_forall_iterator *iter, gfc_typespec *ts,
       /* Variable not declared in outer scope - just set the type.  */
       v->ts.type = v->symtree->n.sym->ts.type = BT_INTEGER;
       v->ts.kind = v->symtree->n.sym->ts.kind = ts->kind;
+      gfc_set_sym_referenced (v->symtree->n.sym);
     }
   else
     {
@@ -2651,6 +2652,7 @@ apply_typespec_to_iterator (gfc_forall_iterator *iter, gfc_typespec *ts,
       v->symtree = st;
       gfc_replace_expr (iter->var, v);
       iter->shadow = true;
+      gfc_set_sym_referenced (st->n.sym);
     }
 
   /* Convert iterator bounds to the specified type.  */
index f5c498f6f278b5dacdea54eb8ac9e183c87f25ac..45407a162e7d2690a58e1aa81096d6467151f3fb 100644 (file)
@@ -1,5 +1,8 @@
 ! { dg-do run }
-! { dg-options "-std=f2008" }
+! { dg-options "-std=f2008 -Wall" }
+! { dg-bogus "Unused variable '_i' declared" }
+! { dg-bogus "Unused variable '_k' declared" }
+! { dg-bogus "Unused variable 'n' declared" }
 !
 ! PR fortran/96255
 ! Test DO CONCURRENT with optional type specification
@@ -29,8 +32,6 @@ program test_do_concurrent_typespec
   call test_multiple_iterators()
   test_count = test_count + 1
 
-  print *, "All", test_count, "tests passed"
-
 contains
 
   subroutine test_no_outer_var()