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]

Re: PING: [Patch, Fortran] PR 22552: New warning -Wimplicit-procedure


And now with patch attached...

Daniel Kraft wrote:
ping for the one below!

Thanks,
Daniel

Daniel Kraft wrote:
Hi,

this implements the warning asked for in PR 22552. A new flag -Wimplicit-procedure is added, that warns about usage of a procedure never explicitly declared. That is,

EXTERNAL :: foobar
CALL foobar ()

will not trigger this warning, as -Wimplicit-interface would do. Also, something like

INTEGER :: foobar

also prevents the warning, as does an implicit type. This means that the warning will only ever be issued for SUBROUTINES, as FUNCTIONS need to have a type.

See the test-case for a full example.

While I don't think this flag is very useful for new code (there -Wimplicit-interface could be used better, I guess, when only module procedures with explicit interfaces are used), the patch is quite straight-forward and thus I think we can include it to help with those codes not yet having only explicit-interface procedures.

I did build this patch on the code snipped provided by FX in the PR.

Regression-testing on GNU/Linux-x86-32 at the moment. Do you think this new flag is ok, and ok for trunk if successful?

Yours,
Daniel





--
Done:  Arc-Bar-Cav-Ran-Rog-Sam-Tou-Val-Wiz
To go: Hea-Kni-Mon-Pri
Index: gcc/fortran/interface.c
===================================================================
--- gcc/fortran/interface.c	(revision 145952)
+++ gcc/fortran/interface.c	(working copy)
@@ -2429,12 +2429,18 @@ gfc_procedure_use (gfc_symbol *sym, gfc_
 
   /* Warn about calls with an implicit interface.  Special case
      for calling a ISO_C_BINDING becase c_loc and c_funloc
-     are pseudo-unknown.  */
-  if (gfc_option.warn_implicit_interface
-      && sym->attr.if_source == IFSRC_UNKNOWN
-      && ! sym->attr.is_iso_c)
-    gfc_warning ("Procedure '%s' called with an implicit interface at %L",
-		 sym->name, where);
+     are pseudo-unknown.  Additionally, warn about procedures not
+     explicitly declared at all if requested.  */
+  if (sym->attr.if_source == IFSRC_UNKNOWN && ! sym->attr.is_iso_c)
+    {
+      if (gfc_option.warn_implicit_interface)
+	gfc_warning ("Procedure '%s' called with an implicit interface at %L",
+		     sym->name, where);
+      else if (gfc_option.warn_implicit_procedure
+	       && sym->attr.proc == PROC_UNKNOWN)
+	gfc_warning ("Procedure '%s' called at %L is not explicitly declared",
+		     sym->name, where);
+    }
 
   if (sym->ts.interface && sym->ts.interface->attr.intrinsic)
     {
Index: gcc/fortran/gfortran.h
===================================================================
--- gcc/fortran/gfortran.h	(revision 145952)
+++ gcc/fortran/gfortran.h	(working copy)
@@ -1985,6 +1985,7 @@ typedef struct
   int warn_ampersand;
   int warn_conversion;
   int warn_implicit_interface;
+  int warn_implicit_procedure;
   int warn_line_truncation;
   int warn_surprising;
   int warn_tabs;
Index: gcc/fortran/lang.opt
===================================================================
--- gcc/fortran/lang.opt	(revision 145952)
+++ gcc/fortran/lang.opt	(working copy)
@@ -96,6 +96,10 @@ Wimplicit-interface
 Fortran Warning
 Warn about calls with implicit interface
 
+Wimplicit-procedure
+Fortran Warning
+Warn about called procedures not explicitly declared
+
 Wline-truncation
 Fortran Warning
 Warn about truncated source lines
Index: gcc/fortran/invoke.texi
===================================================================
--- gcc/fortran/invoke.texi	(revision 145952)
+++ gcc/fortran/invoke.texi	(working copy)
@@ -137,9 +137,9 @@ and warnings}.
 @gccoptlist{-fmax-errors=@var{n} @gol
 -fsyntax-only  -pedantic  -pedantic-errors @gol
 -Wall  -Waliasing  -Wampersand  -Warray-bounds -Wcharacter-truncation @gol
--Wconversion -Wimplicit-interface  -Wline-truncation  -Wintrinsics-std @gol
--Wsurprising -Wno-tabs  -Wunderflow -Wunused-parameter -Wintrinsics-shadow @gol
--Wno-align-commons}
+-Wconversion -Wimplicit-interface  -Wimplicit-procedure  -Wline-truncation @gol
+-Wintrinsics-std  -Wsurprising  -Wno-tabs  -Wunderflow  -Wunused-parameter @gol
+-Wintrinsics-shadow  -Wno-align-commons}
 
 @item Debugging Options
 @xref{Debugging Options,,Options for debugging your program or GNU Fortran}.
@@ -753,6 +753,13 @@ Warn if a procedure is called without an
 Note this only checks that an explicit interface is present.  It does not
 check that the declared interfaces are consistent across program units.
 
+@item -Wimplicit-procedure
+@opindex @code{Wimplicit-procedure}
+@cindex warnings, implicit procedure
+Warn if a procedure is called that has not been declared explicitly (either by
+having an explicit interface, being a module procedure or declaring it
+@code{EXTERNAL}).
+
 @item -Wintrinsics-std
 @opindex @code{Wintrinsics-std}
 @cindex warnings, non-standard intrinsics
Index: gcc/fortran/options.c
===================================================================
--- gcc/fortran/options.c	(revision 145952)
+++ gcc/fortran/options.c	(working copy)
@@ -550,6 +550,10 @@ gfc_handle_option (size_t scode, const c
       gfc_option.warn_implicit_interface = value;
       break;
 
+    case OPT_Wimplicit_procedure:
+      gfc_option.warn_implicit_procedure = value;
+      break;
+
     case OPT_Wline_truncation:
       gfc_option.warn_line_truncation = value;
       break;
Index: gcc/testsuite/gfortran.dg/warn_implicit_procedure_1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/warn_implicit_procedure_1.f90	(revision 0)
+++ gcc/testsuite/gfortran.dg/warn_implicit_procedure_1.f90	(revision 0)
@@ -0,0 +1,43 @@
+! { dg-do compile }
+! { dg-options "-Wimplicit-procedure" }
+
+! PR fortran/22552
+! Check for correct -Wimplicit-procedure warnings.
+
+MODULE m
+
+CONTAINS
+
+  SUBROUTINE my_sub ()
+  END SUBROUTINE my_sub
+
+  INTEGER FUNCTION my_func ()
+    my_func = 42
+  END FUNCTION my_func
+
+END MODULE m
+
+SUBROUTINE test (proc)
+  IMPLICIT NONE
+  CALL proc () ! { dg-bogus "is not explicitly declared" }
+END SUBROUTINE test
+
+PROGRAM main
+  USE m
+  EXTERNAL :: ext_sub
+  EXTERNAL :: test
+  INTEGER :: ext_func
+
+  CALL ext_sub () ! { dg-bogus "is not explicitly declared" }
+  PRINT *, ext_func () ! { dg-bogus "is not explicitly declared" }
+  PRINT *, implicit_func () ! { dg-bogus "is not explicitly declared" }
+  CALL my_sub () ! { dg-bogus "is not explicitly declared" }
+  PRINT *, my_func () ! { dg-bogus "is not explicitly declared" }
+  PRINT *, SIN (3.14159) ! { dg-bogus "is not explicitly declared" }
+
+  CALL undef_sub (1, 2, 3) ! { dg-warning "is not explicitly declared" }
+  ! Can't check undefined function, because it needs to be declared a type
+  ! in any case (and the implicit type is enough to not trigger this warning).
+END PROGRAM
+
+! { dg-final { cleanup-modules "m" } }
2009-04-11  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
	    Daniel Kraft  <d@domob.eu>

	PR fortran/22552
	* lang.opt (Wimplicit-procedure): New option.
	* gfortran.h (struct gfc_option_t): New member `warn_implicit_procedure'
	* options.c (gfc_handle_option): Handle -Wimplicit-procedure.
	* interface.c (gfc_procedure_use): Warn about procedure never
	explicitly declared if requested by the new flag.
	* invoke.texi: Document new flag -Wimplicit-procedure.

2009-04-11  Francois-Xavier Coudert  <fxcoudert@gcc.gnu.org>
	    Daniel Kraft  <d@domob.eu>

	PR fortran/22552
	* gfortran.dg/warn_implicit_procedure_1.f90: New test.

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