OSDN Git Service

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