[PATCH/fortran] Add option to make 1st error fatal

Steve Kargl sgk@troutmask.apl.washington.edu
Mon Oct 31 03:38:00 GMT 2005


On Sun, Oct 30, 2005 at 12:58:32PM -0800, Steve Kargl wrote:
> The attached patch has been bootstrapped and regression
> tested on i386-*-freebsd.
> 
> What does it do?  Consider the source in PR fortran/23538.
> This code will cause gfortran to go into an infinite loop,
> which isn't too unexpected in that that code is F66.  However,
> to try to debug the codei and/or gfortran, one see 438 error
> messages fly by the screen.  Many of these errors are simply
> cascaded from an earlier error are somewhat bogus.  This 
> patch disables the output of warnings and the first encountered
> error is fatal.  For example, instead of 438 errors, I now get
> 
> kargl[213] gfc41 -c -ffatal pr23538.f 
>  In file pr23538.f:308
> 
>    37 format(*0absolute addresses of first,nbaxo + nelpaz in elpa*3o21) 
>              1
> Error: Unexpected element in format string at (1)
> 
> 
> OK for mainline?
> 
> 2005-10-30  Steven G. Kargl  <kargls@comcast.net>
> 
> 	*lang.opt: Define -ffatal
> 	*gfortran.h: Add gfc_option.flag_fatal.
> 	*options.c(gfc_init_options,gfc_post_options): Set and use it.
> 	*error.c (gfc_error_check): Use it.
> 	*invoke.texi: Document -ffatal.
> 

Here's a new patch based on feedback from Andrew Pinski on IRC.
Bubblestrap and regression tested on i386-*-freebsd.

2005-10-30  Steven G. Kargl  <kargls@comcast.net>

        *lang.opt: Define -Wfatal-errors and -Werror.
        *gfortran.h: Add gfc_option.warn_error, gfc_option.warn_fatal_error.
        *options.c(gfc_init_options,gfc_post_options): Set and use it.
        *error.c (gfc_error_check): Use it.
        *invoke.texi: Document.

-- 
Steve
-------------- next part --------------
Index: gfortran.h
===================================================================
--- gfortran.h	(revision 106266)
+++ gfortran.h	(working copy)
@@ -1453,6 +1453,8 @@
 
   int warn_aliasing;
   int warn_conversion;
+  int warn_error;
+  int warn_fatal_errors;
   int warn_implicit_interface;
   int warn_line_truncation;
   int warn_underflow;
Index: error.c
===================================================================
--- error.c	(revision 106266)
+++ error.c	(working copy)
@@ -480,6 +480,9 @@
   va_end (argp);
 
   error_char ('\0');
+
+  if (gfc_option.warn_error)
+    exit (1);
 }
 
 
@@ -571,6 +574,9 @@
       if (warning_buffer.message != NULL)
 	fputs (warning_buffer.message, stderr);
       warning_buffer.flag = 0;
+
+      if (gfc_option.warn_error)
+	exit (1);
     }
 }
 
@@ -687,6 +693,9 @@
       if (error_buffer.message != NULL)
 	fputs (error_buffer.message, stderr);
       error_buffer.flag = 0;
+
+      if (gfc_option.warn_fatal_errors)
+	exit (1);
     }
 
   return rc;
Index: lang.opt
===================================================================
--- lang.opt	(revision 106266)
+++ lang.opt	(working copy)
@@ -45,6 +45,14 @@
 Fortran
 Warn about implicit conversion
 
+Werror
+Fortran
+Warning message becomes fatal
+
+Wfatal-errors
+Fortran RejectNegative
+Error message becomes fatal
+
 Wimplicit-interface
 Fortran
 Warn about calls with implicit interface
Index: invoke.texi
===================================================================
--- invoke.texi	(revision 106266)
+++ invoke.texi	(working copy)
@@ -126,7 +126,7 @@
 @xref{Warning Options,,Options to Request or Suppress Warnings}.
 @gccoptlist{
 -fsyntax-only  -pedantic  -pedantic-errors @gol
--w  -Wall  -Waliasing  -Wconversion @gol
+-w  -Wall  -Waliasing  -Wconversion -Werror -Wfatal-errors @gol
 -Wimplicit-interface  -Wnonstd-intrinsics  -Wsurprising  -Wunderflow @gol
 -Wunused-labels -Wline-truncation @gol
 -Werror  -W}
@@ -382,6 +382,20 @@
 Warn about implicit conversions between different types.
 
 
+@cindex -Werror option
+@item -Werror
+@cindex fatal warnings
+The first encountered warning will be fatal.  This option
+should be used with discretion with legacy code.
+
+
+@cindex -Wfatal-errors option
+@item -Wfatal-errors
+@cindex fatal errors
+The first encountered error will be fatal.  If the -Werror option 
+is used, warnings are ignored.
+
+
 @cindex -Wimplicit-interface option
 @cindex options, -Wimplicit-interface
 @item -Wimplicit-interface
@@ -722,7 +736,6 @@
 In the future this may also include other forms of checking, eg. checking
 substring references.
 
-
 @cindex -fmax-stack-var-size option
 @item -fmax-stack-var-size=@var{n}
 This option specifies the size in bytes of the largest array that will be put
Index: options.c
===================================================================
--- options.c	(revision 106266)
+++ options.c	(working copy)
@@ -52,6 +52,8 @@
 
   gfc_option.warn_aliasing = 0;
   gfc_option.warn_conversion = 0;
+  gfc_option.warn_error = 0;
+  gfc_option.warn_fatal_errors = 0;
   gfc_option.warn_implicit_interface = 0;
   gfc_option.warn_line_truncation = 0;
   gfc_option.warn_underflow = 1;
@@ -234,6 +236,10 @@
   if (!gfc_option.flag_automatic)
     gfc_option.flag_max_stack_var_size = 0;
 
+  /* Inhibit warnings if -Wfatal-error is given and -Werror is not.  */
+  if (gfc_option.warn_fatal_errors && !gfc_option.warn_error)
+    inhibit_warnings = 1;
+
   return false;
 }
 
@@ -350,6 +356,14 @@
       gfc_option.warn_conversion = value;
       break;
 
+    case OPT_Werror:
+      gfc_option.warn_error = 1;
+      break;
+
+    case OPT_Wfatal_errors:
+      gfc_option.warn_fatal_errors = 1;
+      break;
+
     case OPT_Wimplicit_interface:
       gfc_option.warn_implicit_interface = value;
       break;


More information about the Gcc-patches mailing list