OSDN Git Service

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