OSDN Git Service

* diagnostic.c: Don't include plugin.h.
[pf3gnuchains/gcc-fork.git] / gcc / diagnostic.c
1 /* Language-independent diagnostic subroutines for the GNU Compiler Collection
2    Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3    2009, 2010 Free Software Foundation, Inc.
4    Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
5
6 This file is part of GCC.
7
8 GCC is free software; you can redistribute it and/or modify it under
9 the terms of the GNU General Public License as published by the Free
10 Software Foundation; either version 3, or (at your option) any later
11 version.
12
13 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
14 WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16 for more details.
17
18 You should have received a copy of the GNU General Public License
19 along with GCC; see the file COPYING3.  If not see
20 <http://www.gnu.org/licenses/>.  */
21
22
23 /* This file implements the language independent aspect of diagnostic
24    message module.  */
25
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "version.h"
30 #include "input.h"
31 #include "toplev.h"
32 #include "intl.h"
33 #include "diagnostic.h"
34 #include "opts.h"
35
36 #define pedantic_warning_kind(DC)                       \
37   ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
38 #define permissive_error_kind(DC) ((DC)->permissive ? DK_WARNING : DK_ERROR)
39
40 /* Prototypes.  */
41 static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
42
43 static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
44
45 static void diagnostic_action_after_output (diagnostic_context *,
46                                             diagnostic_info *);
47 static void real_abort (void) ATTRIBUTE_NORETURN;
48
49 /* A diagnostic_context surrogate for stderr.  */
50 static diagnostic_context global_diagnostic_context;
51 diagnostic_context *global_dc = &global_diagnostic_context;
52
53 \f
54 /* Return a malloc'd string containing MSG formatted a la printf.  The
55    caller is responsible for freeing the memory.  */
56 static char *
57 build_message_string (const char *msg, ...)
58 {
59   char *str;
60   va_list ap;
61
62   va_start (ap, msg);
63   vasprintf (&str, msg, ap);
64   va_end (ap);
65
66   return str;
67 }
68
69 /* Same as diagnostic_build_prefix, but only the source FILE is given.  */
70 char *
71 file_name_as_prefix (const char *f)
72 {
73   return build_message_string ("%s: ", f);
74 }
75
76
77 \f
78 /* Initialize the diagnostic message outputting machinery.  */
79 void
80 diagnostic_initialize (diagnostic_context *context)
81 {
82   /* Allocate a basic pretty-printer.  Clients will replace this a
83      much more elaborated pretty-printer if they wish.  */
84   context->printer = XNEW (pretty_printer);
85   pp_construct (context->printer, NULL, 0);
86   /* By default, diagnostics are sent to stderr.  */
87   context->printer->buffer->stream = stderr;
88   /* By default, we emit prefixes once per message.  */
89   context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
90
91   memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
92   context->some_warnings_are_errors = false;
93   context->warning_as_error_requested = false;
94   memset (context->classify_diagnostic, DK_UNSPECIFIED,
95           sizeof context->classify_diagnostic);
96   context->show_option_requested = false;
97   context->abort_on_error = false;
98   context->internal_error = NULL;
99   diagnostic_starter (context) = default_diagnostic_starter;
100   diagnostic_finalizer (context) = default_diagnostic_finalizer;
101   context->last_module = 0;
102   context->x_data = NULL;
103   context->lock = 0;
104   context->inhibit_notes_p = false;
105 }
106
107 /* Do any cleaning up required after the last diagnostic is emitted.  */
108
109 void
110 diagnostic_finish (diagnostic_context *context)
111 {
112   /* Some of the errors may actually have been warnings.  */
113   if (context->some_warnings_are_errors)
114     {
115       /* -Werror was given.  */
116       if (context->warning_as_error_requested)
117         pp_verbatim (context->printer,
118                      _("%s: all warnings being treated as errors\n"),
119                      progname);
120       /* At least one -Werror= was given.  */
121       else
122         pp_verbatim (context->printer,
123                      _("%s: some warnings being treated as errors\n"),
124                      progname);
125       pp_flush (context->printer);
126     }
127 }
128
129 /* Initialize DIAGNOSTIC, where the message MSG has already been
130    translated.  */
131 void
132 diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
133                                 va_list *args, location_t location,
134                                 diagnostic_t kind)
135 {
136   diagnostic->message.err_no = errno;
137   diagnostic->message.args_ptr = args;
138   diagnostic->message.format_spec = msg;
139   diagnostic->location = location;
140   diagnostic->override_column = 0;
141   diagnostic->kind = kind;
142   diagnostic->option_index = 0;
143 }
144
145 /* Initialize DIAGNOSTIC, where the message GMSGID has not yet been
146    translated.  */
147 void
148 diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid,
149                      va_list *args, location_t location,
150                      diagnostic_t kind)
151 {
152   diagnostic_set_info_translated (diagnostic, _(gmsgid), args, location, kind);
153 }
154
155 /* Return a malloc'd string describing a location.  The caller is
156    responsible for freeing the memory.  */
157 char *
158 diagnostic_build_prefix (diagnostic_context *context,
159                          diagnostic_info *diagnostic)
160 {
161   static const char *const diagnostic_kind_text[] = {
162 #define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
163 #include "diagnostic.def"
164 #undef DEFINE_DIAGNOSTIC_KIND
165     "must-not-happen"
166   };
167   const char *text = _(diagnostic_kind_text[diagnostic->kind]);
168   expanded_location s = expand_location (diagnostic->location);
169   if (diagnostic->override_column)
170     s.column = diagnostic->override_column;
171   gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
172
173   return
174     (s.file == NULL
175      ? build_message_string ("%s: %s", progname, text)
176      : context->show_column
177      ? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text)
178      : build_message_string ("%s:%d: %s", s.file, s.line, text));
179 }
180
181 /* Take any action which is expected to happen after the diagnostic
182    is written out.  This function does not always return.  */
183 static void
184 diagnostic_action_after_output (diagnostic_context *context,
185                                 diagnostic_info *diagnostic)
186 {
187   switch (diagnostic->kind)
188     {
189     case DK_DEBUG:
190     case DK_NOTE:
191     case DK_ANACHRONISM:
192     case DK_WARNING:
193       break;
194
195     case DK_ERROR:
196     case DK_SORRY:
197       if (context->abort_on_error)
198         real_abort ();
199       if (context->fatal_errors)
200         {
201           fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
202           diagnostic_finish (context);
203           exit (FATAL_EXIT_CODE);
204         }
205       break;
206
207     case DK_ICE:
208       if (context->abort_on_error)
209         real_abort ();
210
211       fnotice (stderr, "Please submit a full bug report,\n"
212                "with preprocessed source if appropriate.\n"
213                "See %s for instructions.\n", bug_report_url);
214       exit (ICE_EXIT_CODE);
215
216     case DK_FATAL:
217       if (context->abort_on_error)
218         real_abort ();
219       diagnostic_finish (context);
220       fnotice (stderr, "compilation terminated.\n");
221       exit (FATAL_EXIT_CODE);
222
223     default:
224       gcc_unreachable ();
225     }
226 }
227
228 void
229 diagnostic_report_current_module (diagnostic_context *context)
230 {
231   const struct line_map *map;
232
233   if (pp_needs_newline (context->printer))
234     {
235       pp_newline (context->printer);
236       pp_needs_newline (context->printer) = false;
237     }
238
239   if (input_location <= BUILTINS_LOCATION)
240     return;
241
242   map = linemap_lookup (line_table, input_location);
243   if (map && diagnostic_last_module_changed (context, map))
244     {
245       diagnostic_set_last_module (context, map);
246       if (! MAIN_FILE_P (map))
247         {
248           map = INCLUDED_FROM (line_table, map);
249           if (context->show_column)
250             pp_verbatim (context->printer,
251                          "In file included from %s:%d:%d",
252                          map->to_file,
253                          LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
254           else
255             pp_verbatim (context->printer,
256                          "In file included from %s:%d",
257                          map->to_file, LAST_SOURCE_LINE (map));
258           while (! MAIN_FILE_P (map))
259             {
260               map = INCLUDED_FROM (line_table, map);
261               pp_verbatim (context->printer,
262                            ",\n                 from %s:%d",
263                            map->to_file, LAST_SOURCE_LINE (map));
264             }
265           pp_verbatim (context->printer, ":");
266           pp_newline (context->printer);
267         }
268     }
269 }
270
271 void
272 default_diagnostic_starter (diagnostic_context *context,
273                             diagnostic_info *diagnostic)
274 {
275   diagnostic_report_current_module (context);
276   pp_set_prefix (context->printer, diagnostic_build_prefix (context,
277                                                             diagnostic));
278 }
279
280 void
281 default_diagnostic_finalizer (diagnostic_context *context,
282                               diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
283 {
284   pp_destroy_prefix (context->printer);
285 }
286
287 /* Interface to specify diagnostic kind overrides.  Returns the
288    previous setting, or DK_UNSPECIFIED if the parameters are out of
289    range.  */
290 diagnostic_t
291 diagnostic_classify_diagnostic (diagnostic_context *context,
292                                 int option_index,
293                                 diagnostic_t new_kind)
294 {
295   diagnostic_t old_kind;
296
297   if (option_index <= 0
298       || option_index >= N_OPTS
299       || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
300     return DK_UNSPECIFIED;
301
302   old_kind = context->classify_diagnostic[option_index];
303   context->classify_diagnostic[option_index] = new_kind;
304   return old_kind;
305 }
306
307 /* Report a diagnostic message (an error or a warning) as specified by
308    DC.  This function is *the* subroutine in terms of which front-ends
309    should implement their specific diagnostic handling modules.  The
310    front-end independent format specifiers are exactly those described
311    in the documentation of output_format.
312    Return true if a diagnostic was printed, false otherwise.  */
313
314 bool
315 diagnostic_report_diagnostic (diagnostic_context *context,
316                               diagnostic_info *diagnostic)
317 {
318   location_t location = diagnostic->location;
319   diagnostic_t orig_diag_kind = diagnostic->kind;
320   const char *saved_format_spec;
321
322   /* Give preference to being able to inhibit warnings, before they
323      get reclassified to something else.  */
324   if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN)
325       && !diagnostic_report_warnings_p (location))
326     return false;
327
328   if (diagnostic->kind == DK_PEDWARN)
329     {
330       diagnostic->kind = pedantic_warning_kind (context);
331       /* We do this to avoid giving the message for -pedantic-errors.  */
332       orig_diag_kind = diagnostic->kind;
333     }
334  
335   if (diagnostic->kind == DK_NOTE && context->inhibit_notes_p)
336     return false;
337
338   if (context->lock > 0)
339     {
340       /* If we're reporting an ICE in the middle of some other error,
341          try to flush out the previous error, then let this one
342          through.  Don't do this more than once.  */
343       if (diagnostic->kind == DK_ICE && context->lock == 1)
344         pp_flush (context->printer);
345       else
346         error_recursion (context);
347     }
348
349   /* If the user requested that warnings be treated as errors, so be
350      it.  Note that we do this before the next block so that
351      individual warnings can be overridden back to warnings with
352      -Wno-error=*.  */
353   if (context->warning_as_error_requested
354       && diagnostic->kind == DK_WARNING)
355     {
356       diagnostic->kind = DK_ERROR;
357     }
358
359   if (diagnostic->option_index)
360     {
361       /* This tests if the user provided the appropriate -Wfoo or
362          -Wno-foo option.  */
363       if (! option_enabled (diagnostic->option_index))
364         return false;
365       /* This tests if the user provided the appropriate -Werror=foo
366          option.  */
367       if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
368         {
369           diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
370         }
371       /* This allows for future extensions, like temporarily disabling
372          warnings for ranges of source code.  */
373       if (diagnostic->kind == DK_IGNORED)
374         return false;
375     }
376
377   if (orig_diag_kind == DK_WARNING && diagnostic->kind == DK_ERROR)
378     context->some_warnings_are_errors = true;
379
380   context->lock++;
381
382   if (diagnostic->kind == DK_ICE)
383     {
384 #ifndef ENABLE_CHECKING
385       /* When not checking, ICEs are converted to fatal errors when an
386          error has already occurred.  This is counteracted by
387          abort_on_error.  */
388       if ((diagnostic_kind_count (context, DK_ERROR) > 0
389            || diagnostic_kind_count (context, DK_SORRY) > 0)
390           && !context->abort_on_error)
391         {
392           expanded_location s = expand_location (diagnostic->location);
393           fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
394                    s.file, s.line);
395           exit (ICE_EXIT_CODE);
396         }
397 #endif
398       if (context->internal_error)
399         (*context->internal_error) (context,
400                                     diagnostic->message.format_spec,
401                                     diagnostic->message.args_ptr);
402     }
403   ++diagnostic_kind_count (context, diagnostic->kind);
404
405   saved_format_spec = diagnostic->message.format_spec;
406   if (context->show_option_requested)
407     {
408       const char * option_text = NULL;
409
410       if (diagnostic->option_index)
411         {
412           /* A warning classified as an error.  */
413           if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
414               && diagnostic->kind == DK_ERROR)
415             option_text 
416               = ACONCAT ((cl_options[OPT_Werror_].opt_text,
417                           /* Skip over "-W".  */
418                           cl_options[diagnostic->option_index].opt_text + 2,
419                           NULL));
420           /* A warning with option.  */
421           else
422             option_text = cl_options[diagnostic->option_index].opt_text;
423         }
424       /* A warning without option classified as an error.  */
425       else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
426                || diagnostic->kind == DK_WARNING)
427         {
428           if (context->warning_as_error_requested)
429             option_text = cl_options[OPT_Werror].opt_text;
430           else
431             option_text = _("enabled by default");
432         }
433
434       if (option_text)
435         diagnostic->message.format_spec
436           = ACONCAT ((diagnostic->message.format_spec,
437                       " ", 
438                       "[", option_text, "]",
439                       NULL));
440     }
441   diagnostic->message.locus = &diagnostic->location;
442   diagnostic->message.x_data = &diagnostic->x_data;
443   diagnostic->x_data = NULL;
444   pp_format (context->printer, &diagnostic->message);
445   (*diagnostic_starter (context)) (context, diagnostic);
446   pp_output_formatted_text (context->printer);
447   (*diagnostic_finalizer (context)) (context, diagnostic);
448   pp_flush (context->printer);
449   diagnostic_action_after_output (context, diagnostic);
450   diagnostic->message.format_spec = saved_format_spec;
451   diagnostic->x_data = NULL;
452
453   context->lock--;
454
455   return true;
456 }
457
458 /* Given a partial pathname as input, return another pathname that
459    shares no directory elements with the pathname of __FILE__.  This
460    is used by fancy_abort() to print `Internal compiler error in expr.c'
461    instead of `Internal compiler error in ../../GCC/gcc/expr.c'.  */
462
463 const char *
464 trim_filename (const char *name)
465 {
466   static const char this_file[] = __FILE__;
467   const char *p = name, *q = this_file;
468
469   /* First skip any "../" in each filename.  This allows us to give a proper
470      reference to a file in a subdirectory.  */
471   while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2]))
472     p += 3;
473
474   while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2]))
475     q += 3;
476
477   /* Now skip any parts the two filenames have in common.  */
478   while (*p == *q && *p != 0 && *q != 0)
479     p++, q++;
480
481   /* Now go backwards until the previous directory separator.  */
482   while (p > name && !IS_DIR_SEPARATOR (p[-1]))
483     p--;
484
485   return p;
486 }
487 \f
488 /* Standard error reporting routines in increasing order of severity.
489    All of these take arguments like printf.  */
490
491 /* Text to be emitted verbatim to the error message stream; this
492    produces no prefix and disables line-wrapping.  Use rarely.  */
493 void
494 verbatim (const char *gmsgid, ...)
495 {
496   text_info text;
497   va_list ap;
498
499   va_start (ap, gmsgid);
500   text.err_no = errno;
501   text.args_ptr = &ap;
502   text.format_spec = _(gmsgid);
503   text.locus = NULL;
504   text.x_data = NULL;
505   pp_format_verbatim (global_dc->printer, &text);
506   pp_flush (global_dc->printer);
507   va_end (ap);
508 }
509
510 bool
511 emit_diagnostic (diagnostic_t kind, location_t location, int opt,
512                  const char *gmsgid, ...)
513 {
514   diagnostic_info diagnostic;
515   va_list ap;
516
517   va_start (ap, gmsgid);
518   if (kind == DK_PERMERROR)
519     {
520       diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
521                            permissive_error_kind (global_dc));
522       diagnostic.option_index = OPT_fpermissive;
523     }
524   else {
525       diagnostic_set_info (&diagnostic, gmsgid, &ap, location, kind);
526       if (kind == DK_WARNING || kind == DK_PEDWARN)
527         diagnostic.option_index = opt;
528   }
529   va_end (ap);
530
531   return report_diagnostic (&diagnostic);
532 }
533
534 /* An informative note at LOCATION.  Use this for additional details on an error
535    message.  */
536 void
537 inform (location_t location, const char *gmsgid, ...)
538 {
539   diagnostic_info diagnostic;
540   va_list ap;
541
542   va_start (ap, gmsgid);
543   diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE);
544   report_diagnostic (&diagnostic);
545   va_end (ap);
546 }
547
548 /* An informative note at LOCATION.  Use this for additional details on an
549    error message.  */
550 void
551 inform_n (location_t location, int n, const char *singular_gmsgid,
552           const char *plural_gmsgid, ...)
553 {
554   diagnostic_info diagnostic;
555   va_list ap;
556
557   va_start (ap, plural_gmsgid);
558   diagnostic_set_info_translated (&diagnostic,
559                                   ngettext (singular_gmsgid, plural_gmsgid, n),
560                                   &ap, location, DK_NOTE);
561   report_diagnostic (&diagnostic);
562   va_end (ap);
563 }
564
565 /* A warning at INPUT_LOCATION.  Use this for code which is correct according
566    to the relevant language specification but is likely to be buggy anyway.
567    Returns true if the warning was printed, false if it was inhibited.  */
568 bool
569 warning (int opt, const char *gmsgid, ...)
570 {
571   diagnostic_info diagnostic;
572   va_list ap;
573
574   va_start (ap, gmsgid);
575   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING);
576   diagnostic.option_index = opt;
577
578   va_end (ap);
579   return report_diagnostic (&diagnostic);
580 }
581
582 /* A warning at LOCATION.  Use this for code which is correct according to the
583    relevant language specification but is likely to be buggy anyway.
584    Returns true if the warning was printed, false if it was inhibited.  */
585
586 bool
587 warning_at (location_t location, int opt, const char *gmsgid, ...)
588 {
589   diagnostic_info diagnostic;
590   va_list ap;
591
592   va_start (ap, gmsgid);
593   diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING);
594   diagnostic.option_index = opt;
595   va_end (ap);
596   return report_diagnostic (&diagnostic);
597 }
598
599 /* A "pedantic" warning at LOCATION: issues a warning unless
600    -pedantic-errors was given on the command line, in which case it
601    issues an error.  Use this for diagnostics required by the relevant
602    language standard, if you have chosen not to make them errors.
603
604    Note that these diagnostics are issued independent of the setting
605    of the -pedantic command-line switch.  To get a warning enabled
606    only with that switch, use either "if (pedantic) pedwarn
607    (OPT_pedantic,...)" or just "pedwarn (OPT_pedantic,..)".  To get a
608    pedwarn independently of the -pedantic switch use "pedwarn (0,...)".
609
610    Returns true if the warning was printed, false if it was inhibited.  */
611
612 bool
613 pedwarn (location_t location, int opt, const char *gmsgid, ...)
614 {
615   diagnostic_info diagnostic;
616   va_list ap;
617
618   va_start (ap, gmsgid);
619   diagnostic_set_info (&diagnostic, gmsgid, &ap, location,  DK_PEDWARN);
620   diagnostic.option_index = opt;
621   va_end (ap);
622   return report_diagnostic (&diagnostic);
623 }
624
625 /* A "permissive" error at LOCATION: issues an error unless
626    -fpermissive was given on the command line, in which case it issues
627    a warning.  Use this for things that really should be errors but we
628    want to support legacy code.
629
630    Returns true if the warning was printed, false if it was inhibited.  */
631
632 bool
633 permerror (location_t location, const char *gmsgid, ...)
634 {
635   diagnostic_info diagnostic;
636   va_list ap;
637
638   va_start (ap, gmsgid);
639   diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
640                        permissive_error_kind (global_dc));
641   diagnostic.option_index = OPT_fpermissive;
642   va_end (ap);
643   return report_diagnostic (&diagnostic);
644 }
645
646 /* A hard error: the code is definitely ill-formed, and an object file
647    will not be produced.  */
648 void
649 error (const char *gmsgid, ...)
650 {
651   diagnostic_info diagnostic;
652   va_list ap;
653
654   va_start (ap, gmsgid);
655   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR);
656   report_diagnostic (&diagnostic);
657   va_end (ap);
658 }
659
660 /* A hard error: the code is definitely ill-formed, and an object file
661    will not be produced.  */
662 void
663 error_n (location_t location, int n, const char *singular_gmsgid,
664          const char *plural_gmsgid, ...)
665 {
666   diagnostic_info diagnostic;
667   va_list ap;
668
669   va_start (ap, plural_gmsgid);
670   diagnostic_set_info_translated (&diagnostic,
671                                   ngettext (singular_gmsgid, plural_gmsgid, n),
672                                   &ap, location, DK_ERROR);
673   report_diagnostic (&diagnostic);
674   va_end (ap);
675 }
676
677 /* Same as ebove, but use location LOC instead of input_location.  */
678 void
679 error_at (location_t loc, const char *gmsgid, ...)
680 {
681   diagnostic_info diagnostic;
682   va_list ap;
683
684   va_start (ap, gmsgid);
685   diagnostic_set_info (&diagnostic, gmsgid, &ap, loc, DK_ERROR);
686   report_diagnostic (&diagnostic);
687   va_end (ap);
688 }
689
690 /* "Sorry, not implemented."  Use for a language feature which is
691    required by the relevant specification but not implemented by GCC.
692    An object file will not be produced.  */
693 void
694 sorry (const char *gmsgid, ...)
695 {
696   diagnostic_info diagnostic;
697   va_list ap;
698
699   va_start (ap, gmsgid);
700   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_SORRY);
701   report_diagnostic (&diagnostic);
702   va_end (ap);
703 }
704
705 /* An error which is severe enough that we make no attempt to
706    continue.  Do not use this for internal consistency checks; that's
707    internal_error.  Use of this function should be rare.  */
708 void
709 fatal_error (const char *gmsgid, ...)
710 {
711   diagnostic_info diagnostic;
712   va_list ap;
713
714   va_start (ap, gmsgid);
715   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_FATAL);
716   report_diagnostic (&diagnostic);
717   va_end (ap);
718
719   gcc_unreachable ();
720 }
721
722 /* An internal consistency check has failed.  We make no attempt to
723    continue.  Note that unless there is debugging value to be had from
724    a more specific message, or some other good reason, you should use
725    abort () instead of calling this function directly.  */
726 void
727 internal_error (const char *gmsgid, ...)
728 {
729   diagnostic_info diagnostic;
730   va_list ap;
731
732   va_start (ap, gmsgid);
733   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ICE);
734   report_diagnostic (&diagnostic);
735   va_end (ap);
736
737   gcc_unreachable ();
738 }
739 \f
740 /* Special case error functions.  Most are implemented in terms of the
741    above, or should be.  */
742
743 /* Print a diagnostic MSGID on FILE.  This is just fprintf, except it
744    runs its second argument through gettext.  */
745 void
746 fnotice (FILE *file, const char *cmsgid, ...)
747 {
748   va_list ap;
749
750   va_start (ap, cmsgid);
751   vfprintf (file, _(cmsgid), ap);
752   va_end (ap);
753 }
754
755 /* Inform the user that an error occurred while trying to report some
756    other error.  This indicates catastrophic internal inconsistencies,
757    so give up now.  But do try to flush out the previous error.
758    This mustn't use internal_error, that will cause infinite recursion.  */
759
760 static void
761 error_recursion (diagnostic_context *context)
762 {
763   diagnostic_info diagnostic;
764
765   if (context->lock < 3)
766     pp_flush (context->printer);
767
768   fnotice (stderr,
769            "Internal compiler error: Error reporting routines re-entered.\n");
770
771   /* Call diagnostic_action_after_output to get the "please submit a bug
772      report" message.  It only looks at the kind field of diagnostic_info.  */
773   diagnostic.kind = DK_ICE;
774   diagnostic_action_after_output (context, &diagnostic);
775
776   /* Do not use gcc_unreachable here; that goes through internal_error
777      and therefore would cause infinite recursion.  */
778   real_abort ();
779 }
780
781 /* Report an internal compiler error in a friendly manner.  This is
782    the function that gets called upon use of abort() in the source
783    code generally, thanks to a special macro.  */
784
785 void
786 fancy_abort (const char *file, int line, const char *function)
787 {
788   internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
789 }
790
791 /* Really call the system 'abort'.  This has to go right at the end of
792    this file, so that there are no functions after it that call abort
793    and get the system abort instead of our macro.  */
794 #undef abort
795 static void
796 real_abort (void)
797 {
798   abort ();
799 }