OSDN Git Service

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