OSDN Git Service

2009-04-14 Diego Novillo <dnovillo@google.com>
[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 && s.column != 0
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           pp_verbatim (context->printer,
248                        "In file included from %s:%d",
249                        map->to_file, LAST_SOURCE_LINE (map));
250           while (! MAIN_FILE_P (map))
251             {
252               map = INCLUDED_FROM (line_table, map);
253               pp_verbatim (context->printer,
254                            ",\n                 from %s:%d",
255                            map->to_file, LAST_SOURCE_LINE (map));
256             }
257           pp_verbatim (context->printer, ":");
258           pp_newline (context->printer);
259         }
260     }
261 }
262
263 static void
264 default_diagnostic_starter (diagnostic_context *context,
265                             diagnostic_info *diagnostic)
266 {
267   diagnostic_report_current_function (context, diagnostic);
268   pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
269 }
270
271 static void
272 default_diagnostic_finalizer (diagnostic_context *context,
273                               diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
274 {
275   pp_destroy_prefix (context->printer);
276 }
277
278 /* Interface to specify diagnostic kind overrides.  Returns the
279    previous setting, or DK_UNSPECIFIED if the parameters are out of
280    range.  */
281 diagnostic_t
282 diagnostic_classify_diagnostic (diagnostic_context *context,
283                                 int option_index,
284                                 diagnostic_t new_kind)
285 {
286   diagnostic_t old_kind;
287
288   if (option_index <= 0
289       || option_index >= N_OPTS
290       || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
291     return DK_UNSPECIFIED;
292
293   old_kind = context->classify_diagnostic[option_index];
294   context->classify_diagnostic[option_index] = new_kind;
295   return old_kind;
296 }
297
298 /* Report a diagnostic message (an error or a warning) as specified by
299    DC.  This function is *the* subroutine in terms of which front-ends
300    should implement their specific diagnostic handling modules.  The
301    front-end independent format specifiers are exactly those described
302    in the documentation of output_format.  
303    Return true if a diagnostic was printed, false otherwise.  */
304
305 bool
306 diagnostic_report_diagnostic (diagnostic_context *context,
307                               diagnostic_info *diagnostic)
308 {
309   location_t location = diagnostic->location;
310   bool maybe_print_warnings_as_errors_message = false;
311   const char *saved_format_spec;
312
313   /* Give preference to being able to inhibit warnings, before they
314      get reclassified to something else.  */
315   if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN)
316       && !diagnostic_report_warnings_p (location))
317     return false;
318
319   if (diagnostic->kind == DK_PEDWARN) 
320     diagnostic->kind = pedantic_warning_kind ();
321   
322   if (context->lock > 0)
323     {
324       /* If we're reporting an ICE in the middle of some other error,
325          try to flush out the previous error, then let this one
326          through.  Don't do this more than once.  */
327       if (diagnostic->kind == DK_ICE && context->lock == 1)
328         pp_flush (context->printer);
329       else
330         error_recursion (context);
331     }
332
333   /* If the user requested that warnings be treated as errors, so be
334      it.  Note that we do this before the next block so that
335      individual warnings can be overridden back to warnings with
336      -Wno-error=*.  */
337   if (context->warning_as_error_requested
338       && diagnostic->kind == DK_WARNING)
339     {
340       diagnostic->kind = DK_ERROR;
341       maybe_print_warnings_as_errors_message = true;
342     }
343   
344   if (diagnostic->option_index)
345     {
346       /* This tests if the user provided the appropriate -Wfoo or
347          -Wno-foo option.  */
348       if (! option_enabled (diagnostic->option_index))
349         return false;
350       /* This tests if the user provided the appropriate -Werror=foo
351          option.  */
352       if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
353         {
354           diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
355           maybe_print_warnings_as_errors_message = false;
356         }
357       /* This allows for future extensions, like temporarily disabling
358          warnings for ranges of source code.  */
359       if (diagnostic->kind == DK_IGNORED)
360         return false;
361     }
362
363   /* If we changed the kind due to -Werror, and didn't override it, we
364      need to print this message.  */
365   if (context->issue_warnings_are_errors_message
366       && maybe_print_warnings_as_errors_message)
367     {
368       pp_verbatim (context->printer,
369                    "%s: warnings being treated as errors\n", progname);
370       context->issue_warnings_are_errors_message = false;
371     }
372
373   context->lock++;
374
375   if ((diagnostic->kind == DK_ERROR
376        || diagnostic->kind == DK_WARNING
377        || diagnostic->kind == DK_ICE)
378       && plugins_active_p ())
379     {
380       fnotice (stderr, "*** WARNING *** there are active plugins, do not report"
381                " this as a bug unless you can reproduce it without enabling"
382                " any plugins.\n");
383       dump_active_plugins (stderr);
384     }
385
386   if (diagnostic->kind == DK_ICE) 
387     {
388 #ifndef ENABLE_CHECKING
389       /* When not checking, ICEs are converted to fatal errors when an
390          error has already occurred.  This is counteracted by
391          abort_on_error.  */
392       if ((diagnostic_kind_count (context, DK_ERROR) > 0
393            || diagnostic_kind_count (context, DK_SORRY) > 0)
394           && !context->abort_on_error)
395         {
396           expanded_location s = expand_location (diagnostic->location);
397           fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
398                    s.file, s.line);
399           exit (ICE_EXIT_CODE);
400         }
401 #endif
402       if (context->internal_error)
403         (*context->internal_error) (diagnostic->message.format_spec,
404                                     diagnostic->message.args_ptr);
405     }
406   ++diagnostic_kind_count (context, diagnostic->kind);
407   
408   saved_format_spec = diagnostic->message.format_spec;
409   if (context->show_option_requested && diagnostic->option_index)
410     diagnostic->message.format_spec
411       = ACONCAT ((diagnostic->message.format_spec,
412                   " [", cl_options[diagnostic->option_index].opt_text, "]", NULL));
413   
414   diagnostic->message.locus = &diagnostic->location;
415   diagnostic->message.abstract_origin = &diagnostic->abstract_origin;
416   diagnostic->abstract_origin = NULL;
417   pp_format (context->printer, &diagnostic->message);
418   (*diagnostic_starter (context)) (context, diagnostic);
419   pp_output_formatted_text (context->printer);
420   (*diagnostic_finalizer (context)) (context, diagnostic);
421   pp_flush (context->printer);
422   diagnostic_action_after_output (context, diagnostic);
423   diagnostic->message.format_spec = saved_format_spec;
424   diagnostic->abstract_origin = NULL;
425
426   context->lock--;
427
428   return true;
429 }
430
431 /* Given a partial pathname as input, return another pathname that
432    shares no directory elements with the pathname of __FILE__.  This
433    is used by fancy_abort() to print `Internal compiler error in expr.c'
434    instead of `Internal compiler error in ../../GCC/gcc/expr.c'.  */
435
436 const char *
437 trim_filename (const char *name)
438 {
439   static const char this_file[] = __FILE__;
440   const char *p = name, *q = this_file;
441
442   /* First skip any "../" in each filename.  This allows us to give a proper
443      reference to a file in a subdirectory.  */
444   while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2]))
445     p += 3;
446
447   while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2]))
448     q += 3;
449
450   /* Now skip any parts the two filenames have in common.  */
451   while (*p == *q && *p != 0 && *q != 0)
452     p++, q++;
453
454   /* Now go backwards until the previous directory separator.  */
455   while (p > name && !IS_DIR_SEPARATOR (p[-1]))
456     p--;
457
458   return p;
459 }
460 \f
461 /* Standard error reporting routines in increasing order of severity.
462    All of these take arguments like printf.  */
463
464 /* Text to be emitted verbatim to the error message stream; this
465    produces no prefix and disables line-wrapping.  Use rarely.  */
466 void
467 verbatim (const char *gmsgid, ...)
468 {
469   text_info text;
470   va_list ap;
471
472   va_start (ap, gmsgid);
473   text.err_no = errno;
474   text.args_ptr = &ap;
475   text.format_spec = _(gmsgid);
476   text.locus = NULL;
477   text.abstract_origin = NULL;
478   pp_format_verbatim (global_dc->printer, &text);
479   pp_flush (global_dc->printer);
480   va_end (ap);
481 }
482
483 bool
484 emit_diagnostic (diagnostic_t kind, location_t location, int opt, 
485                  const char *gmsgid, ...)
486 {
487   diagnostic_info diagnostic;
488   va_list ap;
489
490   va_start (ap, gmsgid);
491   if (kind == DK_PERMERROR)
492     {
493       diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
494                            permissive_error_kind ());
495       diagnostic.option_index = OPT_fpermissive;
496     }
497   else {
498       diagnostic_set_info (&diagnostic, gmsgid, &ap, location, kind);
499       if (kind == DK_WARNING || kind == DK_PEDWARN)
500         diagnostic.option_index = opt;
501   }
502   va_end (ap);
503
504   return report_diagnostic (&diagnostic);
505 }
506
507 /* An informative note at LOCATION.  Use this for additional details on an error
508    message.  */
509 void
510 inform (location_t location, const char *gmsgid, ...)
511 {
512   diagnostic_info diagnostic;
513   va_list ap;
514
515   va_start (ap, gmsgid);
516   diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE);
517   report_diagnostic (&diagnostic);
518   va_end (ap);
519 }
520
521 /* A warning at INPUT_LOCATION.  Use this for code which is correct according
522    to the relevant language specification but is likely to be buggy anyway.  
523    Returns true if the warning was printed, false if it was inhibited.  */
524 bool
525 warning (int opt, const char *gmsgid, ...)
526 {
527   diagnostic_info diagnostic;
528   va_list ap;
529
530   va_start (ap, gmsgid);
531   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING);
532   diagnostic.option_index = opt;
533
534   va_end (ap);
535   return report_diagnostic (&diagnostic);
536 }
537
538 /* A warning at LOCATION.  Use this for code which is correct according to the
539    relevant language specification but is likely to be buggy anyway.
540    Returns true if the warning was printed, false if it was inhibited.  */
541
542 bool
543 warning_at (location_t location, int opt, const char *gmsgid, ...)
544 {
545   diagnostic_info diagnostic;
546   va_list ap;
547
548   va_start (ap, gmsgid);
549   diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING);
550   diagnostic.option_index = opt;
551   va_end (ap);
552   return report_diagnostic (&diagnostic);
553 }
554
555 /* A "pedantic" warning at LOCATION: issues a warning unless
556    -pedantic-errors was given on the command line, in which case it
557    issues an error.  Use this for diagnostics required by the relevant
558    language standard, if you have chosen not to make them errors.
559
560    Note that these diagnostics are issued independent of the setting
561    of the -pedantic command-line switch.  To get a warning enabled
562    only with that switch, use either "if (pedantic) pedwarn
563    (OPT_pedantic,...)" or just "pedwarn (OPT_pedantic,..)".  To get a
564    pedwarn independently of the -pedantic switch use "pedwarn (0,...)".
565
566    Returns true if the warning was printed, false if it was inhibited.  */
567
568 bool
569 pedwarn (location_t location, 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, location,  DK_PEDWARN);
576   diagnostic.option_index = opt;
577   va_end (ap);
578   return report_diagnostic (&diagnostic);
579 }
580
581 /* A "permissive" error at LOCATION: issues an error unless
582    -fpermissive was given on the command line, in which case it issues
583    a warning.  Use this for things that really should be errors but we
584    want to support legacy code.
585
586    Returns true if the warning was printed, false if it was inhibited.  */
587
588 bool
589 permerror (location_t location, const char *gmsgid, ...)
590 {
591   diagnostic_info diagnostic;
592   va_list ap;
593
594   va_start (ap, gmsgid);
595   diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
596                        permissive_error_kind ());
597   diagnostic.option_index = OPT_fpermissive;
598   va_end (ap);
599   return report_diagnostic (&diagnostic);
600 }
601
602 /* A hard error: the code is definitely ill-formed, and an object file
603    will not be produced.  */
604 void
605 error (const char *gmsgid, ...)
606 {
607   diagnostic_info diagnostic;
608   va_list ap;
609
610   va_start (ap, gmsgid);
611   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR);
612   report_diagnostic (&diagnostic);
613   va_end (ap);
614 }
615
616 /* Same as ebove, but use location LOC instead of input_location.  */
617 void
618 error_at (location_t loc, const char *gmsgid, ...)
619 {
620   diagnostic_info diagnostic;
621   va_list ap;
622
623   va_start (ap, gmsgid);
624   diagnostic_set_info (&diagnostic, gmsgid, &ap, loc, DK_ERROR);
625   report_diagnostic (&diagnostic);
626   va_end (ap);
627 }
628
629 /* "Sorry, not implemented."  Use for a language feature which is
630    required by the relevant specification but not implemented by GCC.
631    An object file will not be produced.  */
632 void
633 sorry (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, input_location, DK_SORRY);
640   report_diagnostic (&diagnostic);
641   va_end (ap);
642 }
643
644 /* An error which is severe enough that we make no attempt to
645    continue.  Do not use this for internal consistency checks; that's
646    internal_error.  Use of this function should be rare.  */
647 void
648 fatal_error (const char *gmsgid, ...)
649 {
650   diagnostic_info diagnostic;
651   va_list ap;
652
653   va_start (ap, gmsgid);
654   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_FATAL);
655   report_diagnostic (&diagnostic);
656   va_end (ap);
657
658   gcc_unreachable ();
659 }
660
661 /* An internal consistency check has failed.  We make no attempt to
662    continue.  Note that unless there is debugging value to be had from
663    a more specific message, or some other good reason, you should use
664    abort () instead of calling this function directly.  */
665 void
666 internal_error (const char *gmsgid, ...)
667 {
668   diagnostic_info diagnostic;
669   va_list ap;
670
671   va_start (ap, gmsgid);
672   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ICE);
673   report_diagnostic (&diagnostic);
674   va_end (ap);
675
676   gcc_unreachable ();
677 }
678 \f
679 /* Special case error functions.  Most are implemented in terms of the
680    above, or should be.  */
681
682 /* Print a diagnostic MSGID on FILE.  This is just fprintf, except it
683    runs its second argument through gettext.  */
684 void
685 fnotice (FILE *file, const char *cmsgid, ...)
686 {
687   va_list ap;
688
689   va_start (ap, cmsgid);
690   vfprintf (file, _(cmsgid), ap);
691   va_end (ap);
692 }
693
694 /* Inform the user that an error occurred while trying to report some
695    other error.  This indicates catastrophic internal inconsistencies,
696    so give up now.  But do try to flush out the previous error.
697    This mustn't use internal_error, that will cause infinite recursion.  */
698
699 static void
700 error_recursion (diagnostic_context *context)
701 {
702   diagnostic_info diagnostic;
703
704   if (context->lock < 3)
705     pp_flush (context->printer);
706
707   fnotice (stderr,
708            "Internal compiler error: Error reporting routines re-entered.\n");
709
710   /* Call diagnostic_action_after_output to get the "please submit a bug
711      report" message.  It only looks at the kind field of diagnostic_info.  */
712   diagnostic.kind = DK_ICE;
713   diagnostic_action_after_output (context, &diagnostic);
714
715   /* Do not use gcc_unreachable here; that goes through internal_error
716      and therefore would cause infinite recursion.  */
717   real_abort ();
718 }
719
720 /* Report an internal compiler error in a friendly manner.  This is
721    the function that gets called upon use of abort() in the source
722    code generally, thanks to a special macro.  */
723
724 void
725 fancy_abort (const char *file, int line, const char *function)
726 {
727   internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
728 }
729
730 /* Really call the system 'abort'.  This has to go right at the end of
731    this file, so that there are no functions after it that call abort
732    and get the system abort instead of our macro.  */
733 #undef abort
734 static void
735 real_abort (void)
736 {
737   abort ();
738 }