OSDN Git Service

Fix PR debug/43628
[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 "flags.h"
31 #include "input.h"
32 #include "toplev.h"
33 #include "intl.h"
34 #include "diagnostic.h"
35 #include "opts.h"
36 #include "plugin.h"
37
38 #define pedantic_warning_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
39 #define permissive_error_kind() (flag_permissive ? DK_WARNING : DK_ERROR)
40
41 /* Prototypes.  */
42 static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
43
44 static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
45
46 static void diagnostic_action_after_output (diagnostic_context *,
47                                             diagnostic_info *);
48 static void real_abort (void) ATTRIBUTE_NORETURN;
49
50 /* A diagnostic_context surrogate for stderr.  */
51 static diagnostic_context global_diagnostic_context;
52 diagnostic_context *global_dc = &global_diagnostic_context;
53
54 \f
55 /* Return a malloc'd string containing MSG formatted a la printf.  The
56    caller is responsible for freeing the memory.  */
57 static char *
58 build_message_string (const char *msg, ...)
59 {
60   char *str;
61   va_list ap;
62
63   va_start (ap, msg);
64   vasprintf (&str, msg, ap);
65   va_end (ap);
66
67   return str;
68 }
69
70 /* Same as diagnostic_build_prefix, but only the source FILE is given.  */
71 char *
72 file_name_as_prefix (const char *f)
73 {
74   return build_message_string ("%s: ", f);
75 }
76
77
78 \f
79 /* Initialize the diagnostic message outputting machinery.  */
80 void
81 diagnostic_initialize (diagnostic_context *context)
82 {
83   /* Allocate a basic pretty-printer.  Clients will replace this a
84      much more elaborated pretty-printer if they wish.  */
85   context->printer = XNEW (pretty_printer);
86   pp_construct (context->printer, NULL, 0);
87   /* By default, diagnostics are sent to stderr.  */
88   context->printer->buffer->stream = stderr;
89   /* By default, we emit prefixes once per message.  */
90   context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
91
92   memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
93   context->some_warnings_are_errors = false;
94   context->warning_as_error_requested = false;
95   memset (context->classify_diagnostic, DK_UNSPECIFIED,
96           sizeof context->classify_diagnostic);
97   context->show_option_requested = false;
98   context->abort_on_error = false;
99   context->internal_error = NULL;
100   diagnostic_starter (context) = default_diagnostic_starter;
101   diagnostic_finalizer (context) = default_diagnostic_finalizer;
102   context->last_module = 0;
103   context->x_data = NULL;
104   context->lock = 0;
105   context->inhibit_notes_p = false;
106 }
107
108 /* Do any cleaning up required after the last diagnostic is emitted.  */
109
110 void
111 diagnostic_finish (diagnostic_context *context)
112 {
113   /* Some of the errors may actually have been warnings.  */
114   if (context->some_warnings_are_errors)
115     {
116       /* -Werror was given.  */
117       if (context->warning_as_error_requested)
118         pp_verbatim (context->printer,
119                      _("%s: all warnings being treated as errors\n"),
120                      progname);
121       /* At least one -Werror= was given.  */
122       else
123         pp_verbatim (context->printer,
124                      _("%s: some warnings being treated as errors\n"),
125                      progname);
126       pp_flush (context->printer);
127     }
128 }
129
130 /* Initialize DIAGNOSTIC, where the message MSG has already been
131    translated.  */
132 void
133 diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
134                                 va_list *args, location_t location,
135                                 diagnostic_t kind)
136 {
137   diagnostic->message.err_no = errno;
138   diagnostic->message.args_ptr = args;
139   diagnostic->message.format_spec = msg;
140   diagnostic->location = location;
141   diagnostic->override_column = 0;
142   diagnostic->kind = kind;
143   diagnostic->option_index = 0;
144 }
145
146 /* Initialize DIAGNOSTIC, where the message GMSGID has not yet been
147    translated.  */
148 void
149 diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid,
150                      va_list *args, location_t location,
151                      diagnostic_t kind)
152 {
153   diagnostic_set_info_translated (diagnostic, _(gmsgid), args, location, kind);
154 }
155
156 /* Return a malloc'd string describing a location.  The caller is
157    responsible for freeing the memory.  */
158 char *
159 diagnostic_build_prefix (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      : flag_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 (flag_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 (flag_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 (diagnostic));
277 }
278
279 void
280 default_diagnostic_finalizer (diagnostic_context *context,
281                               diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
282 {
283   pp_destroy_prefix (context->printer);
284 }
285
286 /* Interface to specify diagnostic kind overrides.  Returns the
287    previous setting, or DK_UNSPECIFIED if the parameters are out of
288    range.  */
289 diagnostic_t
290 diagnostic_classify_diagnostic (diagnostic_context *context,
291                                 int option_index,
292                                 diagnostic_t new_kind)
293 {
294   diagnostic_t old_kind;
295
296   if (option_index <= 0
297       || option_index >= N_OPTS
298       || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
299     return DK_UNSPECIFIED;
300
301   old_kind = context->classify_diagnostic[option_index];
302   context->classify_diagnostic[option_index] = new_kind;
303   return old_kind;
304 }
305
306 /* Report a diagnostic message (an error or a warning) as specified by
307    DC.  This function is *the* subroutine in terms of which front-ends
308    should implement their specific diagnostic handling modules.  The
309    front-end independent format specifiers are exactly those described
310    in the documentation of output_format.
311    Return true if a diagnostic was printed, false otherwise.  */
312
313 bool
314 diagnostic_report_diagnostic (diagnostic_context *context,
315                               diagnostic_info *diagnostic)
316 {
317   location_t location = diagnostic->location;
318   diagnostic_t orig_diag_kind = diagnostic->kind;
319   const char *saved_format_spec;
320
321   /* Give preference to being able to inhibit warnings, before they
322      get reclassified to something else.  */
323   if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN)
324       && !diagnostic_report_warnings_p (location))
325     return false;
326
327   if (diagnostic->kind == DK_PEDWARN)
328     {
329       diagnostic->kind = pedantic_warning_kind ();
330       /* We do this to avoid giving the message for -pedantic-errors.  */
331       orig_diag_kind = diagnostic->kind;
332     }
333  
334   if (diagnostic->kind == DK_NOTE && context->inhibit_notes_p)
335     return false;
336
337   if (context->lock > 0)
338     {
339       /* If we're reporting an ICE in the middle of some other error,
340          try to flush out the previous error, then let this one
341          through.  Don't do this more than once.  */
342       if (diagnostic->kind == DK_ICE && context->lock == 1)
343         pp_flush (context->printer);
344       else
345         error_recursion (context);
346     }
347
348   /* If the user requested that warnings be treated as errors, so be
349      it.  Note that we do this before the next block so that
350      individual warnings can be overridden back to warnings with
351      -Wno-error=*.  */
352   if (context->warning_as_error_requested
353       && diagnostic->kind == DK_WARNING)
354     {
355       diagnostic->kind = DK_ERROR;
356     }
357
358   if (diagnostic->option_index)
359     {
360       /* This tests if the user provided the appropriate -Wfoo or
361          -Wno-foo option.  */
362       if (! option_enabled (diagnostic->option_index))
363         return false;
364       /* This tests if the user provided the appropriate -Werror=foo
365          option.  */
366       if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
367         {
368           diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
369         }
370       /* This allows for future extensions, like temporarily disabling
371          warnings for ranges of source code.  */
372       if (diagnostic->kind == DK_IGNORED)
373         return false;
374     }
375
376   if (orig_diag_kind == DK_WARNING && diagnostic->kind == DK_ERROR)
377     context->some_warnings_are_errors = true;
378
379   context->lock++;
380
381   if (diagnostic->kind == DK_ICE && plugins_active_p ())
382     {
383       fnotice (stderr, "*** WARNING *** there are active plugins, do not report"
384                " this as a bug unless you can reproduce it without enabling"
385                " any plugins.\n");
386       dump_active_plugins (stderr);
387     }
388
389   if (diagnostic->kind == DK_ICE)
390     {
391 #ifndef ENABLE_CHECKING
392       /* When not checking, ICEs are converted to fatal errors when an
393          error has already occurred.  This is counteracted by
394          abort_on_error.  */
395       if ((diagnostic_kind_count (context, DK_ERROR) > 0
396            || diagnostic_kind_count (context, DK_SORRY) > 0)
397           && !context->abort_on_error)
398         {
399           expanded_location s = expand_location (diagnostic->location);
400           fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
401                    s.file, s.line);
402           exit (ICE_EXIT_CODE);
403         }
404 #endif
405       if (context->internal_error)
406         (*context->internal_error) (diagnostic->message.format_spec,
407                                     diagnostic->message.args_ptr);
408     }
409   ++diagnostic_kind_count (context, diagnostic->kind);
410
411   saved_format_spec = diagnostic->message.format_spec;
412   if (context->show_option_requested)
413     {
414       const char * option_text = NULL;
415
416       if (diagnostic->option_index)
417         {
418           /* A warning classified as an error.  */
419           if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
420               && diagnostic->kind == DK_ERROR)
421             option_text 
422               = ACONCAT ((cl_options[OPT_Werror_].opt_text,
423                           /* Skip over "-W".  */
424                           cl_options[diagnostic->option_index].opt_text + 2,
425                           NULL));
426           /* A warning with option.  */
427           else
428             option_text = cl_options[diagnostic->option_index].opt_text;
429         }
430       /* A warning without option classified as an error.  */
431       else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
432                || diagnostic->kind == DK_WARNING)
433         {
434           if (context->warning_as_error_requested)
435             option_text = cl_options[OPT_Werror].opt_text;
436           else
437             option_text = _("enabled by default");
438         }
439
440       if (option_text)
441         diagnostic->message.format_spec
442           = ACONCAT ((diagnostic->message.format_spec,
443                       " ", 
444                       "[", option_text, "]",
445                       NULL));
446     }
447   diagnostic->message.locus = &diagnostic->location;
448   diagnostic->message.x_data = &diagnostic->x_data;
449   diagnostic->x_data = NULL;
450   pp_format (context->printer, &diagnostic->message);
451   (*diagnostic_starter (context)) (context, diagnostic);
452   pp_output_formatted_text (context->printer);
453   (*diagnostic_finalizer (context)) (context, diagnostic);
454   pp_flush (context->printer);
455   diagnostic_action_after_output (context, diagnostic);
456   diagnostic->message.format_spec = saved_format_spec;
457   diagnostic->x_data = NULL;
458
459   context->lock--;
460
461   return true;
462 }
463
464 /* Given a partial pathname as input, return another pathname that
465    shares no directory elements with the pathname of __FILE__.  This
466    is used by fancy_abort() to print `Internal compiler error in expr.c'
467    instead of `Internal compiler error in ../../GCC/gcc/expr.c'.  */
468
469 const char *
470 trim_filename (const char *name)
471 {
472   static const char this_file[] = __FILE__;
473   const char *p = name, *q = this_file;
474
475   /* First skip any "../" in each filename.  This allows us to give a proper
476      reference to a file in a subdirectory.  */
477   while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2]))
478     p += 3;
479
480   while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2]))
481     q += 3;
482
483   /* Now skip any parts the two filenames have in common.  */
484   while (*p == *q && *p != 0 && *q != 0)
485     p++, q++;
486
487   /* Now go backwards until the previous directory separator.  */
488   while (p > name && !IS_DIR_SEPARATOR (p[-1]))
489     p--;
490
491   return p;
492 }
493 \f
494 /* Standard error reporting routines in increasing order of severity.
495    All of these take arguments like printf.  */
496
497 /* Text to be emitted verbatim to the error message stream; this
498    produces no prefix and disables line-wrapping.  Use rarely.  */
499 void
500 verbatim (const char *gmsgid, ...)
501 {
502   text_info text;
503   va_list ap;
504
505   va_start (ap, gmsgid);
506   text.err_no = errno;
507   text.args_ptr = &ap;
508   text.format_spec = _(gmsgid);
509   text.locus = NULL;
510   text.x_data = NULL;
511   pp_format_verbatim (global_dc->printer, &text);
512   pp_flush (global_dc->printer);
513   va_end (ap);
514 }
515
516 bool
517 emit_diagnostic (diagnostic_t kind, location_t location, int opt,
518                  const char *gmsgid, ...)
519 {
520   diagnostic_info diagnostic;
521   va_list ap;
522
523   va_start (ap, gmsgid);
524   if (kind == DK_PERMERROR)
525     {
526       diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
527                            permissive_error_kind ());
528       diagnostic.option_index = OPT_fpermissive;
529     }
530   else {
531       diagnostic_set_info (&diagnostic, gmsgid, &ap, location, kind);
532       if (kind == DK_WARNING || kind == DK_PEDWARN)
533         diagnostic.option_index = opt;
534   }
535   va_end (ap);
536
537   return report_diagnostic (&diagnostic);
538 }
539
540 /* An informative note at LOCATION.  Use this for additional details on an error
541    message.  */
542 void
543 inform (location_t location, 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_NOTE);
550   report_diagnostic (&diagnostic);
551   va_end (ap);
552 }
553
554 /* An informative note at LOCATION.  Use this for additional details on an
555    error message.  */
556 void
557 inform_n (location_t location, int n, const char *singular_gmsgid,
558           const char *plural_gmsgid, ...)
559 {
560   diagnostic_info diagnostic;
561   va_list ap;
562
563   va_start (ap, plural_gmsgid);
564   diagnostic_set_info_translated (&diagnostic,
565                                   ngettext (singular_gmsgid, plural_gmsgid, n),
566                                   &ap, location, DK_NOTE);
567   report_diagnostic (&diagnostic);
568   va_end (ap);
569 }
570
571 /* A warning at INPUT_LOCATION.  Use this for code which is correct according
572    to the relevant language specification but is likely to be buggy anyway.
573    Returns true if the warning was printed, false if it was inhibited.  */
574 bool
575 warning (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, input_location, DK_WARNING);
582   diagnostic.option_index = opt;
583
584   va_end (ap);
585   return report_diagnostic (&diagnostic);
586 }
587
588 /* A warning at LOCATION.  Use this for code which is correct according to the
589    relevant language specification but is likely to be buggy anyway.
590    Returns true if the warning was printed, false if it was inhibited.  */
591
592 bool
593 warning_at (location_t location, int opt, const char *gmsgid, ...)
594 {
595   diagnostic_info diagnostic;
596   va_list ap;
597
598   va_start (ap, gmsgid);
599   diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING);
600   diagnostic.option_index = opt;
601   va_end (ap);
602   return report_diagnostic (&diagnostic);
603 }
604
605 /* A "pedantic" warning at LOCATION: issues a warning unless
606    -pedantic-errors was given on the command line, in which case it
607    issues an error.  Use this for diagnostics required by the relevant
608    language standard, if you have chosen not to make them errors.
609
610    Note that these diagnostics are issued independent of the setting
611    of the -pedantic command-line switch.  To get a warning enabled
612    only with that switch, use either "if (pedantic) pedwarn
613    (OPT_pedantic,...)" or just "pedwarn (OPT_pedantic,..)".  To get a
614    pedwarn independently of the -pedantic switch use "pedwarn (0,...)".
615
616    Returns true if the warning was printed, false if it was inhibited.  */
617
618 bool
619 pedwarn (location_t location, int opt, const char *gmsgid, ...)
620 {
621   diagnostic_info diagnostic;
622   va_list ap;
623
624   va_start (ap, gmsgid);
625   diagnostic_set_info (&diagnostic, gmsgid, &ap, location,  DK_PEDWARN);
626   diagnostic.option_index = opt;
627   va_end (ap);
628   return report_diagnostic (&diagnostic);
629 }
630
631 /* A "permissive" error at LOCATION: issues an error unless
632    -fpermissive was given on the command line, in which case it issues
633    a warning.  Use this for things that really should be errors but we
634    want to support legacy code.
635
636    Returns true if the warning was printed, false if it was inhibited.  */
637
638 bool
639 permerror (location_t location, 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, location,
646                        permissive_error_kind ());
647   diagnostic.option_index = OPT_fpermissive;
648   va_end (ap);
649   return report_diagnostic (&diagnostic);
650 }
651
652 /* A hard error: the code is definitely ill-formed, and an object file
653    will not be produced.  */
654 void
655 error (const char *gmsgid, ...)
656 {
657   diagnostic_info diagnostic;
658   va_list ap;
659
660   va_start (ap, gmsgid);
661   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR);
662   report_diagnostic (&diagnostic);
663   va_end (ap);
664 }
665
666 /* A hard error: the code is definitely ill-formed, and an object file
667    will not be produced.  */
668 void
669 error_n (location_t location, int n, const char *singular_gmsgid,
670          const char *plural_gmsgid, ...)
671 {
672   diagnostic_info diagnostic;
673   va_list ap;
674
675   va_start (ap, plural_gmsgid);
676   diagnostic_set_info_translated (&diagnostic,
677                                   ngettext (singular_gmsgid, plural_gmsgid, n),
678                                   &ap, location, DK_ERROR);
679   report_diagnostic (&diagnostic);
680   va_end (ap);
681 }
682
683 /* Same as ebove, but use location LOC instead of input_location.  */
684 void
685 error_at (location_t loc, const char *gmsgid, ...)
686 {
687   diagnostic_info diagnostic;
688   va_list ap;
689
690   va_start (ap, gmsgid);
691   diagnostic_set_info (&diagnostic, gmsgid, &ap, loc, DK_ERROR);
692   report_diagnostic (&diagnostic);
693   va_end (ap);
694 }
695
696 /* "Sorry, not implemented."  Use for a language feature which is
697    required by the relevant specification but not implemented by GCC.
698    An object file will not be produced.  */
699 void
700 sorry (const char *gmsgid, ...)
701 {
702   diagnostic_info diagnostic;
703   va_list ap;
704
705   va_start (ap, gmsgid);
706   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_SORRY);
707   report_diagnostic (&diagnostic);
708   va_end (ap);
709 }
710
711 /* An error which is severe enough that we make no attempt to
712    continue.  Do not use this for internal consistency checks; that's
713    internal_error.  Use of this function should be rare.  */
714 void
715 fatal_error (const char *gmsgid, ...)
716 {
717   diagnostic_info diagnostic;
718   va_list ap;
719
720   va_start (ap, gmsgid);
721   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_FATAL);
722   report_diagnostic (&diagnostic);
723   va_end (ap);
724
725   gcc_unreachable ();
726 }
727
728 /* An internal consistency check has failed.  We make no attempt to
729    continue.  Note that unless there is debugging value to be had from
730    a more specific message, or some other good reason, you should use
731    abort () instead of calling this function directly.  */
732 void
733 internal_error (const char *gmsgid, ...)
734 {
735   diagnostic_info diagnostic;
736   va_list ap;
737
738   va_start (ap, gmsgid);
739   diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ICE);
740   report_diagnostic (&diagnostic);
741   va_end (ap);
742
743   gcc_unreachable ();
744 }
745 \f
746 /* Special case error functions.  Most are implemented in terms of the
747    above, or should be.  */
748
749 /* Print a diagnostic MSGID on FILE.  This is just fprintf, except it
750    runs its second argument through gettext.  */
751 void
752 fnotice (FILE *file, const char *cmsgid, ...)
753 {
754   va_list ap;
755
756   va_start (ap, cmsgid);
757   vfprintf (file, _(cmsgid), ap);
758   va_end (ap);
759 }
760
761 /* Inform the user that an error occurred while trying to report some
762    other error.  This indicates catastrophic internal inconsistencies,
763    so give up now.  But do try to flush out the previous error.
764    This mustn't use internal_error, that will cause infinite recursion.  */
765
766 static void
767 error_recursion (diagnostic_context *context)
768 {
769   diagnostic_info diagnostic;
770
771   if (context->lock < 3)
772     pp_flush (context->printer);
773
774   fnotice (stderr,
775            "Internal compiler error: Error reporting routines re-entered.\n");
776
777   /* Call diagnostic_action_after_output to get the "please submit a bug
778      report" message.  It only looks at the kind field of diagnostic_info.  */
779   diagnostic.kind = DK_ICE;
780   diagnostic_action_after_output (context, &diagnostic);
781
782   /* Do not use gcc_unreachable here; that goes through internal_error
783      and therefore would cause infinite recursion.  */
784   real_abort ();
785 }
786
787 /* Report an internal compiler error in a friendly manner.  This is
788    the function that gets called upon use of abort() in the source
789    code generally, thanks to a special macro.  */
790
791 void
792 fancy_abort (const char *file, int line, const char *function)
793 {
794   internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
795 }
796
797 /* Really call the system 'abort'.  This has to go right at the end of
798    this file, so that there are no functions after it that call abort
799    and get the system abort instead of our macro.  */
800 #undef abort
801 static void
802 real_abort (void)
803 {
804   abort ();
805 }