This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
diagnostic.c cleanup, 2 of 3
- From: Zack Weinberg <zack at codesourcery dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 11 May 2003 15:07:51 -0700
- Subject: diagnostic.c cleanup, 2 of 3
This is part two of what is now slated to be a three-part series of
cleanups to diagnostic.c. This part moves code around so that the
layer boundary between the 'simple' diagnostic routines (like "error")
and the 'primitive' diagnostic routines (like "report_diagnostic") is
consistent throughout the compiler.
On a high level, the problem was that
internal_error ("the greeble is frotzed");
would print the "Please submit a bug report" message and call exit,
but
diagnostic_set_info (&d, "the greeble is frotzed", &ap,
input_file, input_line, DK_ICE);
report_diagnostic (&d);
wouldn't. There were a number of other problems along the same lines.
For instance, there was no consistent rule about when gettext got
called.
I had to change the Fortran and ObjC front ends, which were calling
diagnostic_count_diagnostic directly. As far as I could tell, they
shouldn't have been doing that in the first place.
A question, was abort_on_error (-dH) *meant* to cause a core dump on a
plain old error? This patch changes it to apply only to ICEs and
fatal errors. I'll change it back if the old semantics were really
intended.
i686-linux bootstrap in progress.
zw
* diagnostic.c (diagnostic_for_decl): Take a
diagnostic_context argument. Restructure to be consistent
with diagnostic_report_diagnostic.
(diagnostic_count_diagnostic): Now static. Take a
diagnostic_info argument, not just a diagnostic_t. Some code
moved here from internal_error. Move a case label for
clarity.
(diagnostic_action_after_output): New function. Code moved
here from internal_error and fatal_error. Dump core only on
DK_ICE/DK_FATAL, if requested.
(bug_report_request): New #define so that this text appears in
only one place.
(diagnostic_report_diagnostic): Update to match changes to
diagnostic_count_diagnostic. Call diagnostic_action_after_output.
(diagnostic_set_info): Call gettext here.
(pedwarn): Update comment. Don't call gettext here.
(sorry): Use report_diagnostic. Don't call gettext here.
(fatal_error): Remove final fnotice and exit, but call
real_abort to prevent warnings about noreturn function returning.
(internal_error): Likewise. Don't do ICE suppression here nor
call context->internal_error.
(warning_with_decl): Suppress for decls in system headers.
Adjust call to diagnostic_for_decl.
(pedwarn_with_decl): Likewise.
(error_with_decl): Adjust call to diagnostic_for_decl.
(error_recursion): Use bug_report_request.
* diagnostic.h: Remove prototype of diagnostic_count_diagnostic.
f:
* bad.c: Don't call diagnostic_count_diagnostic.
objc:
* objc-act.c (error_with_ivar, warn_with_method): Don't call
diagnostic_count_diagnostic.
===================================================================
Index: diagnostic.c
--- diagnostic.c 11 May 2003 02:06:12 -0000 1.111
+++ diagnostic.c 11 May 2003 21:53:43 -0000
@@ -54,7 +54,8 @@ static void output_indent PARAMS ((outpu
static char *build_message_string PARAMS ((const char *, ...))
ATTRIBUTE_PRINTF_1;
static void format_with_decl PARAMS ((output_buffer *, text_info *, tree));
-static void diagnostic_for_decl PARAMS ((diagnostic_info *, tree));
+static void diagnostic_for_decl PARAMS ((diagnostic_context *,
+ diagnostic_info *, tree));
static void set_real_maximum_length PARAMS ((output_buffer *));
static void output_unsigned_decimal PARAMS ((output_buffer *, unsigned int));
@@ -79,6 +80,10 @@ static void default_diagnostic_finalizer
static void error_recursion PARAMS ((diagnostic_context *)) ATTRIBUTE_NORETURN;
static bool text_specifies_location PARAMS ((text_info *, location_t *));
+static bool diagnostic_count_diagnostic PARAMS ((diagnostic_context *,
+ diagnostic_info *));
+static void diagnostic_action_after_output PARAMS ((diagnostic_context *,
+ diagnostic_info *));
static void real_abort PARAMS ((void)) ATTRIBUTE_NORETURN;
extern int rtl_dump_and_exit;
@@ -88,6 +93,12 @@ extern int warnings_are_errors;
static diagnostic_context global_diagnostic_context;
diagnostic_context *global_dc = &global_diagnostic_context;
+/* Boilerplate text used in two locations. */
+#define bug_report_request \
+"Please submit a full bug report,\n\
+with preprocessed source if appropriate.\n\
+See %s for instructions.\n"
+
/* Subroutine of output_set_maximum_length. Set up BUFFER's
internal maximum characters per line. */
@@ -805,7 +816,7 @@ diagnostic_set_info (diagnostic, msgid,
int line;
diagnostic_t kind;
{
- diagnostic->message.format_spec = msgid;
+ diagnostic->message.format_spec = _(msgid);
diagnostic->message.args_ptr = args;
/* If the diagnostic message doesn't specify a location,
use FILE and LINE. */
@@ -850,18 +861,38 @@ diagnostic_flush_buffer (context)
}
/* Count a diagnostic. Return true if the message should be printed. */
-bool
-diagnostic_count_diagnostic (context, kind)
+static bool
+diagnostic_count_diagnostic (context, diagnostic)
diagnostic_context *context;
- diagnostic_t kind;
+ diagnostic_info *diagnostic;
{
+ diagnostic_t kind = diagnostic->kind;
switch (kind)
{
default:
abort();
break;
- case DK_FATAL: case DK_ICE: case DK_SORRY:
+ case DK_ICE:
+#ifndef ENABLE_CHECKING
+ /* When not checking, ICEs are converted to fatal errors when an
+ error has already occurred. This is counteracted by
+ abort_on_error. */
+ if ((diagnostic_kind_count (context, DK_ERROR) > 0
+ || diagnostic_kind_count (context, DK_SORRY) > 0)
+ && !context->abort_on_error)
+ {
+ fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
+ diagnostic->location.file, diagnostic->location.line);
+ exit (FATAL_EXIT_CODE);
+ }
+#endif
+ if (context->internal_error)
+ (*context->internal_error) (diagnostic->message.format_spec,
+ diagnostic->message.args_ptr);
+ /* fall through */
+
+ case DK_FATAL: case DK_SORRY:
case DK_ANACHRONISM: case DK_NOTE:
++diagnostic_kind_count (context, kind);
break;
@@ -869,20 +900,22 @@ diagnostic_count_diagnostic (context, ki
case DK_WARNING:
if (!diagnostic_report_warnings_p ())
return false;
- else if (!warnings_are_errors)
+
+ if (!warnings_are_errors)
{
++diagnostic_kind_count (context, DK_WARNING);
break;
}
- /* else fall through. */
- case DK_ERROR:
- if (kind == DK_WARNING && context->warnings_are_errors_message)
+ if (context->warnings_are_errors_message)
{
output_verbatim (&context->buffer,
"%s: warnings being treated as errors\n", progname);
context->warnings_are_errors_message = false;
}
+
+ /* and fall through */
+ case DK_ERROR:
++diagnostic_kind_count (context, DK_ERROR);
break;
}
@@ -890,6 +923,27 @@ diagnostic_count_diagnostic (context, ki
return true;
}
+/* Take any action which is expected to happen after the diagnostic
+ is written out. This function does not always return. */
+static void
+diagnostic_action_after_output (context, diagnostic)
+ diagnostic_context *context;
+ diagnostic_info *diagnostic;
+{
+ if (diagnostic->kind != DK_ICE && diagnostic->kind != DK_FATAL)
+ return;
+
+ if (context->abort_on_error)
+ real_abort ();
+
+ if (diagnostic->kind == DK_FATAL)
+ fnotice (stderr, "compilation terminated.\n");
+ else
+ fnotice (stderr, bug_report_request, bug_report_url);
+
+ exit (FATAL_EXIT_CODE);
+}
+
/* Called when the start of a function definition is parsed,
this function prints on stderr the name of the function. */
void
@@ -1016,40 +1070,40 @@ diagnostic_report_diagnostic (context, d
if (context->lock++)
error_recursion (context);
- if (diagnostic_count_diagnostic (context, diagnostic->kind))
+ if (diagnostic_count_diagnostic (context, diagnostic))
{
(*diagnostic_starter (context)) (context, diagnostic);
output_format (&context->buffer, &diagnostic->message);
(*diagnostic_finalizer (context)) (context, diagnostic);
output_flush (&context->buffer);
+ diagnostic_action_after_output (context, diagnostic);
}
- if (context->abort_on_error && diagnostic->kind <= DK_ERROR)
- real_abort();
- --context->lock;
+ context->lock--;
}
/* Report a diagnostic MESSAGE at the declaration DECL.
MSG is a format string which uses %s to substitute the declaration
name; subsequent substitutions are a la output_format. */
static void
-diagnostic_for_decl (diagnostic, decl)
+diagnostic_for_decl (context, diagnostic, decl)
+ diagnostic_context *context;
diagnostic_info *diagnostic;
tree decl;
{
- if (global_dc->lock++)
- error_recursion (global_dc);
+ if (context->lock++)
+ error_recursion (context);
- if (diagnostic_count_diagnostic (global_dc, diagnostic->kind))
+ if (diagnostic_count_diagnostic (context, diagnostic))
{
- diagnostic_report_current_function (global_dc);
- output_set_prefix
- (&global_dc->buffer, diagnostic_build_prefix (diagnostic));
- format_with_decl (&global_dc->buffer, &diagnostic->message, decl);
- output_flush (&global_dc->buffer);
- output_destroy_prefix (&global_dc->buffer);
+ (*diagnostic_starter (context)) (context, diagnostic);
+ format_with_decl (&context->buffer, &diagnostic->message, decl);
+ (*diagnostic_finalizer (context)) (context, diagnostic);
+ output_flush (&context->buffer);
+ diagnostic_action_after_output (context, diagnostic);
}
- global_dc->lock--;
+
+ context->lock--;
}
/* Given a partial pathname as input, return another pathname that
@@ -1148,15 +1202,14 @@ warning VPARAMS ((const char *msgid, ...
VA_CLOSE (ap);
}
-/* A "pedantic" warning. Use this for code which triggers a
- diagnostic which is required by the relevant language
- specification, but which is considered unhelpful (i.e. there isn't
- anything *really* wrong with the construct in the language as she
- is spoke). It is a normal warning unless -pedantic-errors is
- applied, which turns it into an error. Note that pedwarn-s still
- happen if -pedantic is not given; you must write
- "if (pedantic) pedwarn (...)" to get a warning enabled only under
- -pedantic. All such warnings should, however, use pedwarn. */
+/* A "pedantic" warning: issues a warning unless -pedantic-errors was
+ given on the command line, in which case it issues an error. Use
+ this for diagnostics required by the relevant language standard,
+ if you have chosen not to make them errors.
+
+ Note that these diagnostics are issued independent of the setting
+ of the -pedantic command-line switch. To get a warning enabled
+ only with that switch, write "if (pedantic) pedwarn (...);" */
void
pedwarn VPARAMS ((const char *msgid, ...))
{
@@ -1164,7 +1217,7 @@ pedwarn VPARAMS ((const char *msgid, ...
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, const char *, msgid);
- diagnostic_set_info (&diagnostic, _(msgid), &ap, input_filename, input_line,
+ diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
pedantic_error_kind ());
report_diagnostic (&diagnostic);
VA_CLOSE (ap);
@@ -1197,14 +1250,9 @@ sorry VPARAMS ((const char *msgid, ...))
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, const char *, msgid);
- ++sorrycount;
- diagnostic_set_info (&diagnostic, _(msgid), &ap,
- input_filename, input_line, DK_SORRY);
-
- output_set_prefix
- (&global_dc->buffer, diagnostic_build_prefix (&diagnostic));
- output_format (&global_dc->buffer, &diagnostic.message);
- output_flush (&global_dc->buffer);
+ diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
+ DK_SORRY);
+ report_diagnostic (&diagnostic);
VA_CLOSE (ap);
}
@@ -1224,8 +1272,8 @@ fatal_error VPARAMS ((const char *msgid,
report_diagnostic (&diagnostic);
VA_CLOSE (ap);
- fnotice (stderr, "compilation terminated.\n");
- exit (FATAL_EXIT_CODE);
+ /* NOTREACHED */
+ real_abort ();
}
/* An internal consistency check has failed. We make no attempt to
@@ -1240,31 +1288,13 @@ internal_error VPARAMS ((const char *msg
VA_OPEN (ap, msgid);
VA_FIXEDARG (ap, const char *, msgid);
- if (global_dc->lock)
- error_recursion (global_dc);
-
-#ifndef ENABLE_CHECKING
- if (errorcount > 0 || sorrycount > 0)
- {
- fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
- input_filename, input_line);
- exit (FATAL_EXIT_CODE);
- }
-#endif
-
- if (global_dc->internal_error != 0)
- (*global_dc->internal_error) (_(msgid), &ap);
-
diagnostic_set_info (&diagnostic, msgid, &ap, input_filename, input_line,
DK_ICE);
report_diagnostic (&diagnostic);
VA_CLOSE (ap);
- fnotice (stderr,
-"Please submit a full bug report,\n\
-with preprocessed source if appropriate.\n\
-See %s for instructions.\n", bug_report_url);
- exit (FATAL_EXIT_CODE);
+ /* NOTREACHED */
+ real_abort ();
}
/* Variants of some of the above, which make reference to a particular
@@ -1278,10 +1308,15 @@ warning_with_decl VPARAMS ((tree decl, c
VA_FIXEDARG (ap, tree, decl);
VA_FIXEDARG (ap, const char *, msgid);
+ /* Do not issue a warning about a decl which came from a system header,
+ unless -Wsystem-headers. */
+ if (DECL_IN_SYSTEM_HEADER (decl) && !warn_system_headers)
+ return;
+
diagnostic_set_info (&diagnostic, msgid, &ap,
DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
DK_WARNING);
- diagnostic_for_decl (&diagnostic, decl);
+ diagnostic_for_decl (global_dc, &diagnostic, decl);
VA_CLOSE (ap);
}
@@ -1293,18 +1328,16 @@ pedwarn_with_decl VPARAMS ((tree decl, c
VA_FIXEDARG (ap, tree, decl);
VA_FIXEDARG (ap, const char *, msgid);
- diagnostic_set_info (&diagnostic, _(msgid), &ap,
+ /* Do not issue a warning about a decl which came from a system header,
+ unless -Wsystem-headers. */
+ if (DECL_IN_SYSTEM_HEADER (decl) && !warn_system_headers)
+ return;
+
+ diagnostic_set_info (&diagnostic, msgid, &ap,
DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
pedantic_error_kind ());
+ diagnostic_for_decl (global_dc, &diagnostic, decl);
- /* We don't want -pedantic-errors to cause the compilation to fail from
- "errors" in system header files. Sometimes fixincludes can't fix what's
- broken (eg: unsigned char bitfields - fixing it may change the alignment
- which will cause programs to mysteriously fail because the C library
- or kernel uses the original layout). There's no point in issuing a
- warning either, it's just unnecessary noise. */
- if (!DECL_IN_SYSTEM_HEADER (decl))
- diagnostic_for_decl (&diagnostic, decl);
VA_CLOSE (ap);
}
@@ -1319,7 +1352,7 @@ error_with_decl VPARAMS ((tree decl, con
diagnostic_set_info (&diagnostic, msgid, &ap,
DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl),
DK_ERROR);
- diagnostic_for_decl (&diagnostic, decl);
+ diagnostic_for_decl (global_dc, &diagnostic, decl);
VA_CLOSE (ap);
}
@@ -1410,10 +1443,7 @@ error_recursion (context)
fnotice (stderr,
"Internal compiler error: Error reporting routines re-entered.\n");
- fnotice (stderr,
-"Please submit a full bug report,\n\
-with preprocessed source if appropriate.\n\
-See %s for instructions.\n", bug_report_url);
+ fnotice (stderr, bug_report_request, bug_report_url);
exit (FATAL_EXIT_CODE);
}
===================================================================
Index: diagnostic.h
--- diagnostic.h 2 May 2003 11:33:02 -0000 1.54
+++ diagnostic.h 11 May 2003 21:53:43 -0000
@@ -294,8 +294,6 @@ extern void diagnostic_initialize PARAMS
extern void diagnostic_report_current_module PARAMS ((diagnostic_context *));
extern void diagnostic_report_current_function PARAMS ((diagnostic_context *));
extern void diagnostic_flush_buffer PARAMS ((diagnostic_context *));
-extern bool diagnostic_count_diagnostic PARAMS ((diagnostic_context *,
- diagnostic_t));
extern void diagnostic_report_diagnostic PARAMS ((diagnostic_context *,
diagnostic_info *));
extern void diagnostic_set_info PARAMS ((diagnostic_info *,
===================================================================
Index: f/bad.c
--- f/bad.c 11 Jun 2002 23:11:34 -0000 1.19
+++ f/bad.c 11 May 2003 21:53:44 -0000
@@ -203,11 +203,12 @@ ffebad_start_ (bool lex_override, ffebad
if ((ffebad_severity_ != FFEBAD_severityPEDANTIC)
|| !flag_pedantic_errors)
{
- if (!diagnostic_count_diagnostic (global_dc, DK_WARNING))
+ if (!diagnostic_report_warnings_p ())
{ /* User wants no warnings. */
ffebad_is_temp_inhibited_ = TRUE;
return FALSE;
}
+ diagnostic_kind_count (global_dc, DK_WARNING)++;
break;
}
/* Fall through (PEDANTIC && flag_pedantic_errors). */
@@ -215,7 +216,7 @@ ffebad_start_ (bool lex_override, ffebad
case FFEBAD_severityWEIRD:
case FFEBAD_severitySEVERE:
case FFEBAD_severityDISASTER:
- diagnostic_count_diagnostic (global_dc, DK_ERROR);
+ diagnostic_kind_count (global_dc, DK_ERROR)++;
break;
default:
===================================================================
Index: objc/objc-act.c
--- objc/objc-act.c 8 May 2003 17:32:30 -0000 1.172
+++ objc/objc-act.c 11 May 2003 21:53:46 -0000
@@ -3539,10 +3539,6 @@ error_with_ivar (message, decl, rawdecl)
tree decl;
tree rawdecl;
{
- diagnostic_count_diagnostic (global_dc, DK_ERROR);
-
- diagnostic_report_current_function (global_dc);
-
error ("%H%s `%s'", &DECL_SOURCE_LOCATION (decl),
message, gen_declaration (rawdecl, errbuf));
@@ -7108,11 +7104,6 @@ warn_with_method (message, mtype, method
int mtype;
tree method;
{
- if (!diagnostic_count_diagnostic (global_dc, DK_WARNING))
- return;
-
- diagnostic_report_current_function (global_dc);
-
/* Add a readable method name to the warning. */
warning ("%H%s `%c%s'", &DECL_SOURCE_LOCATION (method),
message, mtype, gen_method_decl (method, errbuf));