OSDN Git Service

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