This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Patch, Fortran] PR37420 - Fix -Wunused-variable.


With the support for warning about unset result variables, printing a
warning about other unused variables got disabled. The solution is to
move sym->mark down.

sym->mask = sym->result->mark is unneeded. If the function name = result
name then  sym->result is a pointer to sym and if not, then setting
sym->mask is not needed.

Build and check-gfortran regtested on x86-64-linux.
OK for the trunk?

Tobias
2008-09-09  Tobias Burnus  <burnus@net-b.de>

	PR fortran/37420
	* trans-decl.c (get_proc_pointer_decl): Fix -Wunused-variable.

2008-09-09  Tobias Burnus  <burnus@net-b.de>

	PR fortran/37420
	* gfortran.dg/warn_unused_var.f90: New test.
	* gfortran.dg/warn_unused_var.f90: Add cleanup-modules.

Index: gcc/fortran/trans-decl.c
===================================================================
--- gcc/fortran/trans-decl.c	(Revision 140155)
+++ gcc/fortran/trans-decl.c	(Arbeitskopie)
@@ -1170,7 +1170,8 @@ get_proc_pointer_decl (gfc_symbol *sym)
   decl = build_decl (VAR_DECL, get_identifier (sym->name),
 		     build_pointer_type (gfc_get_function_type (sym)));
 
-  if (sym->ns->proc_name->backend_decl == current_function_decl
+  if ((sym->ns->proc_name
+      && sym->ns->proc_name->backend_decl == current_function_decl)
       || sym->attr.contained)
     gfc_add_decl_to_function (decl);
   else
@@ -3476,11 +3477,6 @@ generate_local_decl (gfc_symbol * sym)
 {
   if (sym->attr.flavor == FL_VARIABLE)
     {
-      /* Check for dependencies in the array specification and string
-	length, adding the necessary declarations to the function.  We
-	mark the symbol now, as well as in traverse_ns, to prevent
-	getting stuck in a circular dependency.  */
-      sym->mark = 1;
       if (!sym->attr.dummy && !sym->ns->proc_name->attr.entry_master)
         generate_dependency_declarations (sym);
 
@@ -3516,6 +3512,12 @@ generate_local_decl (gfc_symbol * sym)
 	  gfc_get_symbol_decl (sym);
 	}
 
+      /* Check for dependencies in the array specification and string
+	length, adding the necessary declarations to the function.  We
+	mark the symbol now, as well as in traverse_ns, to prevent
+	getting stuck in a circular dependency.  */
+      sym->mark = 1;
+
       /* We do not want the middle-end to warn about unused parameters
          as this was already done above.  */
       if (sym->attr.dummy && sym->backend_decl != NULL_TREE)
@@ -3545,7 +3547,7 @@ generate_local_decl (gfc_symbol * sym)
 		        &sym->result->declared_at);
 
 	  /* Prevents "Unused variable" warning for RESULT variables.  */
-	  sym->mark = sym->result->mark = 1;
+	  sym->result->mark = 1;
 	}
     }
 
Index: gcc/testsuite/gfortran.dg/warn_unused_var.f90
===================================================================
--- gcc/testsuite/gfortran.dg/warn_unused_var.f90	(Revision 0)
+++ gcc/testsuite/gfortran.dg/warn_unused_var.f90	(Revision 0)
@@ -0,0 +1,7 @@
+! { dg-do compile }
+! { dg-options "-Wunused-variable" }
+!
+! PR fortran/37420
+!
+integer :: i ! { dg-warning "Unused variable" }
+end
Index: gcc/testsuite/gfortran.dg/implicit_12.f90
===================================================================
--- gcc/testsuite/gfortran.dg/implicit_12.f90	(Revision 140161)
+++ gcc/testsuite/gfortran.dg/implicit_12.f90	(Arbeitskopie)
@@ -21,3 +21,5 @@
    if('#'//Q2//'#' /='#abcdefghijkl#') call abort()
    call sub('ABCDEFGHIJKLM') ! len=13
 end program startest
+
+! { dg-final { cleanup-modules "mod" } }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]