[RFC] possible approach to fix fortran/pr21061
Bernhard Fischer
rep.nop@aon.at
Sat Nov 26 16:44:00 GMT 2005
Hello,
Attached patchlet would fix pr21061.
Two short questions:
(1) Is the path taken in this patch ok?
(2) There are a couple of warning() invocations, which obviously do not
use gfc_{warning,error}() but the generic ones from C et al. The second
part of attached patch does correct all except one occurance of
"warning()" in trans-decl.c. My question is, is it ok to remove these
warning() calls in favour of using the gfc_() ones? This would make the
warning and error diagnostics more consistent, imho.
Opinions?
PS: if (1) is ok, then i'll clean it up and submit proper.
TIA,
Bernhard
-------------- next part --------------
diff -X excl -rduNp gcc.oorig/gcc/fortran/error.c gcc/gcc/fortran/error.c
--- gcc.oorig/gcc/fortran/error.c 2005-11-09 22:45:27.000000000 +0100
+++ gcc/gcc/fortran/error.c 2005-11-26 13:51:10.000000000 +0100
@@ -23,7 +23,7 @@ Software Foundation, 51 Franklin Street,
/* Handle the inevitable errors. A major catch here is that things
flagged as errors in one match subroutine can conceivably be legal
elsewhere. This means that error messages are recorded and saved
- for possible use later. If a line does not match a legal
+ for possible later use. If a line does not match a legal
construction, then the saved error message is reported. */
#include "config.h"
@@ -114,7 +114,7 @@ error_string (const char *p)
}
-/* Show the file, where it was included and the source line, give a
+/* Show the file, where it was included and the source line, given a
locus. Calls error_printf() recursively, but the recursion is at
most one level deep. */
@@ -461,25 +461,18 @@ error_printf (const char *nocmsgid, ...)
/* Issue a warning. */
-void
-gfc_warning (const char *nocmsgid, ...)
+static void
+_gfc_warning (const char *nocmsgid, va_list argp)
{
- va_list argp;
-
- if (inhibit_warnings)
- return;
warning_buffer.flag = 1;
warning_buffer.index = 0;
cur_error_buffer = &warning_buffer;
- va_start (argp, nocmsgid);
if (buffer_flag == 0)
warnings++;
error_print (_("Warning:"), _(nocmsgid), argp);
- va_end (argp);
- error_char ('\0');
}
@@ -502,7 +495,10 @@ gfc_notify_std (int std, const char *noc
if (gfc_suppress_error)
return warning ? SUCCESS : FAILURE;
-
+
+ if (warnings_are_errors)
+ warning = 0;
+
cur_error_buffer = warning ? &warning_buffer : &error_buffer;
cur_error_buffer->flag = 1;
cur_error_buffer->index = 0;
@@ -525,27 +521,19 @@ gfc_notify_std (int std, const char *noc
return warning ? SUCCESS : FAILURE;
}
-
/* Immediate warning (i.e. do not buffer the warning). */
-void
-gfc_warning_now (const char *nocmsgid, ...)
+static void
+_gfc_warning_now (const char *nocmsgid, va_list argp)
{
- va_list argp;
int i;
- if (inhibit_warnings)
- return;
-
i = buffer_flag;
buffer_flag = 0;
warnings++;
- va_start (argp, nocmsgid);
error_print (_("Warning:"), _(nocmsgid), argp);
- va_end (argp);
- error_char ('\0');
buffer_flag = i;
}
@@ -574,9 +562,20 @@ gfc_warning_check (void)
}
}
-
/* Issue an error. */
+static void
+_gfc_error (const char *nocmsgid, va_list argp)
+{
+ error_buffer.flag = 1;
+ error_buffer.index = 0;
+ cur_error_buffer = &error_buffer;
+
+ if (buffer_flag == 0)
+ errors++;
+ error_print (_("Error:"), _(nocmsgid), argp);
+}
+
void
gfc_error (const char *nocmsgid, ...)
{
@@ -585,26 +584,18 @@ gfc_error (const char *nocmsgid, ...)
if (gfc_suppress_error)
return;
- error_buffer.flag = 1;
- error_buffer.index = 0;
- cur_error_buffer = &error_buffer;
-
va_start (argp, nocmsgid);
- if (buffer_flag == 0)
- errors++;
- error_print (_("Error:"), _(nocmsgid), argp);
+ _gfc_error(nocmsgid, argp);
va_end (argp);
error_char ('\0');
}
-
/* Immediate error. */
-void
-gfc_error_now (const char *nocmsgid, ...)
+static void
+_gfc_error_now (const char *nocmsgid, va_list argp)
{
- va_list argp;
int i;
error_buffer.flag = 1;
@@ -615,18 +606,27 @@ gfc_error_now (const char *nocmsgid, ...
buffer_flag = 0;
errors++;
- va_start (argp, nocmsgid);
error_print (_("Error:"), _(nocmsgid), argp);
+
+ buffer_flag = i;
+
+}
+
+void
+gfc_error_now (const char *nocmsgid, ...)
+{
+ va_list argp;
+
+ va_start (argp, nocmsgid);
+ _gfc_error_now(nocmsgid, argp);
va_end (argp);
error_char ('\0');
- buffer_flag = i;
if (flag_fatal_errors)
exit (1);
}
-
/* Fatal error, never returns. */
void
@@ -773,3 +773,47 @@ gfc_get_errors (int *w, int *e)
if (e != NULL)
*e = errors;
}
+
+/* Wrapper to turn warnings into errors if -Werror was given. */
+
+void
+gfc_warning (const char *nocmsgid, ...)
+{
+ va_list argp;
+
+ va_start (argp, nocmsgid);
+ if (warnings_are_errors)
+ {
+ _gfc_error(nocmsgid, argp);
+ }
+ else
+ {
+ if (!inhibit_warnings)
+ _gfc_warning(nocmsgid, argp);
+ }
+ va_end (argp);
+
+ error_char ('\0');
+}
+
+void
+gfc_warning_now (const char *nocmsgid, ...)
+{
+ va_list argp;
+
+ va_start (argp, nocmsgid);
+ if (warnings_are_errors)
+ {
+ _gfc_error_now(nocmsgid, argp);
+ }
+ else
+ {
+ if (!inhibit_warnings)
+ _gfc_warning_now(nocmsgid, argp);
+ }
+ va_end (argp);
+
+ error_char ('\0');
+}
+
+
diff -X excl -rduNp gcc.oorig/gcc/fortran/trans-decl.c gcc/gcc/fortran/trans-decl.c
--- gcc.oorig/gcc/fortran/trans-decl.c 2005-11-21 18:51:30.000000000 +0100
+++ gcc/gcc/fortran/trans-decl.c 2005-11-26 15:48:05.000000000 +0100
@@ -2452,13 +2452,15 @@ generate_local_decl (gfc_symbol * sym)
{
if (sym->attr.referenced)
gfc_get_symbol_decl (sym);
- else if (sym->attr.dummy && warn_unused_parameter)
- warning (0, "unused parameter %qs", sym->name);
+ else if (warn_unused_parameter && sym->attr.dummy)
+ gfc_warning ("unused parameter \"%s\" at %L", sym->name,
+ &sym->declared_at);
/* Warn for unused variables, but not if they're inside a common
block or are use-associated. */
else if (warn_unused_variable
&& !(sym->attr.in_common || sym->attr.use_assoc))
- warning (0, "unused variable %qs", sym->name);
+ gfc_warning ("unused variable \"%s\" at %L", sym->name,
+ &sym->declared_at);
}
}
@@ -2645,7 +2647,7 @@ gfc_generate_function_code (gfc_namespac
result = sym->result->backend_decl;
if (result == NULL_TREE)
- warning (0, "Function return value not set");
+ gfc_warning ("Function return value not set at %L", &sym->declared_at);
else
{
/* Set the return value to the dummy result variable. */
More information about the Fortran
mailing list