re PR fortran/77260 (bogus warning with ENTRY in a function)
authorSteven G. Kargl <kargl@gcc.gnu.org>
Mon, 22 Aug 2016 18:12:33 +0000 (18:12 +0000)
committerSteven G. Kargl <kargl@gcc.gnu.org>
Mon, 22 Aug 2016 18:12:33 +0000 (18:12 +0000)
2016-08-22  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/77260
* gcc/fortran/trans-decl.c (generate_local_decl): Suppress warning
for unused variable if symbol is entry point.

2016-08-22  Steven G. Kargl  <kargl@gcc.gnu.org>

PR fortran/77260
* gfortran.dg/pr77260_1.f90: New test.
* gfortran.dg/pr77260_2.f90: Ditto.

From-SVN: r239666

gcc/fortran/ChangeLog
gcc/fortran/trans-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gfortran.dg/pr77260_1.f90 [new file with mode: 0644]
gcc/testsuite/gfortran.dg/pr77260_2.f90 [new file with mode: 0644]

index a404c432d64087f9af0ba36b2e57fa1fd5dcf102..900d91560f292e7e3cb1e1ec5eabb476578bf7be 100644 (file)
@@ -1,3 +1,10 @@
+2016-08-22  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/77260
+       * gcc/fortran/trans-decl.c (generate_local_decl): Suppress warning
+       for unused variable if symbol is entry point.
+
+
 2016-08-19  Joseph Myers  <joseph@codesourcery.com>
 
        PR c/32187
index 6cf7f573bf616154c653cee1fb11e379d8860b7d..96d413eb8c2d2ea687a8263b241fbff070e63d47 100644 (file)
@@ -5316,9 +5316,19 @@ generate_local_decl (gfc_symbol * sym)
            }
          else if (!sym->attr.use_assoc)
            {
-             gfc_warning (OPT_Wunused_variable,
-                          "Unused variable %qs declared at %L",
-                          sym->name, &sym->declared_at);
+             /* Corner case: the symbol may be an entry point.  At this point,
+                it may appear to be an unused variable.  Suppress warning.  */
+             bool enter = false;
+             gfc_entry_list *el;
+
+             for (el = sym->ns->entries; el; el=el->next)
+               if (strcmp(sym->name, el->sym->name) == 0)
+                 enter = true;
+
+             if (!enter)
+               gfc_warning (OPT_Wunused_variable,
+                            "Unused variable %qs declared at %L",
+                            sym->name, &sym->declared_at);
              if (sym->backend_decl != NULL_TREE)
                TREE_NO_WARNING(sym->backend_decl) = 1;
            }
index 0a82b69d0586faa5e7332844fe10c6ccaeedfe12..82b4db4d9602e2a65185eafe4f6384306187c190 100644 (file)
@@ -1,3 +1,9 @@
+2016-08-22  Steven G. Kargl  <kargl@gcc.gnu.org>
+
+       PR fortran/77260
+       * gfortran.dg/pr77260_1.f90: New test.
+       * gfortran.dg/pr77260_2.f90: Ditto.
+
 2016-08-22  Joseph Myers  <joseph@codesourcery.com>
 
        PR middle-end/77269
diff --git a/gcc/testsuite/gfortran.dg/pr77260_1.f90 b/gcc/testsuite/gfortran.dg/pr77260_1.f90
new file mode 100644 (file)
index 0000000..0d2ead6
--- /dev/null
@@ -0,0 +1,25 @@
+! { dg-do compile }
+! { dg-options "-Wall" }
+module foo
+
+   implicit none
+
+   private
+   public f1,f2
+
+   contains
+
+      integer function f1()
+         integer f2
+         f1=5
+      entry f2
+         f2=8
+      end function
+end module
+
+program test
+   use foo
+   implicit none
+   print *,f2()
+end program
+! { dg-final { cleanup-modules "foo" } }
diff --git a/gcc/testsuite/gfortran.dg/pr77260_2.f90 b/gcc/testsuite/gfortran.dg/pr77260_2.f90
new file mode 100644 (file)
index 0000000..ea8da4f
--- /dev/null
@@ -0,0 +1,26 @@
+! { dg-do compile }
+! { dg-options "-Wall" }
+module foo
+
+   implicit none
+
+   private
+   public f1,f2
+
+   contains
+
+      integer function f1()
+         integer f2
+         integer f3           ! { dg-warning "Unused variable" }
+         f1=5
+      entry f2
+         f2=8
+      end function
+end module
+
+program test
+   use foo
+   implicit none
+   print *,f2()
+end program
+! { dg-final { cleanup-modules "foo" } }