* config/sh/sh.c (sh_gimplify_va_arg_expr): Don't call
[official-gcc.git] / gcc / diagnostic.c
blobd297cdda0ca857c2de8ae49ac56a35a169099b4c
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>
6 This file is part of GCC.
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.
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.
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/>. */
23 /* This file implements the language independent aspect of diagnostic
24 message module. */
26 #include "config.h"
27 #include "system.h"
28 #include "coretypes.h"
29 #include "version.h"
30 #include "input.h"
31 #include "intl.h"
32 #include "diagnostic.h"
34 #define pedantic_warning_kind(DC) \
35 ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
36 #define permissive_error_kind(DC) ((DC)->permissive ? DK_WARNING : DK_ERROR)
37 #define permissive_error_option(DC) ((DC)->opt_permissive)
39 /* Prototypes. */
40 static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
42 static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
44 static void diagnostic_action_after_output (diagnostic_context *,
45 diagnostic_info *);
46 static void real_abort (void) ATTRIBUTE_NORETURN;
48 /* Name of program invoked, sans directories. */
50 const char *progname;
52 /* A diagnostic_context surrogate for stderr. */
53 static diagnostic_context global_diagnostic_context;
54 diagnostic_context *global_dc = &global_diagnostic_context;
57 /* Return a malloc'd string containing MSG formatted a la printf. The
58 caller is responsible for freeing the memory. */
59 static char *
60 build_message_string (const char *msg, ...)
62 char *str;
63 va_list ap;
65 va_start (ap, msg);
66 vasprintf (&str, msg, ap);
67 va_end (ap);
69 return str;
72 /* Same as diagnostic_build_prefix, but only the source FILE is given. */
73 char *
74 file_name_as_prefix (const char *f)
76 return build_message_string ("%s: ", f);
81 /* Initialize the diagnostic message outputting machinery. */
82 void
83 diagnostic_initialize (diagnostic_context *context, int n_opts)
85 int i;
87 /* Allocate a basic pretty-printer. Clients will replace this a
88 much more elaborated pretty-printer if they wish. */
89 context->printer = XNEW (pretty_printer);
90 pp_construct (context->printer, NULL, 0);
91 /* By default, diagnostics are sent to stderr. */
92 context->printer->buffer->stream = stderr;
93 /* By default, we emit prefixes once per message. */
94 context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
96 memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
97 context->some_warnings_are_errors = false;
98 context->warning_as_error_requested = false;
99 context->n_opts = n_opts;
100 context->classify_diagnostic = XNEWVEC (diagnostic_t, n_opts);
101 for (i = 0; i < n_opts; i++)
102 context->classify_diagnostic[i] = DK_UNSPECIFIED;
103 context->show_option_requested = false;
104 context->abort_on_error = false;
105 context->show_column = false;
106 context->pedantic_errors = false;
107 context->permissive = false;
108 context->opt_permissive = 0;
109 context->fatal_errors = false;
110 context->dc_inhibit_warnings = false;
111 context->dc_warn_system_headers = false;
112 context->max_errors = 0;
113 context->internal_error = NULL;
114 diagnostic_starter (context) = default_diagnostic_starter;
115 diagnostic_finalizer (context) = default_diagnostic_finalizer;
116 context->option_enabled = NULL;
117 context->option_state = NULL;
118 context->option_name = NULL;
119 context->last_module = 0;
120 context->x_data = NULL;
121 context->lock = 0;
122 context->inhibit_notes_p = false;
125 /* Do any cleaning up required after the last diagnostic is emitted. */
127 void
128 diagnostic_finish (diagnostic_context *context)
130 /* Some of the errors may actually have been warnings. */
131 if (context->some_warnings_are_errors)
133 /* -Werror was given. */
134 if (context->warning_as_error_requested)
135 pp_verbatim (context->printer,
136 _("%s: all warnings being treated as errors\n"),
137 progname);
138 /* At least one -Werror= was given. */
139 else
140 pp_verbatim (context->printer,
141 _("%s: some warnings being treated as errors\n"),
142 progname);
143 pp_flush (context->printer);
147 /* Initialize DIAGNOSTIC, where the message MSG has already been
148 translated. */
149 void
150 diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
151 va_list *args, location_t location,
152 diagnostic_t kind)
154 diagnostic->message.err_no = errno;
155 diagnostic->message.args_ptr = args;
156 diagnostic->message.format_spec = msg;
157 diagnostic->location = location;
158 diagnostic->override_column = 0;
159 diagnostic->kind = kind;
160 diagnostic->option_index = 0;
163 /* Initialize DIAGNOSTIC, where the message GMSGID has not yet been
164 translated. */
165 void
166 diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid,
167 va_list *args, location_t location,
168 diagnostic_t kind)
170 diagnostic_set_info_translated (diagnostic, _(gmsgid), args, location, kind);
173 /* Return a malloc'd string describing a location. The caller is
174 responsible for freeing the memory. */
175 char *
176 diagnostic_build_prefix (diagnostic_context *context,
177 diagnostic_info *diagnostic)
179 static const char *const diagnostic_kind_text[] = {
180 #define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
181 #include "diagnostic.def"
182 #undef DEFINE_DIAGNOSTIC_KIND
183 "must-not-happen"
185 const char *text = _(diagnostic_kind_text[diagnostic->kind]);
186 expanded_location s = expand_location (diagnostic->location);
187 if (diagnostic->override_column)
188 s.column = diagnostic->override_column;
189 gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
191 return
192 (s.file == NULL
193 ? build_message_string ("%s: %s", progname, text)
194 : context->show_column
195 ? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text)
196 : build_message_string ("%s:%d: %s", s.file, s.line, text));
199 /* Take any action which is expected to happen after the diagnostic
200 is written out. This function does not always return. */
201 static void
202 diagnostic_action_after_output (diagnostic_context *context,
203 diagnostic_info *diagnostic)
205 switch (diagnostic->kind)
207 case DK_DEBUG:
208 case DK_NOTE:
209 case DK_ANACHRONISM:
210 case DK_WARNING:
211 break;
213 case DK_ERROR:
214 case DK_SORRY:
215 if (context->abort_on_error)
216 real_abort ();
217 if (context->fatal_errors)
219 fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
220 diagnostic_finish (context);
221 exit (FATAL_EXIT_CODE);
223 if (context->max_errors != 0
224 && ((unsigned) (diagnostic_kind_count (context, DK_ERROR)
225 + diagnostic_kind_count (context, DK_SORRY))
226 >= context->max_errors))
228 fnotice (stderr,
229 "compilation terminated due to -fmax-errors=%u.\n",
230 context->max_errors);
231 diagnostic_finish (context);
232 exit (FATAL_EXIT_CODE);
234 break;
236 case DK_ICE:
237 if (context->abort_on_error)
238 real_abort ();
240 fnotice (stderr, "Please submit a full bug report,\n"
241 "with preprocessed source if appropriate.\n"
242 "See %s for instructions.\n", bug_report_url);
243 exit (ICE_EXIT_CODE);
245 case DK_FATAL:
246 if (context->abort_on_error)
247 real_abort ();
248 diagnostic_finish (context);
249 fnotice (stderr, "compilation terminated.\n");
250 exit (FATAL_EXIT_CODE);
252 default:
253 gcc_unreachable ();
257 void
258 diagnostic_report_current_module (diagnostic_context *context)
260 const struct line_map *map;
262 if (pp_needs_newline (context->printer))
264 pp_newline (context->printer);
265 pp_needs_newline (context->printer) = false;
268 if (input_location <= BUILTINS_LOCATION)
269 return;
271 map = linemap_lookup (line_table, input_location);
272 if (map && diagnostic_last_module_changed (context, map))
274 diagnostic_set_last_module (context, map);
275 if (! MAIN_FILE_P (map))
277 map = INCLUDED_FROM (line_table, map);
278 if (context->show_column)
279 pp_verbatim (context->printer,
280 "In file included from %s:%d:%d",
281 map->to_file,
282 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
283 else
284 pp_verbatim (context->printer,
285 "In file included from %s:%d",
286 map->to_file, LAST_SOURCE_LINE (map));
287 while (! MAIN_FILE_P (map))
289 map = INCLUDED_FROM (line_table, map);
290 pp_verbatim (context->printer,
291 ",\n from %s:%d",
292 map->to_file, LAST_SOURCE_LINE (map));
294 pp_verbatim (context->printer, ":");
295 pp_newline (context->printer);
300 void
301 default_diagnostic_starter (diagnostic_context *context,
302 diagnostic_info *diagnostic)
304 diagnostic_report_current_module (context);
305 pp_set_prefix (context->printer, diagnostic_build_prefix (context,
306 diagnostic));
309 void
310 default_diagnostic_finalizer (diagnostic_context *context,
311 diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
313 pp_destroy_prefix (context->printer);
316 /* Interface to specify diagnostic kind overrides. Returns the
317 previous setting, or DK_UNSPECIFIED if the parameters are out of
318 range. */
319 diagnostic_t
320 diagnostic_classify_diagnostic (diagnostic_context *context,
321 int option_index,
322 diagnostic_t new_kind,
323 location_t where)
325 diagnostic_t old_kind;
327 if (option_index <= 0
328 || option_index >= context->n_opts
329 || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
330 return DK_UNSPECIFIED;
332 old_kind = context->classify_diagnostic[option_index];
334 /* Handle pragmas separately, since we need to keep track of *where*
335 the pragmas were. */
336 if (where != UNKNOWN_LOCATION)
338 int i;
340 for (i = context->n_classification_history - 1; i >= 0; i --)
341 if (context->classification_history[i].option == option_index)
343 old_kind = context->classification_history[i].kind;
344 break;
347 i = context->n_classification_history;
348 context->classification_history =
349 (diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
350 * sizeof (diagnostic_classification_change_t));
351 context->classification_history[i].location = where;
352 context->classification_history[i].option = option_index;
353 context->classification_history[i].kind = new_kind;
354 context->n_classification_history ++;
356 else
357 context->classify_diagnostic[option_index] = new_kind;
359 return old_kind;
362 /* Save all diagnostic classifications in a stack. */
363 void
364 diagnostic_push_diagnostics (diagnostic_context *context, location_t where ATTRIBUTE_UNUSED)
366 context->push_list = (int *) xrealloc (context->push_list, (context->n_push + 1) * sizeof (int));
367 context->push_list[context->n_push ++] = context->n_classification_history;
370 /* Restore the topmost classification set off the stack. If the stack
371 is empty, revert to the state based on command line parameters. */
372 void
373 diagnostic_pop_diagnostics (diagnostic_context *context, location_t where)
375 int jump_to;
376 int i;
378 if (context->n_push)
379 jump_to = context->push_list [-- context->n_push];
380 else
381 jump_to = 0;
383 i = context->n_classification_history;
384 context->classification_history =
385 (diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
386 * sizeof (diagnostic_classification_change_t));
387 context->classification_history[i].location = where;
388 context->classification_history[i].option = jump_to;
389 context->classification_history[i].kind = DK_POP;
390 context->n_classification_history ++;
393 /* Report a diagnostic message (an error or a warning) as specified by
394 DC. This function is *the* subroutine in terms of which front-ends
395 should implement their specific diagnostic handling modules. The
396 front-end independent format specifiers are exactly those described
397 in the documentation of output_format.
398 Return true if a diagnostic was printed, false otherwise. */
400 bool
401 diagnostic_report_diagnostic (diagnostic_context *context,
402 diagnostic_info *diagnostic)
404 location_t location = diagnostic->location;
405 diagnostic_t orig_diag_kind = diagnostic->kind;
406 const char *saved_format_spec;
408 /* Give preference to being able to inhibit warnings, before they
409 get reclassified to something else. */
410 if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN)
411 && !diagnostic_report_warnings_p (context, location))
412 return false;
414 if (diagnostic->kind == DK_PEDWARN)
416 diagnostic->kind = pedantic_warning_kind (context);
417 /* We do this to avoid giving the message for -pedantic-errors. */
418 orig_diag_kind = diagnostic->kind;
421 if (diagnostic->kind == DK_NOTE && context->inhibit_notes_p)
422 return false;
424 if (context->lock > 0)
426 /* If we're reporting an ICE in the middle of some other error,
427 try to flush out the previous error, then let this one
428 through. Don't do this more than once. */
429 if (diagnostic->kind == DK_ICE && context->lock == 1)
430 pp_flush (context->printer);
431 else
432 error_recursion (context);
435 /* If the user requested that warnings be treated as errors, so be
436 it. Note that we do this before the next block so that
437 individual warnings can be overridden back to warnings with
438 -Wno-error=*. */
439 if (context->warning_as_error_requested
440 && diagnostic->kind == DK_WARNING)
442 diagnostic->kind = DK_ERROR;
445 if (diagnostic->option_index)
447 diagnostic_t diag_class = DK_UNSPECIFIED;
449 /* This tests if the user provided the appropriate -Wfoo or
450 -Wno-foo option. */
451 if (! context->option_enabled (diagnostic->option_index,
452 context->option_state))
453 return false;
455 /* This tests for #pragma diagnostic changes. */
456 if (context->n_classification_history > 0)
458 int i;
459 /* FIXME: Stupid search. Optimize later. */
460 for (i = context->n_classification_history - 1; i >= 0; i --)
462 if (context->classification_history[i].location <= location)
464 if (context->classification_history[i].kind == (int) DK_POP)
466 i = context->classification_history[i].option;
467 continue;
469 if (context->classification_history[i].option == diagnostic->option_index)
471 diag_class = context->classification_history[i].kind;
472 if (diag_class != DK_UNSPECIFIED)
473 diagnostic->kind = diag_class;
474 break;
479 /* This tests if the user provided the appropriate -Werror=foo
480 option. */
481 if (diag_class == DK_UNSPECIFIED
482 && context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
484 diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
486 /* This allows for future extensions, like temporarily disabling
487 warnings for ranges of source code. */
488 if (diagnostic->kind == DK_IGNORED)
489 return false;
492 if (orig_diag_kind == DK_WARNING && diagnostic->kind == DK_ERROR)
493 context->some_warnings_are_errors = true;
495 context->lock++;
497 if (diagnostic->kind == DK_ICE)
499 #ifndef ENABLE_CHECKING
500 /* When not checking, ICEs are converted to fatal errors when an
501 error has already occurred. This is counteracted by
502 abort_on_error. */
503 if ((diagnostic_kind_count (context, DK_ERROR) > 0
504 || diagnostic_kind_count (context, DK_SORRY) > 0)
505 && !context->abort_on_error)
507 expanded_location s = expand_location (diagnostic->location);
508 fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
509 s.file, s.line);
510 exit (ICE_EXIT_CODE);
512 #endif
513 if (context->internal_error)
514 (*context->internal_error) (context,
515 diagnostic->message.format_spec,
516 diagnostic->message.args_ptr);
518 ++diagnostic_kind_count (context, diagnostic->kind);
520 saved_format_spec = diagnostic->message.format_spec;
521 if (context->show_option_requested)
523 char *option_text;
525 option_text = context->option_name (context, diagnostic->option_index,
526 orig_diag_kind, diagnostic->kind);
528 if (option_text)
530 diagnostic->message.format_spec
531 = ACONCAT ((diagnostic->message.format_spec,
532 " ",
533 "[", option_text, "]",
534 NULL));
535 free (option_text);
538 diagnostic->message.locus = &diagnostic->location;
539 diagnostic->message.x_data = &diagnostic->x_data;
540 diagnostic->x_data = NULL;
541 pp_format (context->printer, &diagnostic->message);
542 (*diagnostic_starter (context)) (context, diagnostic);
543 pp_output_formatted_text (context->printer);
544 (*diagnostic_finalizer (context)) (context, diagnostic);
545 pp_flush (context->printer);
546 diagnostic_action_after_output (context, diagnostic);
547 diagnostic->message.format_spec = saved_format_spec;
548 diagnostic->x_data = NULL;
550 context->lock--;
552 return true;
555 /* Given a partial pathname as input, return another pathname that
556 shares no directory elements with the pathname of __FILE__. This
557 is used by fancy_abort() to print `Internal compiler error in expr.c'
558 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
560 const char *
561 trim_filename (const char *name)
563 static const char this_file[] = __FILE__;
564 const char *p = name, *q = this_file;
566 /* First skip any "../" in each filename. This allows us to give a proper
567 reference to a file in a subdirectory. */
568 while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2]))
569 p += 3;
571 while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2]))
572 q += 3;
574 /* Now skip any parts the two filenames have in common. */
575 while (*p == *q && *p != 0 && *q != 0)
576 p++, q++;
578 /* Now go backwards until the previous directory separator. */
579 while (p > name && !IS_DIR_SEPARATOR (p[-1]))
580 p--;
582 return p;
585 /* Standard error reporting routines in increasing order of severity.
586 All of these take arguments like printf. */
588 /* Text to be emitted verbatim to the error message stream; this
589 produces no prefix and disables line-wrapping. Use rarely. */
590 void
591 verbatim (const char *gmsgid, ...)
593 text_info text;
594 va_list ap;
596 va_start (ap, gmsgid);
597 text.err_no = errno;
598 text.args_ptr = &ap;
599 text.format_spec = _(gmsgid);
600 text.locus = NULL;
601 text.x_data = NULL;
602 pp_format_verbatim (global_dc->printer, &text);
603 pp_flush (global_dc->printer);
604 va_end (ap);
607 bool
608 emit_diagnostic (diagnostic_t kind, location_t location, int opt,
609 const char *gmsgid, ...)
611 diagnostic_info diagnostic;
612 va_list ap;
614 va_start (ap, gmsgid);
615 if (kind == DK_PERMERROR)
617 diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
618 permissive_error_kind (global_dc));
619 diagnostic.option_index = permissive_error_option (global_dc);
621 else {
622 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, kind);
623 if (kind == DK_WARNING || kind == DK_PEDWARN)
624 diagnostic.option_index = opt;
626 va_end (ap);
628 return report_diagnostic (&diagnostic);
631 /* An informative note at LOCATION. Use this for additional details on an error
632 message. */
633 void
634 inform (location_t location, const char *gmsgid, ...)
636 diagnostic_info diagnostic;
637 va_list ap;
639 va_start (ap, gmsgid);
640 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE);
641 report_diagnostic (&diagnostic);
642 va_end (ap);
645 /* An informative note at LOCATION. Use this for additional details on an
646 error message. */
647 void
648 inform_n (location_t location, int n, const char *singular_gmsgid,
649 const char *plural_gmsgid, ...)
651 diagnostic_info diagnostic;
652 va_list ap;
654 va_start (ap, plural_gmsgid);
655 diagnostic_set_info_translated (&diagnostic,
656 ngettext (singular_gmsgid, plural_gmsgid, n),
657 &ap, location, DK_NOTE);
658 report_diagnostic (&diagnostic);
659 va_end (ap);
662 /* A warning at INPUT_LOCATION. Use this for code which is correct according
663 to the relevant language specification but is likely to be buggy anyway.
664 Returns true if the warning was printed, false if it was inhibited. */
665 bool
666 warning (int opt, const char *gmsgid, ...)
668 diagnostic_info diagnostic;
669 va_list ap;
671 va_start (ap, gmsgid);
672 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING);
673 diagnostic.option_index = opt;
675 va_end (ap);
676 return report_diagnostic (&diagnostic);
679 /* A warning at LOCATION. Use this for code which is correct according to the
680 relevant language specification but is likely to be buggy anyway.
681 Returns true if the warning was printed, false if it was inhibited. */
683 bool
684 warning_at (location_t location, int opt, const char *gmsgid, ...)
686 diagnostic_info diagnostic;
687 va_list ap;
689 va_start (ap, gmsgid);
690 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING);
691 diagnostic.option_index = opt;
692 va_end (ap);
693 return report_diagnostic (&diagnostic);
696 /* A "pedantic" warning at LOCATION: issues a warning unless
697 -pedantic-errors was given on the command line, in which case it
698 issues an error. Use this for diagnostics required by the relevant
699 language standard, if you have chosen not to make them errors.
701 Note that these diagnostics are issued independent of the setting
702 of the -pedantic command-line switch. To get a warning enabled
703 only with that switch, use either "if (pedantic) pedwarn
704 (OPT_pedantic,...)" or just "pedwarn (OPT_pedantic,..)". To get a
705 pedwarn independently of the -pedantic switch use "pedwarn (0,...)".
707 Returns true if the warning was printed, false if it was inhibited. */
709 bool
710 pedwarn (location_t location, int opt, const char *gmsgid, ...)
712 diagnostic_info diagnostic;
713 va_list ap;
715 va_start (ap, gmsgid);
716 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
717 diagnostic.option_index = opt;
718 va_end (ap);
719 return report_diagnostic (&diagnostic);
722 /* A "permissive" error at LOCATION: issues an error unless
723 -fpermissive was given on the command line, in which case it issues
724 a warning. Use this for things that really should be errors but we
725 want to support legacy code.
727 Returns true if the warning was printed, false if it was inhibited. */
729 bool
730 permerror (location_t location, const char *gmsgid, ...)
732 diagnostic_info diagnostic;
733 va_list ap;
735 va_start (ap, gmsgid);
736 diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
737 permissive_error_kind (global_dc));
738 diagnostic.option_index = permissive_error_option (global_dc);
739 va_end (ap);
740 return report_diagnostic (&diagnostic);
743 /* A hard error: the code is definitely ill-formed, and an object file
744 will not be produced. */
745 void
746 error (const char *gmsgid, ...)
748 diagnostic_info diagnostic;
749 va_list ap;
751 va_start (ap, gmsgid);
752 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR);
753 report_diagnostic (&diagnostic);
754 va_end (ap);
757 /* A hard error: the code is definitely ill-formed, and an object file
758 will not be produced. */
759 void
760 error_n (location_t location, int n, const char *singular_gmsgid,
761 const char *plural_gmsgid, ...)
763 diagnostic_info diagnostic;
764 va_list ap;
766 va_start (ap, plural_gmsgid);
767 diagnostic_set_info_translated (&diagnostic,
768 ngettext (singular_gmsgid, plural_gmsgid, n),
769 &ap, location, DK_ERROR);
770 report_diagnostic (&diagnostic);
771 va_end (ap);
774 /* Same as ebove, but use location LOC instead of input_location. */
775 void
776 error_at (location_t loc, const char *gmsgid, ...)
778 diagnostic_info diagnostic;
779 va_list ap;
781 va_start (ap, gmsgid);
782 diagnostic_set_info (&diagnostic, gmsgid, &ap, loc, DK_ERROR);
783 report_diagnostic (&diagnostic);
784 va_end (ap);
787 /* "Sorry, not implemented." Use for a language feature which is
788 required by the relevant specification but not implemented by GCC.
789 An object file will not be produced. */
790 void
791 sorry (const char *gmsgid, ...)
793 diagnostic_info diagnostic;
794 va_list ap;
796 va_start (ap, gmsgid);
797 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_SORRY);
798 report_diagnostic (&diagnostic);
799 va_end (ap);
802 /* Return true if an error or a "sorry" has been seen. Various
803 processing is disabled after errors. */
804 bool
805 seen_error (void)
807 return errorcount || sorrycount;
810 /* An error which is severe enough that we make no attempt to
811 continue. Do not use this for internal consistency checks; that's
812 internal_error. Use of this function should be rare. */
813 void
814 fatal_error (const char *gmsgid, ...)
816 diagnostic_info diagnostic;
817 va_list ap;
819 va_start (ap, gmsgid);
820 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_FATAL);
821 report_diagnostic (&diagnostic);
822 va_end (ap);
824 gcc_unreachable ();
827 /* An internal consistency check has failed. We make no attempt to
828 continue. Note that unless there is debugging value to be had from
829 a more specific message, or some other good reason, you should use
830 abort () instead of calling this function directly. */
831 void
832 internal_error (const char *gmsgid, ...)
834 diagnostic_info diagnostic;
835 va_list ap;
837 va_start (ap, gmsgid);
838 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ICE);
839 report_diagnostic (&diagnostic);
840 va_end (ap);
842 gcc_unreachable ();
845 /* Special case error functions. Most are implemented in terms of the
846 above, or should be. */
848 /* Print a diagnostic MSGID on FILE. This is just fprintf, except it
849 runs its second argument through gettext. */
850 void
851 fnotice (FILE *file, const char *cmsgid, ...)
853 va_list ap;
855 va_start (ap, cmsgid);
856 vfprintf (file, _(cmsgid), ap);
857 va_end (ap);
860 /* Inform the user that an error occurred while trying to report some
861 other error. This indicates catastrophic internal inconsistencies,
862 so give up now. But do try to flush out the previous error.
863 This mustn't use internal_error, that will cause infinite recursion. */
865 static void
866 error_recursion (diagnostic_context *context)
868 diagnostic_info diagnostic;
870 if (context->lock < 3)
871 pp_flush (context->printer);
873 fnotice (stderr,
874 "Internal compiler error: Error reporting routines re-entered.\n");
876 /* Call diagnostic_action_after_output to get the "please submit a bug
877 report" message. It only looks at the kind field of diagnostic_info. */
878 diagnostic.kind = DK_ICE;
879 diagnostic_action_after_output (context, &diagnostic);
881 /* Do not use gcc_unreachable here; that goes through internal_error
882 and therefore would cause infinite recursion. */
883 real_abort ();
886 /* Report an internal compiler error in a friendly manner. This is
887 the function that gets called upon use of abort() in the source
888 code generally, thanks to a special macro. */
890 void
891 fancy_abort (const char *file, int line, const char *function)
893 internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
896 /* Really call the system 'abort'. This has to go right at the end of
897 this file, so that there are no functions after it that call abort
898 and get the system abort instead of our macro. */
899 #undef abort
900 static void
901 real_abort (void)
903 abort ();