]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/diagnostic.c
Update copyright years in gcc/
[thirdparty/gcc.git] / gcc / diagnostic.c
CommitLineData
47b69537 1/* Language-independent diagnostic subroutines for the GNU Compiler Collection
23a5b65a 2 Copyright (C) 1999-2014 Free Software Foundation, Inc.
406a65d0 3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
6ed551b4 4
1322177d 5This file is part of GCC.
6ed551b4 6
1322177d
LB
7GCC is free software; you can redistribute it and/or modify it under
8the terms of the GNU General Public License as published by the Free
9dcd6f09 9Software Foundation; either version 3, or (at your option) any later
1322177d 10version.
6ed551b4 11
1322177d
LB
12GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13WARRANTY; without even the implied warranty of MERCHANTABILITY or
14FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15for more details.
6ed551b4
GDR
16
17You should have received a copy of the GNU General Public License
9dcd6f09
NC
18along with GCC; see the file COPYING3. If not see
19<http://www.gnu.org/licenses/>. */
6ed551b4
GDR
20
21
4eb00163 22/* This file implements the language independent aspect of diagnostic
6ed551b4
GDR
23 message module. */
24
25#include "config.h"
6ed551b4 26#include "system.h"
4977bab6 27#include "coretypes.h"
a757585a 28#include "version.h"
d83697f4 29#include "demangle.h"
6ed551b4 30#include "input.h"
6ed551b4 31#include "intl.h"
d83697f4 32#include "backtrace.h"
345ed1fe 33#include "diagnostic.h"
4b84d650 34#include "diagnostic-color.h"
6ed551b4 35
da6ca2b5
GDR
36#include <new> // For placement new.
37
243fbddd
JM
38#define pedantic_warning_kind(DC) \
39 ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
40#define permissive_error_kind(DC) ((DC)->permissive ? DK_WARNING : DK_ERROR)
5f0f4a3b 41#define permissive_error_option(DC) ((DC)->opt_permissive)
c707a408 42
30f7a378 43/* Prototypes. */
b6fe0bb8 44static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
79a490a9 45
79a490a9 46static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
52249a2e 47
79a490a9
AJ
48static void diagnostic_action_after_output (diagnostic_context *,
49 diagnostic_info *);
50static void real_abort (void) ATTRIBUTE_NORETURN;
fbfc1192 51
1da2ed5f
JM
52/* Name of program invoked, sans directories. */
53
54const char *progname;
55
f68fc4db
GDR
56/* A diagnostic_context surrogate for stderr. */
57static diagnostic_context global_diagnostic_context;
58diagnostic_context *global_dc = &global_diagnostic_context;
6ed551b4 59\f
59650e48
ZW
60/* Return a malloc'd string containing MSG formatted a la printf. The
61 caller is responsible for freeing the memory. */
36244024 62static char *
e34d07f2 63build_message_string (const char *msg, ...)
b903d81e 64{
36244024 65 char *str;
e34d07f2 66 va_list ap;
b903d81e 67
e34d07f2 68 va_start (ap, msg);
59650e48 69 vasprintf (&str, msg, ap);
e34d07f2 70 va_end (ap);
b903d81e
GDR
71
72 return str;
73}
74
95bd1dd7 75/* Same as diagnostic_build_prefix, but only the source FILE is given. */
24805e80 76char *
e78e8a0b 77file_name_as_prefix (diagnostic_context *context, const char *f)
24805e80 78{
e78e8a0b
JJ
79 const char *locus_cs
80 = colorize_start (pp_show_color (context->printer), "locus");
81 const char *locus_ce = colorize_stop (pp_show_color (context->printer));
82 return build_message_string ("%s%s:%s ", locus_cs, f, locus_ce);
24805e80
GDR
83}
84
47b69537 85
6ed551b4 86\f
9fec0042
MLI
87/* Return the value of the getenv("COLUMNS") as an integer. If the
88 value is not set to a positive integer, then return INT_MAX. */
89static int
90getenv_columns (void)
91{
92 const char * s = getenv ("COLUMNS");
93 if (s != NULL) {
94 int n = atoi (s);
95 if (n > 0)
96 return n;
97 }
98 return INT_MAX;
99}
100
101/* Set caret_max_width to value. */
102void
103diagnostic_set_caret_max_width (diagnostic_context *context, int value)
104{
105 /* One minus to account for the leading empty space. */
106 value = value ? value - 1
025311c4 107 : (isatty (fileno (pp_buffer (context->printer)->stream))
9fec0042
MLI
108 ? getenv_columns () - 1: INT_MAX);
109
110 if (value <= 0)
111 value = INT_MAX;
112
113 context->caret_max_width = value;
114}
115
47b69537
GDR
116/* Initialize the diagnostic message outputting machinery. */
117void
5f0f4a3b 118diagnostic_initialize (diagnostic_context *context, int n_opts)
47b69537 119{
5f0f4a3b
JM
120 int i;
121
b6fe0bb8
GDR
122 /* Allocate a basic pretty-printer. Clients will replace this a
123 much more elaborated pretty-printer if they wish. */
5ed6ace5 124 context->printer = XNEW (pretty_printer);
da6ca2b5 125 new (context->printer) pretty_printer ();
47b69537 126
b6fe0bb8 127 memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
d0b8780d 128 context->some_warnings_are_errors = false;
7783b402 129 context->warning_as_error_requested = false;
5f0f4a3b
JM
130 context->n_opts = n_opts;
131 context->classify_diagnostic = XNEWVEC (diagnostic_t, n_opts);
132 for (i = 0; i < n_opts; i++)
133 context->classify_diagnostic[i] = DK_UNSPECIFIED;
9fec0042
MLI
134 context->show_caret = false;
135 diagnostic_set_caret_max_width (context, pp_line_cutoff (context->printer));
2098fe9e 136 context->show_option_requested = false;
b6fe0bb8 137 context->abort_on_error = false;
5f0f4a3b
JM
138 context->show_column = false;
139 context->pedantic_errors = false;
140 context->permissive = false;
141 context->opt_permissive = 0;
142 context->fatal_errors = false;
e3339d0f
JM
143 context->dc_inhibit_warnings = false;
144 context->dc_warn_system_headers = false;
3a789837 145 context->max_errors = 0;
b6fe0bb8 146 context->internal_error = NULL;
47b69537
GDR
147 diagnostic_starter (context) = default_diagnostic_starter;
148 diagnostic_finalizer (context) = default_diagnostic_finalizer;
5f0f4a3b 149 context->option_enabled = NULL;
46625112 150 context->option_state = NULL;
5f0f4a3b 151 context->option_name = NULL;
1b8b126f 152 context->last_location = UNKNOWN_LOCATION;
b6fe0bb8 153 context->last_module = 0;
cf835838 154 context->x_data = NULL;
b6fe0bb8 155 context->lock = 0;
0e94b750 156 context->inhibit_notes_p = false;
47b69537
GDR
157}
158
d0b8780d
MLI
159/* Do any cleaning up required after the last diagnostic is emitted. */
160
161void
162diagnostic_finish (diagnostic_context *context)
163{
164 /* Some of the errors may actually have been warnings. */
165 if (context->some_warnings_are_errors)
166 {
167 /* -Werror was given. */
168 if (context->warning_as_error_requested)
169 pp_verbatim (context->printer,
1f01c3ec 170 _("%s: all warnings being treated as errors"),
d0b8780d
MLI
171 progname);
172 /* At least one -Werror= was given. */
173 else
174 pp_verbatim (context->printer,
1f01c3ec 175 _("%s: some warnings being treated as errors"),
d0b8780d 176 progname);
f8923f7e 177 pp_newline_and_flush (context->printer);
d0b8780d
MLI
178 }
179}
180
178b58b5
JM
181/* Initialize DIAGNOSTIC, where the message MSG has already been
182 translated. */
47b69537 183void
178b58b5
JM
184diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
185 va_list *args, location_t location,
186 diagnostic_t kind)
47b69537 187{
fa6ef813 188 diagnostic->message.err_no = errno;
47b69537 189 diagnostic->message.args_ptr = args;
178b58b5 190 diagnostic->message.format_spec = msg;
d5706a1e 191 diagnostic->location = location;
148e4216 192 diagnostic->override_column = 0;
47b69537 193 diagnostic->kind = kind;
ccf08a6e 194 diagnostic->option_index = 0;
47b69537
GDR
195}
196
178b58b5
JM
197/* Initialize DIAGNOSTIC, where the message GMSGID has not yet been
198 translated. */
199void
200diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid,
201 va_list *args, location_t location,
202 diagnostic_t kind)
203{
204 diagnostic_set_info_translated (diagnostic, _(gmsgid), args, location, kind);
205}
206
47b69537
GDR
207/* Return a malloc'd string describing a location. The caller is
208 responsible for freeing the memory. */
209char *
243fbddd 210diagnostic_build_prefix (diagnostic_context *context,
dfa32261 211 const diagnostic_info *diagnostic)
47b69537 212{
ef9772c8 213 static const char *const diagnostic_kind_text[] = {
4b84d650 214#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (T),
4b1d52c7
GDR
215#include "diagnostic.def"
216#undef DEFINE_DIAGNOSTIC_KIND
217 "must-not-happen"
218 };
4b84d650
JJ
219 static const char *const diagnostic_kind_color[] = {
220#define DEFINE_DIAGNOSTIC_KIND(K, T, C) (C),
221#include "diagnostic.def"
222#undef DEFINE_DIAGNOSTIC_KIND
223 NULL
224 };
255508dd 225 const char *text = _(diagnostic_kind_text[diagnostic->kind]);
4b84d650
JJ
226 const char *text_cs = "", *text_ce = "";
227 const char *locus_cs, *locus_ce;
228 pretty_printer *pp = context->printer;
229
230 if (diagnostic_kind_color[diagnostic->kind])
231 {
232 text_cs = colorize_start (pp_show_color (pp),
233 diagnostic_kind_color[diagnostic->kind]);
234 text_ce = colorize_stop (pp_show_color (pp));
235 }
236 locus_cs = colorize_start (pp_show_color (pp), "locus");
237 locus_ce = colorize_stop (pp_show_color (pp));
238
7eb918cc 239 expanded_location s = expand_location_to_spelling_point (diagnostic->location);
148e4216
JM
240 if (diagnostic->override_column)
241 s.column = diagnostic->override_column;
ced3f397 242 gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
4b1d52c7 243
255508dd
PB
244 return
245 (s.file == NULL
4b84d650
JJ
246 ? build_message_string ("%s%s:%s %s%s%s", locus_cs, progname, locus_ce,
247 text_cs, text, text_ce)
97f1f314
PC
248 : !strcmp (s.file, N_("<built-in>"))
249 ? build_message_string ("%s%s:%s %s%s%s", locus_cs, s.file, locus_ce,
250 text_cs, text, text_ce)
243fbddd 251 : context->show_column
4b84d650
JJ
252 ? build_message_string ("%s%s:%d:%d:%s %s%s%s", locus_cs, s.file, s.line,
253 s.column, locus_ce, text_cs, text, text_ce)
254 : build_message_string ("%s%s:%d:%s %s%s%s", locus_cs, s.file, s.line, locus_ce,
255 text_cs, text, text_ce));
47b69537
GDR
256}
257
9fec0042
MLI
258/* If LINE is longer than MAX_WIDTH, and COLUMN is not smaller than
259 MAX_WIDTH by some margin, then adjust the start of the line such
260 that the COLUMN is smaller than MAX_WIDTH minus the margin. The
261 margin is either 10 characters or the difference between the column
7f4d640c 262 and the length of the line, whatever is smaller. */
9fec0042 263static const char *
7f4d640c 264adjust_line (const char *line, int max_width, int *column_p)
9fec0042
MLI
265{
266 int right_margin = 10;
7f4d640c 267 int line_width = strlen (line);
9fec0042
MLI
268 int column = *column_p;
269
c3284718 270 right_margin = MIN (line_width - column, right_margin);
9fec0042
MLI
271 right_margin = max_width - right_margin;
272 if (line_width >= max_width && column > right_margin)
273 {
274 line += column - right_margin;
275 *column_p = right_margin;
276 }
277 return line;
278}
279
280/* Print the physical source line corresponding to the location of
281 this diagnostics, and a caret indicating the precise column. */
282void
283diagnostic_show_locus (diagnostic_context * context,
284 const diagnostic_info *diagnostic)
285{
286 const char *line;
287 char *buffer;
288 expanded_location s;
289 int max_width;
290 const char *saved_prefix;
4b84d650 291 const char *caret_cs, *caret_ce;
9fec0042
MLI
292
293 if (!context->show_caret
1b8b126f
MLI
294 || diagnostic->location <= BUILTINS_LOCATION
295 || diagnostic->location == context->last_location)
9fec0042
MLI
296 return;
297
1b8b126f 298 context->last_location = diagnostic->location;
7eb918cc 299 s = expand_location_to_spelling_point (diagnostic->location);
7f4d640c 300 line = location_get_source_line (s);
9fec0042
MLI
301 if (line == NULL)
302 return;
303
304 max_width = context->caret_max_width;
7f4d640c 305 line = adjust_line (line, max_width, &(s.column));
9fec0042
MLI
306
307 pp_newline (context->printer);
308 saved_prefix = pp_get_prefix (context->printer);
309 pp_set_prefix (context->printer, NULL);
07838b13 310 pp_space (context->printer);
7f4d640c 311 while (max_width > 0 && *line != '\0')
9fec0042
MLI
312 {
313 char c = *line == '\t' ? ' ' : *line;
314 pp_character (context->printer, c);
315 max_width--;
316 line++;
317 }
318 pp_newline (context->printer);
4b84d650
JJ
319 caret_cs = colorize_start (pp_show_color (context->printer), "caret");
320 caret_ce = colorize_stop (pp_show_color (context->printer));
321
9fec0042 322 /* pp_printf does not implement %*c. */
4b84d650
JJ
323 size_t len = s.column + 3 + strlen (caret_cs) + strlen (caret_ce);
324 buffer = XALLOCAVEC (char, len);
325 snprintf (buffer, len, "%s %*c%s", caret_cs, s.column, '^', caret_ce);
9fec0042
MLI
326 pp_string (context->printer, buffer);
327 pp_set_prefix (context->printer, saved_prefix);
328}
329
d83697f4
ILT
330/* Functions at which to stop the backtrace print. It's not
331 particularly helpful to print the callers of these functions. */
332
333static const char * const bt_stop[] =
334{
335 "main",
336 "toplev_main",
337 "execute_one_pass",
338 "compile_file",
339};
340
341/* A callback function passed to the backtrace_full function. */
342
343static int
344bt_callback (void *data, uintptr_t pc, const char *filename, int lineno,
345 const char *function)
346{
347 int *pcount = (int *) data;
348
349 /* If we don't have any useful information, don't print
350 anything. */
351 if (filename == NULL && function == NULL)
352 return 0;
353
354 /* Skip functions in diagnostic.c. */
355 if (*pcount == 0
356 && filename != NULL
c3284718 357 && strcmp (lbasename (filename), "diagnostic.c") == 0)
d83697f4
ILT
358 return 0;
359
360 /* Print up to 20 functions. We could make this a --param, but
361 since this is only for debugging just use a constant for now. */
362 if (*pcount >= 20)
363 {
364 /* Returning a non-zero value stops the backtrace. */
365 return 1;
366 }
367 ++*pcount;
368
369 char *alc = NULL;
370 if (function != NULL)
371 {
372 char *str = cplus_demangle_v3 (function,
373 (DMGL_VERBOSE | DMGL_ANSI
374 | DMGL_GNU_V3 | DMGL_PARAMS));
375 if (str != NULL)
376 {
377 alc = str;
378 function = str;
379 }
380
381 for (size_t i = 0; i < ARRAY_SIZE (bt_stop); ++i)
382 {
383 size_t len = strlen (bt_stop[i]);
384 if (strncmp (function, bt_stop[i], len) == 0
385 && (function[len] == '\0' || function[len] == '('))
386 {
387 if (alc != NULL)
388 free (alc);
389 /* Returning a non-zero value stops the backtrace. */
390 return 1;
391 }
392 }
393 }
394
395 fprintf (stderr, "0x%lx %s\n\t%s:%d\n",
a67a73fd 396 (unsigned long) pc,
d83697f4
ILT
397 function == NULL ? "???" : function,
398 filename == NULL ? "???" : filename,
399 lineno);
400
401 if (alc != NULL)
402 free (alc);
403
404 return 0;
405}
406
407/* A callback function passed to the backtrace_full function. This is
408 called if backtrace_full has an error. */
409
410static void
411bt_err_callback (void *data ATTRIBUTE_UNUSED, const char *msg, int errnum)
412{
413 if (errnum < 0)
414 {
415 /* This means that no debug info was available. Just quietly
416 skip printing backtrace info. */
417 return;
418 }
419 fprintf (stderr, "%s%s%s\n", msg, errnum == 0 ? "" : ": ",
420 errnum == 0 ? "" : xstrerror (errnum));
421}
422
9804f5fb
ZW
423/* Take any action which is expected to happen after the diagnostic
424 is written out. This function does not always return. */
425static void
79a490a9
AJ
426diagnostic_action_after_output (diagnostic_context *context,
427 diagnostic_info *diagnostic)
9804f5fb
ZW
428{
429 switch (diagnostic->kind)
430 {
431 case DK_DEBUG:
432 case DK_NOTE:
433 case DK_ANACHRONISM:
434 case DK_WARNING:
435 break;
436
437 case DK_ERROR:
438 case DK_SORRY:
439 if (context->abort_on_error)
440 real_abort ();
243fbddd 441 if (context->fatal_errors)
c65a01af
RG
442 {
443 fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
d0b8780d 444 diagnostic_finish (context);
c65a01af
RG
445 exit (FATAL_EXIT_CODE);
446 }
3a789837
NF
447 if (context->max_errors != 0
448 && ((unsigned) (diagnostic_kind_count (context, DK_ERROR)
449 + diagnostic_kind_count (context, DK_SORRY))
450 >= context->max_errors))
451 {
452 fnotice (stderr,
453 "compilation terminated due to -fmax-errors=%u.\n",
454 context->max_errors);
455 diagnostic_finish (context);
456 exit (FATAL_EXIT_CODE);
457 }
9804f5fb
ZW
458 break;
459
460 case DK_ICE:
d83697f4
ILT
461 {
462 struct backtrace_state *state =
463 backtrace_create_state (NULL, 0, bt_err_callback, NULL);
464 int count = 0;
465 if (state != NULL)
466 backtrace_full (state, 2, bt_callback, bt_err_callback,
467 (void *) &count);
468
469 if (context->abort_on_error)
470 real_abort ();
471
472 fnotice (stderr, "Please submit a full bug report,\n"
473 "with preprocessed source if appropriate.\n");
474 if (count > 0)
475 fnotice (stderr,
476 ("Please include the complete backtrace "
477 "with any bug report.\n"));
478 fnotice (stderr, "See %s for instructions.\n", bug_report_url);
9804f5fb 479
d83697f4
ILT
480 exit (ICE_EXIT_CODE);
481 }
9804f5fb
ZW
482
483 case DK_FATAL:
484 if (context->abort_on_error)
485 real_abort ();
d0b8780d 486 diagnostic_finish (context);
9804f5fb
ZW
487 fnotice (stderr, "compilation terminated.\n");
488 exit (FATAL_EXIT_CODE);
489
490 default:
d5706a1e 491 gcc_unreachable ();
9804f5fb
ZW
492 }
493}
494
6ed551b4 495void
07a0b324 496diagnostic_report_current_module (diagnostic_context *context, location_t where)
6ed551b4 497{
07a0b324 498 const struct line_map *map = NULL;
6ed551b4 499
b6fe0bb8 500 if (pp_needs_newline (context->printer))
59650e48 501 {
b6fe0bb8
GDR
502 pp_newline (context->printer);
503 pp_needs_newline (context->printer) = false;
59650e48 504 }
6ed551b4 505
07a0b324 506 if (where <= BUILTINS_LOCATION)
966e8f4d
TT
507 return;
508
07a0b324
TT
509 linemap_resolve_location (line_table, where,
510 LRK_MACRO_DEFINITION_LOCATION,
511 &map);
512
966e8f4d 513 if (map && diagnostic_last_module_changed (context, map))
59650e48 514 {
966e8f4d
TT
515 diagnostic_set_last_module (context, map);
516 if (! MAIN_FILE_P (map))
6773e15f 517 {
966e8f4d 518 map = INCLUDED_FROM (line_table, map);
243fbddd 519 if (context->show_column)
e74fe492 520 pp_verbatim (context->printer,
2e55d062 521 "In file included from %r%s:%d:%d%R", "locus",
46427374 522 LINEMAP_FILE (map),
e74fe492
AH
523 LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
524 else
525 pp_verbatim (context->printer,
2e55d062 526 "In file included from %r%s:%d%R", "locus",
46427374 527 LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
966e8f4d
TT
528 while (! MAIN_FILE_P (map))
529 {
530 map = INCLUDED_FROM (line_table, map);
531 pp_verbatim (context->printer,
2e55d062 532 ",\n from %r%s:%d%R", "locus",
46427374 533 LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
966e8f4d
TT
534 }
535 pp_verbatim (context->printer, ":");
536 pp_newline (context->printer);
6773e15f 537 }
59650e48
ZW
538 }
539}
400500c4 540
4537ec0c 541void
79a490a9
AJ
542default_diagnostic_starter (diagnostic_context *context,
543 diagnostic_info *diagnostic)
6ed551b4 544{
07a0b324 545 diagnostic_report_current_module (context, diagnostic->location);
243fbddd
JM
546 pp_set_prefix (context->printer, diagnostic_build_prefix (context,
547 diagnostic));
59650e48 548}
6ed551b4 549
4537ec0c 550void
dfa32261 551default_diagnostic_finalizer (diagnostic_context *context ATTRIBUTE_UNUSED,
cbd13f8a 552 diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
59650e48 553{
6ed551b4
GDR
554}
555
79cf5994
DD
556/* Interface to specify diagnostic kind overrides. Returns the
557 previous setting, or DK_UNSPECIFIED if the parameters are out of
3c8ca1ab
EB
558 range. If OPTION_INDEX is zero, the new setting is for all the
559 diagnostics. */
79cf5994
DD
560diagnostic_t
561diagnostic_classify_diagnostic (diagnostic_context *context,
562 int option_index,
cd7fe53b
DD
563 diagnostic_t new_kind,
564 location_t where)
79cf5994
DD
565{
566 diagnostic_t old_kind;
567
3c8ca1ab 568 if (option_index < 0
5f0f4a3b 569 || option_index >= context->n_opts
79cf5994
DD
570 || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
571 return DK_UNSPECIFIED;
572
573 old_kind = context->classify_diagnostic[option_index];
cd7fe53b
DD
574
575 /* Handle pragmas separately, since we need to keep track of *where*
576 the pragmas were. */
577 if (where != UNKNOWN_LOCATION)
578 {
579 int i;
580
581 for (i = context->n_classification_history - 1; i >= 0; i --)
582 if (context->classification_history[i].option == option_index)
583 {
584 old_kind = context->classification_history[i].kind;
585 break;
586 }
587
588 i = context->n_classification_history;
589 context->classification_history =
590 (diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
591 * sizeof (diagnostic_classification_change_t));
592 context->classification_history[i].location = where;
593 context->classification_history[i].option = option_index;
594 context->classification_history[i].kind = new_kind;
595 context->n_classification_history ++;
596 }
597 else
598 context->classify_diagnostic[option_index] = new_kind;
599
79cf5994
DD
600 return old_kind;
601}
602
cd7fe53b
DD
603/* Save all diagnostic classifications in a stack. */
604void
605diagnostic_push_diagnostics (diagnostic_context *context, location_t where ATTRIBUTE_UNUSED)
606{
607 context->push_list = (int *) xrealloc (context->push_list, (context->n_push + 1) * sizeof (int));
608 context->push_list[context->n_push ++] = context->n_classification_history;
609}
610
611/* Restore the topmost classification set off the stack. If the stack
612 is empty, revert to the state based on command line parameters. */
613void
614diagnostic_pop_diagnostics (diagnostic_context *context, location_t where)
615{
616 int jump_to;
617 int i;
618
619 if (context->n_push)
620 jump_to = context->push_list [-- context->n_push];
621 else
622 jump_to = 0;
623
624 i = context->n_classification_history;
625 context->classification_history =
626 (diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
627 * sizeof (diagnostic_classification_change_t));
628 context->classification_history[i].location = where;
629 context->classification_history[i].option = jump_to;
630 context->classification_history[i].kind = DK_POP;
631 context->n_classification_history ++;
632}
633
59650e48
ZW
634/* Report a diagnostic message (an error or a warning) as specified by
635 DC. This function is *the* subroutine in terms of which front-ends
636 should implement their specific diagnostic handling modules. The
637 front-end independent format specifiers are exactly those described
b8698a0f 638 in the documentation of output_format.
71205d17 639 Return true if a diagnostic was printed, false otherwise. */
400500c4 640
71205d17 641bool
79a490a9
AJ
642diagnostic_report_diagnostic (diagnostic_context *context,
643 diagnostic_info *diagnostic)
400500c4 644{
aa14403d 645 location_t location = diagnostic->location;
d0b8780d 646 diagnostic_t orig_diag_kind = diagnostic->kind;
52249a2e 647 const char *saved_format_spec;
4e2bae26
MLI
648
649 /* Give preference to being able to inhibit warnings, before they
650 get reclassified to something else. */
71205d17 651 if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN)
5f0f4a3b 652 && !diagnostic_report_warnings_p (context, location))
71205d17
MLI
653 return false;
654
b8698a0f 655 if (diagnostic->kind == DK_PEDWARN)
d0b8780d 656 {
243fbddd 657 diagnostic->kind = pedantic_warning_kind (context);
d0b8780d
MLI
658 /* We do this to avoid giving the message for -pedantic-errors. */
659 orig_diag_kind = diagnostic->kind;
660 }
0e94b750
MLI
661
662 if (diagnostic->kind == DK_NOTE && context->inhibit_notes_p)
663 return false;
b8698a0f 664
d5706a1e
ZW
665 if (context->lock > 0)
666 {
667 /* If we're reporting an ICE in the middle of some other error,
668 try to flush out the previous error, then let this one
669 through. Don't do this more than once. */
670 if (diagnostic->kind == DK_ICE && context->lock == 1)
f8923f7e 671 pp_newline_and_flush (context->printer);
d5706a1e
ZW
672 else
673 error_recursion (context);
674 }
675
4e2bae26
MLI
676 /* If the user requested that warnings be treated as errors, so be
677 it. Note that we do this before the next block so that
678 individual warnings can be overridden back to warnings with
679 -Wno-error=*. */
680 if (context->warning_as_error_requested
681 && diagnostic->kind == DK_WARNING)
682 {
683 diagnostic->kind = DK_ERROR;
4e2bae26 684 }
b8698a0f 685
0c3641b0
MLI
686 if (diagnostic->option_index
687 && diagnostic->option_index != permissive_error_option (context))
79cf5994 688 {
cd7fe53b
DD
689 diagnostic_t diag_class = DK_UNSPECIFIED;
690
79cf5994
DD
691 /* This tests if the user provided the appropriate -Wfoo or
692 -Wno-foo option. */
46625112
JM
693 if (! context->option_enabled (diagnostic->option_index,
694 context->option_state))
71205d17 695 return false;
cd7fe53b
DD
696
697 /* This tests for #pragma diagnostic changes. */
698 if (context->n_classification_history > 0)
699 {
cd7fe53b 700 /* FIXME: Stupid search. Optimize later. */
3c8ca1ab 701 for (int i = context->n_classification_history - 1; i >= 0; i --)
cd7fe53b 702 {
46427374
TT
703 if (linemap_location_before_p
704 (line_table,
705 context->classification_history[i].location,
706 location))
cd7fe53b
DD
707 {
708 if (context->classification_history[i].kind == (int) DK_POP)
709 {
710 i = context->classification_history[i].option;
711 continue;
712 }
3c8ca1ab
EB
713 int option = context->classification_history[i].option;
714 /* The option 0 is for all the diagnostics. */
715 if (option == 0 || option == diagnostic->option_index)
cd7fe53b
DD
716 {
717 diag_class = context->classification_history[i].kind;
718 if (diag_class != DK_UNSPECIFIED)
719 diagnostic->kind = diag_class;
720 break;
721 }
722 }
723 }
724 }
79cf5994
DD
725 /* This tests if the user provided the appropriate -Werror=foo
726 option. */
cd7fe53b
DD
727 if (diag_class == DK_UNSPECIFIED
728 && context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
4e2bae26
MLI
729 {
730 diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
4e2bae26 731 }
c0220ea4 732 /* This allows for future extensions, like temporarily disabling
79cf5994
DD
733 warnings for ranges of source code. */
734 if (diagnostic->kind == DK_IGNORED)
71205d17 735 return false;
79cf5994 736 }
2098fe9e 737
d0b8780d
MLI
738 if (orig_diag_kind == DK_WARNING && diagnostic->kind == DK_ERROR)
739 context->some_warnings_are_errors = true;
4e2bae26 740
d5706a1e 741 context->lock++;
400500c4 742
b8698a0f 743 if (diagnostic->kind == DK_ICE)
59650e48 744 {
52249a2e
MLI
745#ifndef ENABLE_CHECKING
746 /* When not checking, ICEs are converted to fatal errors when an
747 error has already occurred. This is counteracted by
748 abort_on_error. */
749 if ((diagnostic_kind_count (context, DK_ERROR) > 0
750 || diagnostic_kind_count (context, DK_SORRY) > 0)
751 && !context->abort_on_error)
752 {
753 expanded_location s = expand_location (diagnostic->location);
754 fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
755 s.file, s.line);
756 exit (ICE_EXIT_CODE);
757 }
758#endif
759 if (context->internal_error)
a13812e2
JM
760 (*context->internal_error) (context,
761 diagnostic->message.format_spec,
52249a2e 762 diagnostic->message.args_ptr);
43db5b3c 763 }
37e99116
JJ
764 if (diagnostic->kind == DK_ERROR && orig_diag_kind == DK_WARNING)
765 ++diagnostic_kind_count (context, DK_WERROR);
766 else
767 ++diagnostic_kind_count (context, diagnostic->kind);
b8698a0f 768
52249a2e 769 saved_format_spec = diagnostic->message.format_spec;
289fcbbd
MLI
770 if (context->show_option_requested)
771 {
5f0f4a3b 772 char *option_text;
b8698a0f 773
5f0f4a3b
JM
774 option_text = context->option_name (context, diagnostic->option_index,
775 orig_diag_kind, diagnostic->kind);
289fcbbd
MLI
776
777 if (option_text)
5f0f4a3b
JM
778 {
779 diagnostic->message.format_spec
780 = ACONCAT ((diagnostic->message.format_spec,
781 " ",
782 "[", option_text, "]",
783 NULL));
784 free (option_text);
785 }
289fcbbd 786 }
52249a2e 787 diagnostic->message.locus = &diagnostic->location;
cf835838
JM
788 diagnostic->message.x_data = &diagnostic->x_data;
789 diagnostic->x_data = NULL;
52249a2e
MLI
790 pp_format (context->printer, &diagnostic->message);
791 (*diagnostic_starter (context)) (context, diagnostic);
792 pp_output_formatted_text (context->printer);
9fec0042 793 diagnostic_show_locus (context, diagnostic);
52249a2e 794 (*diagnostic_finalizer (context)) (context, diagnostic);
dfa32261 795 pp_destroy_prefix (context->printer);
f8923f7e 796 pp_newline_and_flush (context->printer);
52249a2e
MLI
797 diagnostic_action_after_output (context, diagnostic);
798 diagnostic->message.format_spec = saved_format_spec;
cf835838 799 diagnostic->x_data = NULL;
9804f5fb
ZW
800
801 context->lock--;
71205d17
MLI
802
803 return true;
59650e48 804}
43db5b3c 805
59650e48
ZW
806/* Given a partial pathname as input, return another pathname that
807 shares no directory elements with the pathname of __FILE__. This
808 is used by fancy_abort() to print `Internal compiler error in expr.c'
809 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
3a538a66 810
59650e48 811const char *
79a490a9 812trim_filename (const char *name)
59650e48
ZW
813{
814 static const char this_file[] = __FILE__;
815 const char *p = name, *q = this_file;
43db5b3c 816
59650e48
ZW
817 /* First skip any "../" in each filename. This allows us to give a proper
818 reference to a file in a subdirectory. */
d5706a1e 819 while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2]))
59650e48
ZW
820 p += 3;
821
d5706a1e 822 while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2]))
59650e48
ZW
823 q += 3;
824
825 /* Now skip any parts the two filenames have in common. */
826 while (*p == *q && *p != 0 && *q != 0)
827 p++, q++;
828
829 /* Now go backwards until the previous directory separator. */
ef9af077 830 while (p > name && !IS_DIR_SEPARATOR (p[-1]))
59650e48
ZW
831 p--;
832
833 return p;
6ed551b4 834}
59650e48
ZW
835\f
836/* Standard error reporting routines in increasing order of severity.
837 All of these take arguments like printf. */
6ed551b4 838
59650e48
ZW
839/* Text to be emitted verbatim to the error message stream; this
840 produces no prefix and disables line-wrapping. Use rarely. */
6ed551b4 841void
4b794eaf 842verbatim (const char *gmsgid, ...)
59650e48
ZW
843{
844 text_info text;
e34d07f2 845 va_list ap;
59650e48 846
4b794eaf 847 va_start (ap, gmsgid);
fa6ef813 848 text.err_no = errno;
59650e48 849 text.args_ptr = &ap;
4b794eaf 850 text.format_spec = _(gmsgid);
39ce81c9 851 text.locus = NULL;
cf835838 852 text.x_data = NULL;
b6fe0bb8 853 pp_format_verbatim (global_dc->printer, &text);
f8923f7e 854 pp_newline_and_flush (global_dc->printer);
e34d07f2 855 va_end (ap);
59650e48
ZW
856}
857
dfa32261
MLI
858/* Add a note with text GMSGID and with LOCATION to the diagnostic CONTEXT. */
859void
860diagnostic_append_note (diagnostic_context *context,
861 location_t location,
862 const char * gmsgid, ...)
863{
864 diagnostic_info diagnostic;
865 va_list ap;
4432aa6c 866 const char *saved_prefix;
dfa32261
MLI
867
868 va_start (ap, gmsgid);
869 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE);
870 if (context->inhibit_notes_p)
3b4adfb3
TB
871 {
872 va_end (ap);
873 return;
874 }
4432aa6c 875 saved_prefix = pp_get_prefix (context->printer);
dfa32261
MLI
876 pp_set_prefix (context->printer,
877 diagnostic_build_prefix (context, &diagnostic));
878 pp_newline (context->printer);
879 pp_format (context->printer, &diagnostic.message);
880 pp_output_formatted_text (context->printer);
881 pp_destroy_prefix (context->printer);
4432aa6c 882 pp_set_prefix (context->printer, saved_prefix);
dfa32261 883 diagnostic_show_locus (context, &diagnostic);
c3284718 884 va_end (ap);
dfa32261
MLI
885}
886
71205d17 887bool
b8698a0f 888emit_diagnostic (diagnostic_t kind, location_t location, int opt,
71205d17 889 const char *gmsgid, ...)
6ed551b4 890{
47b69537 891 diagnostic_info diagnostic;
e34d07f2 892 va_list ap;
80f24351 893 bool ret;
59650e48 894
4b794eaf 895 va_start (ap, gmsgid);
71205d17
MLI
896 if (kind == DK_PERMERROR)
897 {
898 diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
243fbddd 899 permissive_error_kind (global_dc));
5f0f4a3b 900 diagnostic.option_index = permissive_error_option (global_dc);
71205d17
MLI
901 }
902 else {
903 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, kind);
904 if (kind == DK_WARNING || kind == DK_PEDWARN)
905 diagnostic.option_index = opt;
906 }
71205d17 907
80f24351
MM
908 ret = report_diagnostic (&diagnostic);
909 va_end (ap);
910 return ret;
6ed551b4
GDR
911}
912
1f5b3869 913/* An informative note at LOCATION. Use this for additional details on an error
71205d17 914 message. */
6ed551b4 915void
1f5b3869 916inform (location_t location, const char *gmsgid, ...)
d4ee4d25
DD
917{
918 diagnostic_info diagnostic;
919 va_list ap;
920
4b794eaf 921 va_start (ap, gmsgid);
1f5b3869 922 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE);
d4ee4d25
DD
923 report_diagnostic (&diagnostic);
924 va_end (ap);
925}
926
894e2652
SZ
927/* An informative note at LOCATION. Use this for additional details on an
928 error message. */
929void
930inform_n (location_t location, int n, const char *singular_gmsgid,
931 const char *plural_gmsgid, ...)
932{
933 diagnostic_info diagnostic;
934 va_list ap;
935
936 va_start (ap, plural_gmsgid);
937 diagnostic_set_info_translated (&diagnostic,
938 ngettext (singular_gmsgid, plural_gmsgid, n),
939 &ap, location, DK_NOTE);
940 report_diagnostic (&diagnostic);
941 va_end (ap);
942}
943
71205d17 944/* A warning at INPUT_LOCATION. Use this for code which is correct according
b8698a0f 945 to the relevant language specification but is likely to be buggy anyway.
71205d17
MLI
946 Returns true if the warning was printed, false if it was inhibited. */
947bool
948warning (int opt, const char *gmsgid, ...)
6ed551b4 949{
47b69537 950 diagnostic_info diagnostic;
e34d07f2 951 va_list ap;
80f24351 952 bool ret;
6ed551b4 953
4b794eaf
JJ
954 va_start (ap, gmsgid);
955 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING);
71205d17
MLI
956 diagnostic.option_index = opt;
957
80f24351 958 ret = report_diagnostic (&diagnostic);
e34d07f2 959 va_end (ap);
80f24351 960 return ret;
6ed551b4
GDR
961}
962
aa14403d 963/* A warning at LOCATION. Use this for code which is correct according to the
71205d17
MLI
964 relevant language specification but is likely to be buggy anyway.
965 Returns true if the warning was printed, false if it was inhibited. */
966
967bool
aa14403d
RAE
968warning_at (location_t location, int opt, const char *gmsgid, ...)
969{
970 diagnostic_info diagnostic;
971 va_list ap;
80f24351 972 bool ret;
aa14403d
RAE
973
974 va_start (ap, gmsgid);
975 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING);
976 diagnostic.option_index = opt;
80f24351 977 ret = report_diagnostic (&diagnostic);
aa14403d 978 va_end (ap);
80f24351 979 return ret;
aa14403d
RAE
980}
981
85790e66
MLI
982/* A "pedantic" warning at LOCATION: issues a warning unless
983 -pedantic-errors was given on the command line, in which case it
984 issues an error. Use this for diagnostics required by the relevant
985 language standard, if you have chosen not to make them errors.
9804f5fb
ZW
986
987 Note that these diagnostics are issued independent of the setting
c1771a20 988 of the -Wpedantic command-line switch. To get a warning enabled
fcf73884 989 only with that switch, use either "if (pedantic) pedwarn
c1771a20
MLI
990 (OPT_Wpedantic,...)" or just "pedwarn (OPT_Wpedantic,..)". To get a
991 pedwarn independently of the -Wpedantic switch use "pedwarn (0,...)".
fcf73884 992
71205d17
MLI
993 Returns true if the warning was printed, false if it was inhibited. */
994
85790e66 995bool
509c9d60 996pedwarn (location_t location, int opt, const char *gmsgid, ...)
85790e66
MLI
997{
998 diagnostic_info diagnostic;
999 va_list ap;
80f24351 1000 bool ret;
85790e66
MLI
1001
1002 va_start (ap, gmsgid);
1003 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
1004 diagnostic.option_index = opt;
80f24351 1005 ret = report_diagnostic (&diagnostic);
85790e66 1006 va_end (ap);
80f24351 1007 return ret;
85790e66
MLI
1008}
1009
7e99f74b
MLI
1010/* A "permissive" error at LOCATION: issues an error unless
1011 -fpermissive was given on the command line, in which case it issues
1012 a warning. Use this for things that really should be errors but we
71205d17 1013 want to support legacy code.
7e99f74b 1014
71205d17
MLI
1015 Returns true if the warning was printed, false if it was inhibited. */
1016
1017bool
cbe5f3b3 1018permerror (location_t location, const char *gmsgid, ...)
7e99f74b
MLI
1019{
1020 diagnostic_info diagnostic;
1021 va_list ap;
80f24351 1022 bool ret;
7e99f74b
MLI
1023
1024 va_start (ap, gmsgid);
1025 diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
243fbddd 1026 permissive_error_kind (global_dc));
5f0f4a3b 1027 diagnostic.option_index = permissive_error_option (global_dc);
80f24351 1028 ret = report_diagnostic (&diagnostic);
7e99f74b 1029 va_end (ap);
80f24351 1030 return ret;
7e99f74b
MLI
1031}
1032
59650e48
ZW
1033/* A hard error: the code is definitely ill-formed, and an object file
1034 will not be produced. */
8514e318 1035void
4b794eaf 1036error (const char *gmsgid, ...)
8514e318 1037{
59650e48 1038 diagnostic_info diagnostic;
e34d07f2 1039 va_list ap;
59650e48 1040
4b794eaf
JJ
1041 va_start (ap, gmsgid);
1042 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR);
59650e48 1043 report_diagnostic (&diagnostic);
e34d07f2 1044 va_end (ap);
93d87cb1
GDR
1045}
1046
894e2652
SZ
1047/* A hard error: the code is definitely ill-formed, and an object file
1048 will not be produced. */
1049void
1050error_n (location_t location, int n, const char *singular_gmsgid,
1051 const char *plural_gmsgid, ...)
1052{
1053 diagnostic_info diagnostic;
1054 va_list ap;
1055
1056 va_start (ap, plural_gmsgid);
1057 diagnostic_set_info_translated (&diagnostic,
1058 ngettext (singular_gmsgid, plural_gmsgid, n),
1059 &ap, location, DK_ERROR);
1060 report_diagnostic (&diagnostic);
1061 va_end (ap);
1062}
1063
a63068b6
AH
1064/* Same as ebove, but use location LOC instead of input_location. */
1065void
1066error_at (location_t loc, const char *gmsgid, ...)
1067{
1068 diagnostic_info diagnostic;
1069 va_list ap;
1070
1071 va_start (ap, gmsgid);
1072 diagnostic_set_info (&diagnostic, gmsgid, &ap, loc, DK_ERROR);
1073 report_diagnostic (&diagnostic);
1074 va_end (ap);
1075}
1076
59650e48
ZW
1077/* "Sorry, not implemented." Use for a language feature which is
1078 required by the relevant specification but not implemented by GCC.
1079 An object file will not be produced. */
93d87cb1 1080void
4b794eaf 1081sorry (const char *gmsgid, ...)
93d87cb1 1082{
59650e48 1083 diagnostic_info diagnostic;
e34d07f2 1084 va_list ap;
fbfc1192 1085
4b794eaf
JJ
1086 va_start (ap, gmsgid);
1087 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_SORRY);
9804f5fb 1088 report_diagnostic (&diagnostic);
e34d07f2 1089 va_end (ap);
59650e48 1090}
43db5b3c 1091
1da2ed5f
JM
1092/* Return true if an error or a "sorry" has been seen. Various
1093 processing is disabled after errors. */
1094bool
1095seen_error (void)
1096{
1097 return errorcount || sorrycount;
1098}
1099
59650e48
ZW
1100/* An error which is severe enough that we make no attempt to
1101 continue. Do not use this for internal consistency checks; that's
1102 internal_error. Use of this function should be rare. */
1103void
4b794eaf 1104fatal_error (const char *gmsgid, ...)
fbfc1192 1105{
59650e48 1106 diagnostic_info diagnostic;
e34d07f2 1107 va_list ap;
fbfc1192 1108
4b794eaf
JJ
1109 va_start (ap, gmsgid);
1110 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_FATAL);
59650e48 1111 report_diagnostic (&diagnostic);
e34d07f2 1112 va_end (ap);
59650e48 1113
d5706a1e 1114 gcc_unreachable ();
fbfc1192
ZW
1115}
1116
59650e48
ZW
1117/* An internal consistency check has failed. We make no attempt to
1118 continue. Note that unless there is debugging value to be had from
1119 a more specific message, or some other good reason, you should use
1120 abort () instead of calling this function directly. */
1121void
4b794eaf 1122internal_error (const char *gmsgid, ...)
fbfc1192 1123{
59650e48 1124 diagnostic_info diagnostic;
e34d07f2 1125 va_list ap;
fbfc1192 1126
4b794eaf
JJ
1127 va_start (ap, gmsgid);
1128 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ICE);
59650e48 1129 report_diagnostic (&diagnostic);
e34d07f2 1130 va_end (ap);
fbfc1192 1131
d5706a1e 1132 gcc_unreachable ();
fbfc1192 1133}
59650e48 1134\f
59650e48
ZW
1135/* Special case error functions. Most are implemented in terms of the
1136 above, or should be. */
e23bd218 1137
59650e48
ZW
1138/* Print a diagnostic MSGID on FILE. This is just fprintf, except it
1139 runs its second argument through gettext. */
04c1334c 1140void
4b794eaf 1141fnotice (FILE *file, const char *cmsgid, ...)
04c1334c 1142{
e34d07f2 1143 va_list ap;
04c1334c 1144
4b794eaf
JJ
1145 va_start (ap, cmsgid);
1146 vfprintf (file, _(cmsgid), ap);
e34d07f2 1147 va_end (ap);
04c1334c
GDR
1148}
1149
59650e48
ZW
1150/* Inform the user that an error occurred while trying to report some
1151 other error. This indicates catastrophic internal inconsistencies,
1152 so give up now. But do try to flush out the previous error.
1153 This mustn't use internal_error, that will cause infinite recursion. */
1154
1155static void
79a490a9 1156error_recursion (diagnostic_context *context)
59650e48 1157{
d5706a1e
ZW
1158 diagnostic_info diagnostic;
1159
59650e48 1160 if (context->lock < 3)
f8923f7e 1161 pp_newline_and_flush (context->printer);
59650e48
ZW
1162
1163 fnotice (stderr,
1164 "Internal compiler error: Error reporting routines re-entered.\n");
d5706a1e
ZW
1165
1166 /* Call diagnostic_action_after_output to get the "please submit a bug
1167 report" message. It only looks at the kind field of diagnostic_info. */
1168 diagnostic.kind = DK_ICE;
1169 diagnostic_action_after_output (context, &diagnostic);
1170
1171 /* Do not use gcc_unreachable here; that goes through internal_error
1172 and therefore would cause infinite recursion. */
1173 real_abort ();
59650e48
ZW
1174}
1175
1176/* Report an internal compiler error in a friendly manner. This is
1177 the function that gets called upon use of abort() in the source
1178 code generally, thanks to a special macro. */
1179
1180void
79a490a9 1181fancy_abort (const char *file, int line, const char *function)
59650e48
ZW
1182{
1183 internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
1184}
1185
886e0865
GK
1186/* Really call the system 'abort'. This has to go right at the end of
1187 this file, so that there are no functions after it that call abort
1188 and get the system abort instead of our macro. */
1189#undef abort
79a490a9
AJ
1190static void
1191real_abort (void)
886e0865
GK
1192{
1193 abort ();
1194}