All, Currently warnings given by the GNU Fortran front-end typically indicate which flag controls the warning, if any, as given by the first argument to gfc_warning. However, there is no support for controlling warnings which are emitted by gfc_error when warnings_not_errors is set. Herein I propose a patch such that when a call to gfc_error may cause a warning, suppression of the warning can be controlled with a -W* warning flag, as with other warnings.
The simple patch extends the gfc_error interface to also accept an additional 'opt' arg, which is passed as the same first argument to gfc_warning if warnings_not_errors causes a warning instead of an error. The old interface remains, so that a default 'opt' of 0 is passed when gfc_error is called with no 'opt' argument. This minimizes the impact of the interface change on existing code. Note also that if the call to gfc_error would actually cause an error, the warning flag will not suppress the error. See the patch for details. Bootstraps and regtests on x86_64-redhat-linux. Another patch proposal will follow which utilizes this functionality to introduce a new warning -W[no-]argument-mismatch, assuming this one is OK. --- Fritz Reese From: Fritz Reese <fritzore...@gmail.com> Date: Thu, 27 Oct 2016 13:33:57 -0400 Subject: [PATCH] Allow warning flags to associate through gfc_error. gcc/fortran/ * gfortran.h (gfc_error): New declaration for gfc_error with 'opt'. * error.c (gfc_error): Add optional 'opt' argument. * error.c (gfc_notify_std): Call fully-qualified gfc_error.
diff --git a/gcc/fortran/error.c b/gcc/fortran/error.c index fe91419..0fd8a4e 100644 --- a/gcc/fortran/error.c +++ b/gcc/fortran/error.c @@ -67,7 +67,7 @@ gfc_push_suppress_errors (void) } static void -gfc_error (const char *gmsgid, va_list ap) ATTRIBUTE_GCC_GFC(1,0); +gfc_error (int opt, const char *gmsgid, va_list ap) ATTRIBUTE_GCC_GFC(2,0); static bool gfc_warning (int opt, const char *gmsgid, va_list ap) ATTRIBUTE_GCC_GFC(2,0); @@ -902,7 +902,7 @@ gfc_notify_std (int std, const char *gmsgid, ...) if (warning) gfc_warning (0, buffer, argp); else - gfc_error (buffer, argp); + gfc_error (0, buffer, argp); va_end (argp); return (warning && !warnings_are_errors) ? true : false; @@ -1233,7 +1233,7 @@ gfc_warning_check (void) /* Issue an error. */ static void -gfc_error (const char *gmsgid, va_list ap) +gfc_error (int opt, const char *gmsgid, va_list ap) { va_list argp; va_copy (argp, ap); @@ -1241,7 +1241,7 @@ gfc_error (const char *gmsgid, va_list ap) if (warnings_not_errors) { - gfc_warning (/*opt=*/0, gmsgid, argp); + gfc_warning (opt, gmsgid, argp); va_end (argp); return; } @@ -1289,11 +1289,21 @@ gfc_error (const char *gmsgid, va_list ap) void +gfc_error (int opt, const char *gmsgid, ...) +{ + va_list argp; + va_start (argp, gmsgid); + gfc_error (opt, gmsgid, argp); + va_end (argp); +} + + +void gfc_error (const char *gmsgid, ...) { va_list argp; va_start (argp, gmsgid); - gfc_error (gmsgid, argp); + gfc_error (0, gmsgid, argp); va_end (argp); } diff --git a/gcc/fortran/gfortran.h b/gcc/fortran/gfortran.h index a0dcf6d..3fb6f41 100644 --- a/gcc/fortran/gfortran.h +++ b/gcc/fortran/gfortran.h @@ -2731,6 +2731,7 @@ bool gfc_warning_now_at (location_t loc, int opt, const char *gmsgid, ...) void gfc_clear_warning (void); void gfc_warning_check (void); +void gfc_error (int opt, const char *, ...) ATTRIBUTE_GCC_GFC(2,3); void gfc_error (const char *, ...) ATTRIBUTE_GCC_GFC(1,2); void gfc_error_now (const char *, ...) ATTRIBUTE_GCC_GFC(1,2); void gfc_fatal_error (const char *, ...) ATTRIBUTE_NORETURN ATTRIBUTE_GCC_GFC(1,2);