1117395Skan/* Language-independent diagnostic subroutines for the GNU Compiler Collection
2169689Skan   Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006
3169689Skan   Free Software Foundation, Inc.
490075Sobrien   Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
590075Sobrien
690075SobrienThis file is part of GCC.
790075Sobrien
890075SobrienGCC is free software; you can redistribute it and/or modify it under
990075Sobrienthe terms of the GNU General Public License as published by the Free
1090075SobrienSoftware Foundation; either version 2, or (at your option) any later
1190075Sobrienversion.
1290075Sobrien
1390075SobrienGCC is distributed in the hope that it will be useful, but WITHOUT ANY
1490075SobrienWARRANTY; without even the implied warranty of MERCHANTABILITY or
1590075SobrienFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1690075Sobrienfor more details.
1790075Sobrien
1890075SobrienYou should have received a copy of the GNU General Public License
1990075Sobrienalong with GCC; see the file COPYING.  If not, write to the Free
20169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21169689Skan02110-1301, USA.  */
2290075Sobrien
2390075Sobrien
2490075Sobrien/* This file implements the language independent aspect of diagnostic
2590075Sobrien   message module.  */
2690075Sobrien
2790075Sobrien#include "config.h"
2890075Sobrien#undef FLOAT /* This is for hpux. They should change hpux.  */
2990075Sobrien#undef FFS  /* Some systems define this in param.h.  */
3090075Sobrien#include "system.h"
31132718Skan#include "coretypes.h"
32132718Skan#include "tm.h"
3390075Sobrien#include "tree.h"
34169689Skan#include "version.h"
3590075Sobrien#include "tm_p.h"
3690075Sobrien#include "flags.h"
3790075Sobrien#include "input.h"
3890075Sobrien#include "toplev.h"
3990075Sobrien#include "intl.h"
4090075Sobrien#include "diagnostic.h"
41117395Skan#include "langhooks.h"
42117395Skan#include "langhooks-def.h"
43169689Skan#include "opts.h"
4490075Sobrien
4590075Sobrien
4690075Sobrien/* Prototypes.  */
47132718Skanstatic char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
4890075Sobrien
49132718Skanstatic void default_diagnostic_starter (diagnostic_context *,
50132718Skan					diagnostic_info *);
51132718Skanstatic void default_diagnostic_finalizer (diagnostic_context *,
52132718Skan					  diagnostic_info *);
5390075Sobrien
54132718Skanstatic void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
55132718Skanstatic bool diagnostic_count_diagnostic (diagnostic_context *,
56132718Skan					 diagnostic_info *);
57132718Skanstatic void diagnostic_action_after_output (diagnostic_context *,
58132718Skan					    diagnostic_info *);
59132718Skanstatic void real_abort (void) ATTRIBUTE_NORETURN;
6090075Sobrien
6190075Sobrien/* A diagnostic_context surrogate for stderr.  */
6290075Sobrienstatic diagnostic_context global_diagnostic_context;
6390075Sobriendiagnostic_context *global_dc = &global_diagnostic_context;
6490075Sobrien
6590075Sobrien
66132718Skan/* Return a malloc'd string containing MSG formatted a la printf.  The
67132718Skan   caller is responsible for freeing the memory.  */
6890075Sobrienstatic char *
69132718Skanbuild_message_string (const char *msg, ...)
7090075Sobrien{
7190075Sobrien  char *str;
72132718Skan  va_list ap;
7390075Sobrien
74132718Skan  va_start (ap, msg);
7590075Sobrien  vasprintf (&str, msg, ap);
76132718Skan  va_end (ap);
7790075Sobrien
7890075Sobrien  return str;
7990075Sobrien}
8090075Sobrien
81132718Skan/* Same as diagnostic_build_prefix, but only the source FILE is given.  */
8290075Sobrienchar *
83132718Skanfile_name_as_prefix (const char *f)
8490075Sobrien{
8590075Sobrien  return build_message_string ("%s: ", f);
8690075Sobrien}
8790075Sobrien
8890075Sobrien
89117395Skan
90117395Skan/* Initialize the diagnostic message outputting machinery.  */
91117395Skanvoid
92132718Skandiagnostic_initialize (diagnostic_context *context)
93117395Skan{
94132718Skan  /* Allocate a basic pretty-printer.  Clients will replace this a
95132718Skan     much more elaborated pretty-printer if they wish.  */
96169689Skan  context->printer = XNEW (pretty_printer);
97132718Skan  pp_construct (context->printer, NULL, 0);
98117395Skan  /* By default, diagnostics are sent to stderr.  */
99132718Skan  context->printer->buffer->stream = stderr;
100117395Skan  /* By default, we emit prefixes once per message.  */
101169689Skan  context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
102117395Skan
103132718Skan  memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
104169689Skan  context->issue_warnings_are_errors_message = true;
105169689Skan  context->warning_as_error_requested = false;
106169689Skan  memset (context->classify_diagnostic, DK_UNSPECIFIED,
107169689Skan	  sizeof context->classify_diagnostic);
108169689Skan  context->show_option_requested = false;
109132718Skan  context->abort_on_error = false;
110132718Skan  context->internal_error = NULL;
111117395Skan  diagnostic_starter (context) = default_diagnostic_starter;
112117395Skan  diagnostic_finalizer (context) = default_diagnostic_finalizer;
113132718Skan  context->last_module = 0;
114132718Skan  context->last_function = NULL;
115132718Skan  context->lock = 0;
116117395Skan}
117117395Skan
118169689Skan/* Initialize DIAGNOSTIC, where the message MSG has already been
119169689Skan   translated.  */
120169689Skanvoid
121169689Skandiagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
122169689Skan				va_list *args, location_t location,
123169689Skan				diagnostic_t kind)
124117395Skan{
125169689Skan  diagnostic->message.err_no = errno;
126169689Skan  diagnostic->message.args_ptr = args;
127169689Skan  diagnostic->message.format_spec = msg;
128169689Skan  diagnostic->location = location;
129169689Skan  diagnostic->kind = kind;
130169689Skan  diagnostic->option_index = 0;
131117395Skan}
132117395Skan
133169689Skan/* Initialize DIAGNOSTIC, where the message GMSGID has not yet been
134169689Skan   translated.  */
135117395Skanvoid
136169689Skandiagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid,
137132718Skan		     va_list *args, location_t location,
138132718Skan		     diagnostic_t kind)
139117395Skan{
140169689Skan  diagnostic_set_info_translated (diagnostic, _(gmsgid), args, location, kind);
141117395Skan}
142117395Skan
143117395Skan/* Return a malloc'd string describing a location.  The caller is
144117395Skan   responsible for freeing the memory.  */
145117395Skanchar *
146132718Skandiagnostic_build_prefix (diagnostic_info *diagnostic)
147117395Skan{
148117395Skan  static const char *const diagnostic_kind_text[] = {
149117395Skan#define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
150117395Skan#include "diagnostic.def"
151117395Skan#undef DEFINE_DIAGNOSTIC_KIND
152117395Skan    "must-not-happen"
153117395Skan  };
154169689Skan  const char *text = _(diagnostic_kind_text[diagnostic->kind]);
155169689Skan  expanded_location s = expand_location (diagnostic->location);
156169689Skan  gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
157117395Skan
158169689Skan  return
159169689Skan    (s.file == NULL
160169689Skan     ? build_message_string ("%s: %s", progname, text)
161169689Skan#ifdef USE_MAPPED_LOCATION
162169689Skan     : flag_show_column && s.column != 0
163169689Skan     ? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text)
164169689Skan#endif
165169689Skan     : build_message_string ("%s:%d: %s", s.file, s.line, text));
166117395Skan}
167117395Skan
168117395Skan/* Count a diagnostic.  Return true if the message should be printed.  */
169132718Skanstatic bool
170132718Skandiagnostic_count_diagnostic (diagnostic_context *context,
171132718Skan			     diagnostic_info *diagnostic)
17290075Sobrien{
173132718Skan  diagnostic_t kind = diagnostic->kind;
174117395Skan  switch (kind)
17590075Sobrien    {
176117395Skan    default:
177169689Skan      gcc_unreachable ();
17890075Sobrien
179132718Skan    case DK_ICE:
180132718Skan#ifndef ENABLE_CHECKING
181132718Skan      /* When not checking, ICEs are converted to fatal errors when an
182132718Skan	 error has already occurred.  This is counteracted by
183132718Skan	 abort_on_error.  */
184132718Skan      if ((diagnostic_kind_count (context, DK_ERROR) > 0
185132718Skan	   || diagnostic_kind_count (context, DK_SORRY) > 0)
186132718Skan	  && !context->abort_on_error)
187132718Skan	{
188169689Skan	  expanded_location s = expand_location (diagnostic->location);
189132718Skan	  fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
190169689Skan		   s.file, s.line);
191169689Skan	  exit (ICE_EXIT_CODE);
192132718Skan	}
193132718Skan#endif
194132718Skan      if (context->internal_error)
195132718Skan	(*context->internal_error) (diagnostic->message.format_spec,
196132718Skan				    diagnostic->message.args_ptr);
197132718Skan      /* Fall through.  */
198132718Skan
199132718Skan    case DK_FATAL: case DK_SORRY:
200117395Skan    case DK_ANACHRONISM: case DK_NOTE:
201117395Skan      ++diagnostic_kind_count (context, kind);
202117395Skan      break;
203117395Skan
204117395Skan    case DK_WARNING:
205117395Skan      if (!diagnostic_report_warnings_p ())
206117395Skan        return false;
207132718Skan
208169689Skan      /* -Werror can reclassify warnings as errors, but
209169689Skan	 classify_diagnostic can reclassify it back to a warning.  The
210169689Skan	 second part of this test detects that case.  */
211169689Skan      if (!context->warning_as_error_requested
212169689Skan	  || (context->classify_diagnostic[diagnostic->option_index]
213169689Skan	      == DK_WARNING))
214117395Skan        {
215117395Skan          ++diagnostic_kind_count (context, DK_WARNING);
216117395Skan          break;
217117395Skan        }
218169689Skan      else if (context->issue_warnings_are_errors_message)
219117395Skan        {
220132718Skan	  pp_verbatim (context->printer,
221132718Skan                       "%s: warnings being treated as errors\n", progname);
222169689Skan          context->issue_warnings_are_errors_message = false;
223117395Skan        }
224132718Skan
225132718Skan      /* And fall through.  */
226132718Skan    case DK_ERROR:
227117395Skan      ++diagnostic_kind_count (context, DK_ERROR);
228117395Skan      break;
22990075Sobrien    }
23090075Sobrien
231117395Skan  return true;
23290075Sobrien}
23390075Sobrien
234132718Skan/* Take any action which is expected to happen after the diagnostic
235132718Skan   is written out.  This function does not always return.  */
236132718Skanstatic void
237132718Skandiagnostic_action_after_output (diagnostic_context *context,
238132718Skan				diagnostic_info *diagnostic)
23990075Sobrien{
240132718Skan  switch (diagnostic->kind)
241132718Skan    {
242132718Skan    case DK_DEBUG:
243132718Skan    case DK_NOTE:
244132718Skan    case DK_ANACHRONISM:
245132718Skan    case DK_WARNING:
246132718Skan      break;
24790075Sobrien
248132718Skan    case DK_ERROR:
249132718Skan    case DK_SORRY:
250132718Skan      if (context->abort_on_error)
251132718Skan	real_abort ();
252169689Skan      if (flag_fatal_errors)
253169689Skan	{
254169689Skan	  fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
255169689Skan	  exit (FATAL_EXIT_CODE);
256169689Skan	}
257132718Skan      break;
25890075Sobrien
259132718Skan    case DK_ICE:
260132718Skan      if (context->abort_on_error)
261132718Skan	real_abort ();
26290075Sobrien
263169689Skan      fnotice (stderr, "Please submit a full bug report,\n"
264169689Skan	       "with preprocessed source if appropriate.\n"
265169689Skan	       "See %s for instructions.\n", bug_report_url);
266169689Skan      exit (ICE_EXIT_CODE);
26790075Sobrien
268132718Skan    case DK_FATAL:
269132718Skan      if (context->abort_on_error)
270132718Skan	real_abort ();
27190075Sobrien
272132718Skan      fnotice (stderr, "compilation terminated.\n");
273132718Skan      exit (FATAL_EXIT_CODE);
27490075Sobrien
275132718Skan    default:
276169689Skan      gcc_unreachable ();
27790075Sobrien    }
27890075Sobrien}
27990075Sobrien
28090075Sobrien/* Prints out, if necessary, the name of the current function
281169689Skan   that caused an error.  Called from all error and warning functions.  */
28290075Sobrienvoid
283132718Skandiagnostic_report_current_function (diagnostic_context *context)
28490075Sobrien{
285117395Skan  diagnostic_report_current_module (context);
286169689Skan  lang_hooks.print_error_function (context, input_filename);
28790075Sobrien}
28890075Sobrien
28990075Sobrienvoid
290132718Skandiagnostic_report_current_module (diagnostic_context *context)
29190075Sobrien{
292132718Skan  struct file_stack *p;
29390075Sobrien
294132718Skan  if (pp_needs_newline (context->printer))
295132718Skan    {
296132718Skan      pp_newline (context->printer);
297132718Skan      pp_needs_newline (context->printer) = false;
298132718Skan    }
29990075Sobrien
300169689Skan  p = input_file_stack;
301169689Skan  if (p && diagnostic_last_module_changed (context))
30290075Sobrien    {
303169689Skan      expanded_location xloc = expand_location (p->location);
304132718Skan      pp_verbatim (context->printer,
305132718Skan                   "In file included from %s:%d",
306169689Skan		   xloc.file, xloc.line);
307132718Skan      while ((p = p->next) != NULL)
308169689Skan	{
309169689Skan	  xloc = expand_location (p->location);
310169689Skan	  pp_verbatim (context->printer,
311169689Skan		       ",\n                 from %s:%d",
312169689Skan		       xloc.file, xloc.line);
313169689Skan	}
314169689Skan      pp_verbatim (context->printer, ":");
315132718Skan      diagnostic_set_last_module (context);
316169689Skan      pp_newline (context->printer);
31790075Sobrien    }
31890075Sobrien}
31990075Sobrien
320132718Skanstatic void
321132718Skandefault_diagnostic_starter (diagnostic_context *context,
322132718Skan			    diagnostic_info *diagnostic)
32390075Sobrien{
324132718Skan  diagnostic_report_current_function (context);
325132718Skan  pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
32690075Sobrien}
32790075Sobrien
328132718Skanstatic void
329132718Skandefault_diagnostic_finalizer (diagnostic_context *context,
330169689Skan			      diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
33190075Sobrien{
332132718Skan  pp_destroy_prefix (context->printer);
33390075Sobrien}
33490075Sobrien
335169689Skan/* Interface to specify diagnostic kind overrides.  Returns the
336169689Skan   previous setting, or DK_UNSPECIFIED if the parameters are out of
337169689Skan   range.  */
338169689Skandiagnostic_t
339169689Skandiagnostic_classify_diagnostic (diagnostic_context *context,
340169689Skan				int option_index,
341169689Skan				diagnostic_t new_kind)
342169689Skan{
343169689Skan  diagnostic_t old_kind;
344169689Skan
345169689Skan  if (option_index <= 0
346169689Skan      || option_index >= N_OPTS
347169689Skan      || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
348169689Skan    return DK_UNSPECIFIED;
349169689Skan
350169689Skan  old_kind = context->classify_diagnostic[option_index];
351169689Skan  context->classify_diagnostic[option_index] = new_kind;
352169689Skan  return old_kind;
353169689Skan}
354169689Skan
35590075Sobrien/* Report a diagnostic message (an error or a warning) as specified by
35690075Sobrien   DC.  This function is *the* subroutine in terms of which front-ends
35790075Sobrien   should implement their specific diagnostic handling modules.  The
35890075Sobrien   front-end independent format specifiers are exactly those described
35990075Sobrien   in the documentation of output_format.  */
36090075Sobrien
36190075Sobrienvoid
362132718Skandiagnostic_report_diagnostic (diagnostic_context *context,
363132718Skan			      diagnostic_info *diagnostic)
36490075Sobrien{
365169689Skan  if (context->lock > 0)
366169689Skan    {
367169689Skan      /* If we're reporting an ICE in the middle of some other error,
368169689Skan	 try to flush out the previous error, then let this one
369169689Skan	 through.  Don't do this more than once.  */
370169689Skan      if (diagnostic->kind == DK_ICE && context->lock == 1)
371169689Skan	pp_flush (context->printer);
372169689Skan      else
373169689Skan	error_recursion (context);
374169689Skan    }
37590075Sobrien
376169689Skan  if (diagnostic->option_index)
377169689Skan    {
378169689Skan      /* This tests if the user provided the appropriate -Wfoo or
379169689Skan	 -Wno-foo option.  */
380169689Skan      if (! option_enabled (diagnostic->option_index))
381169689Skan	return;
382169689Skan      /* This tests if the user provided the appropriate -Werror=foo
383169689Skan	 option.  */
384169689Skan      if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
385169689Skan	diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
386169689Skan      /* This allows for future extensions, like temporarily disabling
387169689Skan	 warnings for ranges of source code.  */
388169689Skan      if (diagnostic->kind == DK_IGNORED)
389169689Skan	return;
390169689Skan    }
391169689Skan
392169689Skan  context->lock++;
393169689Skan
394132718Skan  if (diagnostic_count_diagnostic (context, diagnostic))
39590075Sobrien    {
396169689Skan      const char *saved_format_spec = diagnostic->message.format_spec;
397169689Skan
398169689Skan      if (context->show_option_requested && diagnostic->option_index)
399169689Skan	diagnostic->message.format_spec
400169689Skan	  = ACONCAT ((diagnostic->message.format_spec,
401169689Skan		      " [", cl_options[diagnostic->option_index].opt_text, "]", NULL));
402169689Skan
403169689Skan      diagnostic->message.locus = &diagnostic->location;
404169689Skan      pp_format (context->printer, &diagnostic->message);
405117395Skan      (*diagnostic_starter (context)) (context, diagnostic);
406169689Skan      pp_output_formatted_text (context->printer);
407117395Skan      (*diagnostic_finalizer (context)) (context, diagnostic);
408132718Skan      pp_flush (context->printer);
409132718Skan      diagnostic_action_after_output (context, diagnostic);
410169689Skan      diagnostic->message.format_spec = saved_format_spec;
41190075Sobrien    }
41290075Sobrien
413132718Skan  context->lock--;
41490075Sobrien}
41590075Sobrien
41690075Sobrien/* Given a partial pathname as input, return another pathname that
41790075Sobrien   shares no directory elements with the pathname of __FILE__.  This
41890075Sobrien   is used by fancy_abort() to print `Internal compiler error in expr.c'
41990075Sobrien   instead of `Internal compiler error in ../../GCC/gcc/expr.c'.  */
42090075Sobrien
42190075Sobrienconst char *
422132718Skantrim_filename (const char *name)
42390075Sobrien{
42490075Sobrien  static const char this_file[] = __FILE__;
42590075Sobrien  const char *p = name, *q = this_file;
42690075Sobrien
42790075Sobrien  /* First skip any "../" in each filename.  This allows us to give a proper
42890075Sobrien     reference to a file in a subdirectory.  */
429169689Skan  while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2]))
43090075Sobrien    p += 3;
43190075Sobrien
432169689Skan  while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2]))
43390075Sobrien    q += 3;
43490075Sobrien
43590075Sobrien  /* Now skip any parts the two filenames have in common.  */
43690075Sobrien  while (*p == *q && *p != 0 && *q != 0)
43790075Sobrien    p++, q++;
43890075Sobrien
43990075Sobrien  /* Now go backwards until the previous directory separator.  */
440169689Skan  while (p > name && !IS_DIR_SEPARATOR (p[-1]))
44190075Sobrien    p--;
44290075Sobrien
44390075Sobrien  return p;
44490075Sobrien}
445132718Skan
446132718Skan/* Standard error reporting routines in increasing order of severity.
447132718Skan   All of these take arguments like printf.  */
44890075Sobrien
449132718Skan/* Text to be emitted verbatim to the error message stream; this
450132718Skan   produces no prefix and disables line-wrapping.  Use rarely.  */
451132718Skanvoid
452169689Skanverbatim (const char *gmsgid, ...)
453132718Skan{
454132718Skan  text_info text;
455132718Skan  va_list ap;
45690075Sobrien
457169689Skan  va_start (ap, gmsgid);
458132718Skan  text.err_no = errno;
459132718Skan  text.args_ptr = &ap;
460169689Skan  text.format_spec = _(gmsgid);
461169689Skan  text.locus = NULL;
462132718Skan  pp_format_verbatim (global_dc->printer, &text);
463132718Skan  pp_flush (global_dc->printer);
464132718Skan  va_end (ap);
465132718Skan}
466132718Skan
467132718Skan/* An informative note.  Use this for additional details on an error
468132718Skan   message.  */
46990075Sobrienvoid
470169689Skaninform (const char *gmsgid, ...)
47190075Sobrien{
472132718Skan  diagnostic_info diagnostic;
473132718Skan  va_list ap;
474132718Skan
475169689Skan  va_start (ap, gmsgid);
476169689Skan  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_NOTE);
477132718Skan  report_diagnostic (&diagnostic);
478132718Skan  va_end (ap);
47990075Sobrien}
48090075Sobrien
481132718Skan/* A warning.  Use this for code which is correct according to the
482132718Skan   relevant language specification but is likely to be buggy anyway.  */
48390075Sobrienvoid
484169689Skanwarning (int opt, const char *gmsgid, ...)
48590075Sobrien{
486132718Skan  diagnostic_info diagnostic;
487132718Skan  va_list ap;
48890075Sobrien
489169689Skan  va_start (ap, gmsgid);
490169689Skan  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING);
491169689Skan  diagnostic.option_index = opt;
492169689Skan
493132718Skan  report_diagnostic (&diagnostic);
494132718Skan  va_end (ap);
495132718Skan}
49690075Sobrien
497169689Skanvoid
498169689Skanwarning0 (const char *gmsgid, ...)
499169689Skan{
500169689Skan  diagnostic_info diagnostic;
501169689Skan  va_list ap;
502169689Skan
503169689Skan  va_start (ap, gmsgid);
504169689Skan  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING);
505169689Skan  report_diagnostic (&diagnostic);
506169689Skan  va_end (ap);
507169689Skan}
508169689Skan
509132718Skan/* A "pedantic" warning: issues a warning unless -pedantic-errors was
510132718Skan   given on the command line, in which case it issues an error.  Use
511132718Skan   this for diagnostics required by the relevant language standard,
512132718Skan   if you have chosen not to make them errors.
513132718Skan
514132718Skan   Note that these diagnostics are issued independent of the setting
515132718Skan   of the -pedantic command-line switch.  To get a warning enabled
516132718Skan   only with that switch, write "if (pedantic) pedwarn (...);"  */
517132718Skanvoid
518169689Skanpedwarn (const char *gmsgid, ...)
519132718Skan{
520132718Skan  diagnostic_info diagnostic;
521132718Skan  va_list ap;
522132718Skan
523169689Skan  va_start (ap, gmsgid);
524169689Skan  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location,
525132718Skan		       pedantic_error_kind ());
526132718Skan  report_diagnostic (&diagnostic);
527132718Skan  va_end (ap);
52890075Sobrien}
52990075Sobrien
530132718Skan/* A hard error: the code is definitely ill-formed, and an object file
531132718Skan   will not be produced.  */
532132718Skanvoid
533169689Skanerror (const char *gmsgid, ...)
53490075Sobrien{
535132718Skan  diagnostic_info diagnostic;
536132718Skan  va_list ap;
537132718Skan
538169689Skan  va_start (ap, gmsgid);
539169689Skan  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR);
540132718Skan  report_diagnostic (&diagnostic);
541132718Skan  va_end (ap);
54290075Sobrien}
54390075Sobrien
544132718Skan/* "Sorry, not implemented."  Use for a language feature which is
545132718Skan   required by the relevant specification but not implemented by GCC.
546132718Skan   An object file will not be produced.  */
547132718Skanvoid
548169689Skansorry (const char *gmsgid, ...)
54990075Sobrien{
550132718Skan  diagnostic_info diagnostic;
551132718Skan  va_list ap;
552132718Skan
553169689Skan  va_start (ap, gmsgid);
554169689Skan  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_SORRY);
555132718Skan  report_diagnostic (&diagnostic);
556132718Skan  va_end (ap);
55790075Sobrien}
55890075Sobrien
559132718Skan/* An error which is severe enough that we make no attempt to
560132718Skan   continue.  Do not use this for internal consistency checks; that's
561132718Skan   internal_error.  Use of this function should be rare.  */
562117395Skanvoid
563169689Skanfatal_error (const char *gmsgid, ...)
564117395Skan{
565117395Skan  diagnostic_info diagnostic;
566132718Skan  va_list ap;
567117395Skan
568169689Skan  va_start (ap, gmsgid);
569169689Skan  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_FATAL);
570132718Skan  report_diagnostic (&diagnostic);
571132718Skan  va_end (ap);
572117395Skan
573169689Skan  gcc_unreachable ();
574132718Skan}
575132718Skan
576132718Skan/* An internal consistency check has failed.  We make no attempt to
577132718Skan   continue.  Note that unless there is debugging value to be had from
578132718Skan   a more specific message, or some other good reason, you should use
579132718Skan   abort () instead of calling this function directly.  */
580132718Skanvoid
581169689Skaninternal_error (const char *gmsgid, ...)
582132718Skan{
583132718Skan  diagnostic_info diagnostic;
584132718Skan  va_list ap;
585132718Skan
586169689Skan  va_start (ap, gmsgid);
587169689Skan  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ICE);
588117395Skan  report_diagnostic (&diagnostic);
589132718Skan  va_end (ap);
590132718Skan
591169689Skan  gcc_unreachable ();
592117395Skan}
593132718Skan
594132718Skan/* Special case error functions.  Most are implemented in terms of the
595132718Skan   above, or should be.  */
596117395Skan
597132718Skan/* Print a diagnostic MSGID on FILE.  This is just fprintf, except it
598132718Skan   runs its second argument through gettext.  */
599117395Skanvoid
600169689Skanfnotice (FILE *file, const char *cmsgid, ...)
60190075Sobrien{
602132718Skan  va_list ap;
60390075Sobrien
604169689Skan  va_start (ap, cmsgid);
605169689Skan  vfprintf (file, _(cmsgid), ap);
606132718Skan  va_end (ap);
607132718Skan}
60890075Sobrien
609132718Skan/* Inform the user that an error occurred while trying to report some
610132718Skan   other error.  This indicates catastrophic internal inconsistencies,
611132718Skan   so give up now.  But do try to flush out the previous error.
612132718Skan   This mustn't use internal_error, that will cause infinite recursion.  */
613117395Skan
614132718Skanstatic void
615132718Skanerror_recursion (diagnostic_context *context)
616132718Skan{
617169689Skan  diagnostic_info diagnostic;
618169689Skan
619132718Skan  if (context->lock < 3)
620132718Skan    pp_flush (context->printer);
621132718Skan
622132718Skan  fnotice (stderr,
623132718Skan	   "Internal compiler error: Error reporting routines re-entered.\n");
624169689Skan
625169689Skan  /* Call diagnostic_action_after_output to get the "please submit a bug
626169689Skan     report" message.  It only looks at the kind field of diagnostic_info.  */
627169689Skan  diagnostic.kind = DK_ICE;
628169689Skan  diagnostic_action_after_output (context, &diagnostic);
629169689Skan
630169689Skan  /* Do not use gcc_unreachable here; that goes through internal_error
631169689Skan     and therefore would cause infinite recursion.  */
632169689Skan  real_abort ();
63390075Sobrien}
634132718Skan
635132718Skan/* Report an internal compiler error in a friendly manner.  This is
636132718Skan   the function that gets called upon use of abort() in the source
637132718Skan   code generally, thanks to a special macro.  */
638132718Skan
639132718Skanvoid
640132718Skanfancy_abort (const char *file, int line, const char *function)
641132718Skan{
642132718Skan  internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
643132718Skan}
644132718Skan
645132718Skan/* Really call the system 'abort'.  This has to go right at the end of
646132718Skan   this file, so that there are no functions after it that call abort
647132718Skan   and get the system abort instead of our macro.  */
648132718Skan#undef abort
649132718Skanstatic void
650132718Skanreal_abort (void)
651132718Skan{
652132718Skan  abort ();
653132718Skan}
654