* gcc_release (-b): Remove option.
[official-gcc.git] / gcc / diagnostic.c
blob8ac0e89199a16ce674d336122cb16fc3a34e28a7
1 /* Language-independent diagnostic subroutines for the GNU C compiler
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
10 any later version.
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file implements the language independent aspect of diagnostic
24 message module. */
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"
31 #include "tree.h"
32 #include "rtl.h"
33 #include "tm_p.h"
34 #include "flags.h"
35 #include "input.h"
36 #include "insn-attr.h"
37 #include "insn-config.h"
38 #include "toplev.h"
39 #include "intl.h"
40 #include "diagnostic.h"
42 #define obstack_chunk_alloc xmalloc
43 #define obstack_chunk_free free
45 #define output_formatted_integer(BUFFER, FORMAT, INTEGER) \
46 do { \
47 sprintf (digit_buffer, FORMAT, INTEGER); \
48 output_add_string (BUFFER, digit_buffer); \
49 } while (0)
51 #define output_text_length(BUFFER) (BUFFER)->line_length
52 #define is_starting_newline(BUFFER) (output_text_length (BUFFER) == 0)
53 #define output_prefix(BUFFER) (BUFFER)->state.prefix
54 #define line_wrap_cutoff(BUFFER) (BUFFER)->state.maximum_length
55 #define ideal_line_wrap_cutoff(BUFFER) (BUFFER)->state.ideal_maximum_length
56 #define prefix_was_emitted_for(BUFFER) (BUFFER)->state.emitted_prefix_p
57 #define prefixing_policy(BUFFER) (BUFFER)->state.prefixing_rule
58 #define output_buffer_ptr_to_format_args(BUFFER) (BUFFER)->state.format_args
60 #define diagnostic_args output_buffer_ptr_to_format_args (diagnostic_buffer)
61 #define diagnostic_msg output_buffer_text_cursor (diagnostic_buffer)
63 /* Prototypes. */
64 static void finish_diagnostic PARAMS ((void));
65 static void output_do_verbatim PARAMS ((output_buffer *,
66 const char *, va_list *));
67 static void output_to_stream PARAMS ((output_buffer *, FILE *));
68 static void output_format PARAMS ((output_buffer *));
69 static void output_indent PARAMS ((output_buffer *));
71 static char *vbuild_message_string PARAMS ((const char *, va_list))
72 ATTRIBUTE_PRINTF (1, 0);
73 static char *build_message_string PARAMS ((const char *, ...))
74 ATTRIBUTE_PRINTF_1;
75 static void output_do_printf PARAMS ((output_buffer *, const char *))
76 ATTRIBUTE_PRINTF (2, 0);
77 static void format_with_decl PARAMS ((output_buffer *, tree));
78 static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
79 static void diagnostic_for_asm PARAMS ((rtx, const char *, va_list *, int));
80 static void diagnostic_for_decl PARAMS ((tree, const char *, va_list *, int));
81 static void set_real_maximum_length PARAMS ((output_buffer *));
83 static void output_unsigned_decimal PARAMS ((output_buffer *, unsigned int));
84 static void output_long_decimal PARAMS ((output_buffer *, long int));
85 static void output_long_unsigned_decimal PARAMS ((output_buffer *,
86 long unsigned int));
87 static void output_octal PARAMS ((output_buffer *, unsigned int));
88 static void output_long_octal PARAMS ((output_buffer *, unsigned long int));
89 static void output_hexadecimal PARAMS ((output_buffer *, unsigned int));
90 static void output_long_hexadecimal PARAMS ((output_buffer *,
91 unsigned long int));
92 static void output_append_r PARAMS ((output_buffer *, const char *, int));
93 static void wrap_text PARAMS ((output_buffer *, const char *, const char *));
94 static void maybe_wrap_text PARAMS ((output_buffer *, const char *,
95 const char *));
96 static void clear_diagnostic_info PARAMS ((output_buffer *));
98 static void default_diagnostic_starter PARAMS ((output_buffer *,
99 diagnostic_context *));
100 static void default_diagnostic_finalizer PARAMS ((output_buffer *,
101 diagnostic_context *));
103 static void error_recursion PARAMS ((void)) ATTRIBUTE_NORETURN;
105 extern int rtl_dump_and_exit;
106 extern int inhibit_warnings;
107 extern int warnings_are_errors;
108 extern int warningcount;
109 extern int errorcount;
111 /* Front-end specific tree formatter, if non-NULL. */
112 printer_fn lang_printer = NULL;
114 /* This must be large enough to hold any printed integer or
115 floating-point value. */
116 static char digit_buffer[128];
118 /* An output_buffer surrogate for stderr. */
119 static output_buffer global_output_buffer;
120 output_buffer *diagnostic_buffer = &global_output_buffer;
122 /* Function of last error message;
123 more generally, function such that if next error message is in it
124 then we don't have to mention the function name. */
125 static tree last_error_function = NULL;
127 /* Used to detect when input_file_stack has changed since last described. */
128 static int last_error_tick;
130 /* Called by report_error_function to print out function name.
131 Default may be overridden by language front-ends. */
133 void (*print_error_function) PARAMS ((const char *)) =
134 default_print_error_function;
136 /* Hooks for language specific diagnostic messages pager and finalizer. */
137 diagnostic_starter_fn lang_diagnostic_starter;
138 diagnostic_finalizer_fn lang_diagnostic_finalizer;
140 /* Maximum characters per line in automatic line wrapping mode.
141 Zero means don't wrap lines. */
143 int diagnostic_message_length_per_line;
145 /* Used to control every diagnostic message formatting. Front-ends should
146 call set_message_prefixing_rule to set up their policies. */
147 static int current_prefixing_rule;
149 /* Prevent recursion into the error handler. */
150 static int diagnostic_lock;
153 /* Return truthvalue if current input file is different from the most recent
154 file involved in a diagnostic message. */
157 error_module_changed ()
159 return last_error_tick != input_file_stack_tick;
162 /* Remember current file as being the most recent file involved in a
163 diagnostic message. */
165 void
166 record_last_error_module ()
168 last_error_tick = input_file_stack_tick;
171 /* Same as error_module_changed, but for function. */
174 error_function_changed ()
176 return last_error_function != current_function_decl;
179 /* Same as record_last_error_module, but for function. */
181 void
182 record_last_error_function ()
184 last_error_function = current_function_decl;
187 /* Initialize the diagnostic message outputting machinery. */
189 void
190 initialize_diagnostics ()
192 /* By default, we don't line-wrap messages. */
193 diagnostic_message_length_per_line = 0;
194 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
196 /* Proceed to actual initialization. */
197 default_initialize_buffer (diagnostic_buffer);
199 lang_diagnostic_starter = default_diagnostic_starter;
200 lang_diagnostic_finalizer = default_diagnostic_finalizer;
203 void
204 set_message_prefixing_rule (rule)
205 int rule;
207 current_prefixing_rule = rule;
210 /* Returns true if BUFFER is in line-wrappind mode. */
213 output_is_line_wrapping (buffer)
214 output_buffer *buffer;
216 return ideal_line_wrap_cutoff (buffer) > 0;
219 /* Return BUFFER's prefix. */
221 const char *
222 output_get_prefix (buffer)
223 const output_buffer *buffer;
225 return output_prefix (buffer);
228 /* Subroutine of output_set_maximum_length. Set up BUFFER's
229 internal maximum characters per line. */
231 static void
232 set_real_maximum_length (buffer)
233 output_buffer *buffer;
235 /* If we're told not to wrap lines then do the obvious thing. In case
236 we'll emit prefix only once per diagnostic message, it is appropriate
237 not to increase unncessarily the line-length cut-off. */
238 if (! output_is_line_wrapping (buffer)
239 || prefixing_policy (buffer) == DIAGNOSTICS_SHOW_PREFIX_ONCE
240 || prefixing_policy (buffer) == DIAGNOSTICS_SHOW_PREFIX_NEVER)
241 line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer);
242 else
244 int prefix_length =
245 output_prefix (buffer) ? strlen (output_prefix (buffer)) : 0;
246 /* If the prefix is ridiculously too long, output at least
247 32 characters. */
248 if (ideal_line_wrap_cutoff (buffer) - prefix_length < 32)
249 line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer) + 32;
250 else
251 line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer);
255 /* Sets the number of maximum characters per line BUFFER can output
256 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
258 void
259 output_set_maximum_length (buffer, length)
260 output_buffer *buffer;
261 int length;
263 ideal_line_wrap_cutoff (buffer) = length;
264 set_real_maximum_length (buffer);
267 /* Sets BUFFER's PREFIX. */
269 void
270 output_set_prefix (buffer, prefix)
271 output_buffer *buffer;
272 const char *prefix;
274 output_prefix (buffer) = prefix;
275 set_real_maximum_length (buffer);
276 prefix_was_emitted_for (buffer) = 0;
277 output_indentation (buffer) = 0;
280 /* Return a pointer to the last character emitted in the output
281 BUFFER area. A NULL pointer means no character available. */
282 const char *
283 output_last_position (buffer)
284 const output_buffer *buffer;
286 const char *p = NULL;
288 if (obstack_base (&buffer->obstack) != obstack_next_free (&buffer->obstack))
289 p = ((const char *) obstack_next_free (&buffer->obstack)) - 1;
290 return p;
293 /* Free BUFFER's prefix, a previously malloc'd string. */
295 void
296 output_destroy_prefix (buffer)
297 output_buffer *buffer;
299 if (output_prefix (buffer) != NULL)
301 free ((char *) output_prefix (buffer));
302 output_prefix (buffer) = NULL;
306 /* Zero out any text output so far in BUFFER. */
308 void
309 output_clear_message_text (buffer)
310 output_buffer *buffer;
312 obstack_free (&buffer->obstack, obstack_base (&buffer->obstack));
313 output_text_length (buffer) = 0;
316 /* Zero out any diagnostic data used so far by BUFFER. */
318 static void
319 clear_diagnostic_info (buffer)
320 output_buffer *buffer;
322 output_buffer_text_cursor (buffer) = NULL;
323 output_buffer_ptr_to_format_args (buffer) = NULL;
324 prefix_was_emitted_for (buffer) = 0;
325 output_indentation (buffer) = 0;
328 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
329 characters per line. */
331 void
332 init_output_buffer (buffer, prefix, maximum_length)
333 output_buffer *buffer;
334 const char *prefix;
335 int maximum_length;
337 memset (buffer, 0, sizeof (output_buffer));
338 obstack_init (&buffer->obstack);
339 ideal_line_wrap_cutoff (buffer) = maximum_length;
340 prefixing_policy (buffer) = current_prefixing_rule;
341 output_set_prefix (buffer, prefix);
342 output_text_length (buffer) = 0;
343 clear_diagnostic_info (buffer);
346 /* Initialize BUFFER with a NULL prefix and current diagnostic message
347 length cutoff. */
349 void
350 default_initialize_buffer (buffer)
351 output_buffer *buffer;
353 init_output_buffer (buffer, NULL, diagnostic_message_length_per_line);
356 /* Recompute diagnostic_buffer's attributes to reflect any change
357 in diagnostic formatting global options. */
359 void
360 reshape_diagnostic_buffer ()
362 ideal_line_wrap_cutoff (diagnostic_buffer) =
363 diagnostic_message_length_per_line;
364 prefixing_policy (diagnostic_buffer) = current_prefixing_rule;
365 set_real_maximum_length (diagnostic_buffer);
368 /* Reinitialize BUFFER. */
370 void
371 output_clear (buffer)
372 output_buffer *buffer;
374 output_clear_message_text (buffer);
375 clear_diagnostic_info (buffer);
378 /* Finishes constructing a NULL-terminated character string representing
379 the BUFFERed message. */
381 const char *
382 output_finalize_message (buffer)
383 output_buffer *buffer;
385 obstack_1grow (&buffer->obstack, '\0');
386 return output_message_text (buffer);
389 void
390 flush_diagnostic_buffer ()
392 output_to_stream (diagnostic_buffer, stderr);
393 fflush (stderr);
396 /* Return the amount of characters BUFFER can accept to
397 make a full line. */
400 output_space_left (buffer)
401 const output_buffer *buffer;
403 return line_wrap_cutoff (buffer) - output_text_length (buffer);
406 /* Write out BUFFER's prefix. */
408 void
409 output_emit_prefix (buffer)
410 output_buffer *buffer;
412 if (output_prefix (buffer) != NULL)
414 switch (prefixing_policy (buffer))
416 default:
417 case DIAGNOSTICS_SHOW_PREFIX_NEVER:
418 break;
420 case DIAGNOSTICS_SHOW_PREFIX_ONCE:
421 if (prefix_was_emitted_for (buffer))
423 output_indent (buffer);
424 break;
426 output_indentation (buffer) += 3;
427 /* Fall through. */
429 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE:
431 int prefix_length = strlen (output_prefix (buffer));
432 output_append_r (buffer, output_prefix (buffer), prefix_length);
433 prefix_was_emitted_for (buffer) = 1;
435 break;
440 /* Have BUFFER start a new line. */
442 void
443 output_add_newline (buffer)
444 output_buffer *buffer;
446 obstack_1grow (&buffer->obstack, '\n');
447 output_text_length (buffer) = 0;
450 /* Appends a character to BUFFER. */
452 void
453 output_add_character (buffer, c)
454 output_buffer *buffer;
455 int c;
457 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
458 output_add_newline (buffer);
459 obstack_1grow (&buffer->obstack, c);
460 ++output_text_length (buffer);
463 /* Adds a space to BUFFER. */
465 void
466 output_add_space (buffer)
467 output_buffer *buffer;
469 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
471 output_add_newline (buffer);
472 return;
474 obstack_1grow (&buffer->obstack, ' ');
475 ++output_text_length (buffer);
478 /* These functions format an INTEGER into BUFFER as suggested by their
479 names. */
481 void
482 output_decimal (buffer, i)
483 output_buffer *buffer;
484 int i;
486 output_formatted_integer (buffer, "%d", i);
489 static void
490 output_long_decimal (buffer, i)
491 output_buffer *buffer;
492 long int i;
494 output_formatted_integer (buffer, "%ld", i);
497 static void
498 output_unsigned_decimal (buffer, i)
499 output_buffer *buffer;
500 unsigned int i;
502 output_formatted_integer (buffer, "%u", i);
505 static void
506 output_long_unsigned_decimal (buffer, i)
507 output_buffer *buffer;
508 long unsigned int i;
510 output_formatted_integer (buffer, "%lu", i);
513 static void
514 output_octal (buffer, i)
515 output_buffer *buffer;
516 unsigned int i;
518 output_formatted_integer (buffer, "%o", i);
521 static void
522 output_long_octal (buffer, i)
523 output_buffer *buffer;
524 unsigned long int i;
526 output_formatted_integer (buffer, "%lo", i);
529 static void
530 output_hexadecimal (buffer, i)
531 output_buffer *buffer;
532 unsigned int i;
534 output_formatted_integer (buffer, "%x", i);
537 static void
538 output_long_hexadecimal (buffer, i)
539 output_buffer *buffer;
540 unsigned long int i;
542 output_formatted_integer (buffer, "%lx", i);
545 /* Append to BUFFER a string specified by its STARTING character
546 and LENGTH. */
548 static void
549 output_append_r (buffer, start, length)
550 output_buffer *buffer;
551 const char *start;
552 int length;
554 obstack_grow (&buffer->obstack, start, length);
555 output_text_length (buffer) += length;
558 /* Append a string deliminated by START and END to BUFFER. No wrapping is
559 done. However, if beginning a new line then emit output_prefix (BUFFER)
560 and skip any leading whitespace if appropriate. The caller must ensure
561 that it is safe to do so. */
563 void
564 output_append (buffer, start, end)
565 output_buffer *buffer;
566 const char *start;
567 const char *end;
569 /* Emit prefix and skip whitespace if we're starting a new line. */
570 if (is_starting_newline (buffer))
572 output_emit_prefix (buffer);
573 if (output_is_line_wrapping (buffer))
574 while (start != end && *start == ' ')
575 ++start;
577 output_append_r (buffer, start, end - start);
580 static void
581 output_indent (buffer)
582 output_buffer *buffer;
584 int n = output_indentation (buffer);
585 int i;
587 for (i = 0; i < n; ++i)
588 output_add_character (buffer, ' ');
591 /* Wrap a text delimited by START and END into BUFFER. */
593 static void
594 wrap_text (buffer, start, end)
595 output_buffer *buffer;
596 const char *start;
597 const char *end;
599 int is_wrapping = output_is_line_wrapping (buffer);
601 while (start != end)
603 /* Dump anything bodered by whitespaces. */
605 const char *p = start;
606 while (p != end && *p != ' ' && *p != '\n')
607 ++p;
608 if (is_wrapping && p - start >= output_space_left (buffer))
609 output_add_newline (buffer);
610 output_append (buffer, start, p);
611 start = p;
614 if (start != end && *start == ' ')
616 output_add_space (buffer);
617 ++start;
619 if (start != end && *start == '\n')
621 output_add_newline (buffer);
622 ++start;
627 /* Same as wrap_text but wrap text only when in line-wrapping mode. */
629 static void
630 maybe_wrap_text (buffer, start, end)
631 output_buffer *buffer;
632 const char *start;
633 const char *end;
635 if (output_is_line_wrapping (buffer))
636 wrap_text (buffer, start, end);
637 else
638 output_append (buffer, start, end);
642 /* Append a STRING to BUFFER; the STRING might be line-wrapped if in
643 appropriate mode. */
645 void
646 output_add_string (buffer, str)
647 output_buffer *buffer;
648 const char *str;
650 maybe_wrap_text (buffer, str, str + (str ? strlen (str) : 0));
653 /* Flush the content of BUFFER onto FILE and reinitialize BUFFER. */
655 static void
656 output_to_stream (buffer, file)
657 output_buffer *buffer;
658 FILE *file;
660 const char *text = output_finalize_message (buffer);
661 fputs (text, file);
662 output_clear_message_text (buffer);
665 /* Format a message pointed to by output_buffer_text_cursor (BUFFER) using
666 output_buffer_format_args (BUFFER) as appropriate. The following format
667 specifiers are recognized as being language independent:
668 %d, %i: (signed) integer in base ten.
669 %u: unsigned integer in base ten.
670 %o: unsigned integer in base eight.
671 %x: unsigned integer in base sixteen.
672 %ld, %li, %lo, %lu, %lx: long versions of the above.
673 %c: character.
674 %s: string.
675 %%: `%'.
676 %*.s: a substring the length of which is specified by an integer. */
678 static void
679 output_format (buffer)
680 output_buffer *buffer;
682 for (; *output_buffer_text_cursor (buffer);
683 ++output_buffer_text_cursor (buffer))
685 int long_integer = 0;
687 /* Ignore text. */
689 const char *p = output_buffer_text_cursor (buffer);
690 while (*p && *p != '%')
691 ++p;
692 wrap_text (buffer, output_buffer_text_cursor (buffer), p);
693 output_buffer_text_cursor (buffer) = p;
696 if (!*output_buffer_text_cursor (buffer))
697 break;
699 /* We got a '%'. Let's see what happens. Record whether we're
700 parsing a long integer format specifier. */
701 if (*++output_buffer_text_cursor (buffer) == 'l')
703 long_integer = 1;
704 ++output_buffer_text_cursor (buffer);
707 /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %o, %s, %u,
708 %x, %.*s; %%. And nothing else. Front-ends should install
709 printers to grok language specific format specifiers. */
710 switch (*output_buffer_text_cursor (buffer))
712 case 'c':
713 output_add_character
714 (buffer, va_arg (output_buffer_format_args (buffer), int));
715 break;
717 case 'd':
718 case 'i':
719 if (long_integer)
720 output_long_decimal
721 (buffer, va_arg (output_buffer_format_args (buffer), long int));
722 else
723 output_decimal
724 (buffer, va_arg (output_buffer_format_args (buffer), int));
725 break;
727 case 'o':
728 if (long_integer)
729 output_long_octal (buffer,
730 va_arg (output_buffer_format_args (buffer),
731 unsigned long int));
732 else
733 output_octal (buffer,
734 va_arg (output_buffer_format_args (buffer),
735 unsigned int));
736 break;
738 case 's':
739 output_add_string (buffer,
740 va_arg (output_buffer_format_args (buffer),
741 const char *));
742 break;
744 case 'u':
745 if (long_integer)
746 output_long_unsigned_decimal
747 (buffer, va_arg (output_buffer_format_args (buffer),
748 long unsigned int));
749 else
750 output_unsigned_decimal
751 (buffer, va_arg (output_buffer_format_args (buffer),
752 unsigned int));
753 break;
755 case 'x':
756 if (long_integer)
757 output_long_hexadecimal
758 (buffer, va_arg (output_buffer_format_args (buffer),
759 unsigned long int));
760 else
761 output_hexadecimal
762 (buffer, va_arg (output_buffer_format_args (buffer),
763 unsigned int));
764 break;
766 case '%':
767 output_add_character (buffer, '%');
768 break;
770 case '.':
772 int n;
773 const char *s;
774 /* We handle no precision specifier but `%.*s'. */
775 if (*++output_buffer_text_cursor (buffer) != '*')
776 abort ();
777 else if (*++output_buffer_text_cursor (buffer) != 's')
778 abort();
779 n = va_arg (output_buffer_format_args (buffer), int);
780 s = va_arg (output_buffer_format_args (buffer), const char *);
781 output_append (buffer, s, s + n);
783 break;
785 default:
786 if (! lang_printer || !(*lang_printer) (buffer))
788 /* Hmmm. The front-end failed to install a format translator
789 but called us with an unrecognized format. Sorry. */
790 abort ();
796 static char *
797 vbuild_message_string (msg, ap)
798 const char *msg;
799 va_list ap;
801 char *str;
803 vasprintf (&str, msg, ap);
804 return str;
807 /* Return a malloc'd string containing MSG formatted a la
808 printf. The caller is reponsible for freeing the memory. */
810 static char *
811 build_message_string VPARAMS ((const char *msg, ...))
813 #ifndef ANSI_PROTOTYPES
814 const char *msg;
815 #endif
816 va_list ap;
817 char *str;
819 VA_START (ap, msg);
821 #ifndef ANSI_PROTOTYPES
822 msg = va_arg (ap, const char *);
823 #endif
825 str = vbuild_message_string (msg, ap);
827 va_end (ap);
829 return str;
832 /* Return a malloc'd string describing a location. The caller is
833 responsible for freeing the memory. */
835 char *
836 context_as_prefix (file, line, warn)
837 const char *file;
838 int line;
839 int warn;
841 if (file)
843 if (warn)
844 return build_message_string (_("%s:%d: warning: "), file, line);
845 else
846 return build_message_string ("%s:%d: ", file, line);
848 else
850 if (warn)
851 return build_message_string (_("%s: warning: "), progname);
852 else
853 return build_message_string ("%s: ", progname);
857 /* Same as context_as_prefix, but only the source FILE is given. */
859 char *
860 file_name_as_prefix (f)
861 const char *f;
863 return build_message_string ("%s: ", f);
866 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
868 static void
869 output_do_printf (buffer, msg)
870 output_buffer *buffer;
871 const char *msg;
873 char *message = vbuild_message_string (msg,
874 output_buffer_format_args (buffer));
876 wrap_text (buffer, message, message + strlen (message));
877 free (message);
881 /* Format a message into BUFFER a la printf. */
883 void
884 output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
886 #ifndef ANSI_PROTOTYPES
887 struct output_buffer *buffer;
888 const char *msgid;
889 #endif
890 va_list ap;
891 va_list *old_args;
893 VA_START (ap, msgid);
894 #ifndef ANSI_PROTOTYPES
895 buffer = va_arg (ap, output_buffer *);
896 msgid = va_arg (ap, const char *);
897 #endif
898 old_args = output_buffer_ptr_to_format_args (buffer);
899 output_buffer_ptr_to_format_args (buffer) = &ap;
900 output_do_printf (buffer, _(msgid));
901 output_buffer_ptr_to_format_args (buffer) = old_args;
902 va_end (ap);
905 /* Print a message relevant to the given DECL. */
907 static void
908 format_with_decl (buffer, decl)
909 output_buffer *buffer;
910 tree decl;
912 const char *p;
914 /* Do magic to get around lack of varargs support for insertion
915 of arguments into existing list. We know that the decl is first;
916 we ass_u_me that it will be printed with "%s". */
917 for (p = output_buffer_text_cursor (buffer); *p; ++p)
919 if (*p == '%')
921 if (*(p + 1) == '%')
922 ++p;
923 else if (*(p + 1) != 's')
924 abort ();
925 else
926 break;
930 /* Print the left-hand substring. */
931 maybe_wrap_text (buffer, output_buffer_text_cursor (buffer), p);
933 if (*p == '%') /* Print the name. */
935 const char *n = (DECL_NAME (decl)
936 ? (*decl_printable_name) (decl, 2)
937 : _("((anonymous))"));
938 output_add_string (buffer, n);
939 while (*p)
941 ++p;
942 if (ISALPHA (*(p - 1) & 0xFF))
943 break;
947 if (*p) /* Print the rest of the message. */
949 output_buffer_text_cursor (buffer) = p;
950 output_format (buffer);
954 /* Figure file and line of the given INSN. */
956 static void
957 file_and_line_for_asm (insn, pfile, pline)
958 rtx insn;
959 const char **pfile;
960 int *pline;
962 rtx body = PATTERN (insn);
963 rtx asmop;
965 /* Find the (or one of the) ASM_OPERANDS in the insn. */
966 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
967 asmop = SET_SRC (body);
968 else if (GET_CODE (body) == ASM_OPERANDS)
969 asmop = body;
970 else if (GET_CODE (body) == PARALLEL
971 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
972 asmop = SET_SRC (XVECEXP (body, 0, 0));
973 else if (GET_CODE (body) == PARALLEL
974 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
975 asmop = XVECEXP (body, 0, 0);
976 else
977 asmop = NULL;
979 if (asmop)
981 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
982 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
984 else
986 *pfile = input_filename;
987 *pline = lineno;
991 /* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
992 of the insn INSN. This is used only when INSN is an `asm' with operands,
993 and each ASM_OPERANDS records its own source file and line. */
995 static void
996 diagnostic_for_asm (insn, msg, args_ptr, warn)
997 rtx insn;
998 const char *msg;
999 va_list *args_ptr;
1000 int warn;
1002 diagnostic_context dc;
1004 set_diagnostic_context (&dc, msg, args_ptr, NULL, 0, warn);
1005 file_and_line_for_asm (insn, &diagnostic_file_location (&dc),
1006 &diagnostic_line_location (&dc));
1007 report_diagnostic (&dc);
1010 /* Report a diagnostic MESSAGE at the declaration DECL.
1011 MSG is a format string which uses %s to substitute the declaration
1012 name; subsequent substitutions are a la output_format. */
1014 static void
1015 diagnostic_for_decl (decl, msgid, args_ptr, warn)
1016 tree decl;
1017 const char *msgid;
1018 va_list *args_ptr;
1019 int warn;
1021 output_state os;
1023 if (diagnostic_lock++)
1024 error_recursion ();
1026 if (count_error (warn))
1028 os = output_buffer_state (diagnostic_buffer);
1029 report_error_function (DECL_SOURCE_FILE (decl));
1030 output_set_prefix
1031 (diagnostic_buffer, context_as_prefix
1032 (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn));
1033 output_buffer_ptr_to_format_args (diagnostic_buffer) = args_ptr;
1034 output_buffer_text_cursor (diagnostic_buffer) = _(msgid);
1035 format_with_decl (diagnostic_buffer, decl);
1036 finish_diagnostic ();
1037 output_destroy_prefix (diagnostic_buffer);
1039 output_buffer_state (diagnostic_buffer) = os;
1041 diagnostic_lock--;
1045 /* Count an error or warning. Return 1 if the message should be printed. */
1048 count_error (warningp)
1049 int warningp;
1051 if (warningp
1052 && (inhibit_warnings
1053 || (in_system_header && !warn_system_headers)))
1054 return 0;
1056 if (warningp && !warnings_are_errors)
1057 warningcount++;
1058 else
1060 static int warning_message = 0;
1062 if (warningp && !warning_message)
1064 verbatim ("%s: warnings being treated as errors\n", progname);
1065 warning_message = 1;
1067 errorcount++;
1070 return 1;
1073 /* Print a diagnostic MSGID on FILE. This is just fprintf, except it
1074 runs its second argument through gettext. */
1076 void
1077 fnotice VPARAMS ((FILE *file, const char *msgid, ...))
1079 #ifndef ANSI_PROTOTYPES
1080 FILE *file;
1081 const char *msgid;
1082 #endif
1083 va_list ap;
1085 VA_START (ap, msgid);
1087 #ifndef ANSI_PROTOTYPES
1088 file = va_arg (ap, FILE *);
1089 msgid = va_arg (ap, const char *);
1090 #endif
1092 vfprintf (file, _(msgid), ap);
1093 va_end (ap);
1097 /* Print a fatal I/O error message. Argument are like printf.
1098 Also include a system error message based on `errno'. */
1100 void
1101 fatal_io_error VPARAMS ((const char *msgid, ...))
1103 #ifndef ANSI_PROTOTYPES
1104 const char *msgid;
1105 #endif
1106 va_list ap;
1107 output_state os;
1109 os = output_buffer_state (diagnostic_buffer);
1110 VA_START (ap, msgid);
1112 #ifndef ANSI_PROTOTYPES
1113 msgid = va_arg (ap, const char *);
1114 #endif
1116 output_printf (diagnostic_buffer, "%s: %s: ", progname, xstrerror (errno));
1117 output_buffer_ptr_to_format_args (diagnostic_buffer) = &ap;
1118 output_buffer_text_cursor (diagnostic_buffer) = _(msgid);
1119 output_format (diagnostic_buffer);
1120 finish_diagnostic ();
1121 output_buffer_state (diagnostic_buffer) = os;
1122 va_end (ap);
1123 exit (FATAL_EXIT_CODE);
1126 /* Issue a pedantic warning MSGID. */
1128 void
1129 pedwarn VPARAMS ((const char *msgid, ...))
1131 #ifndef ANSI_PROTOTYPES
1132 const char *msgid;
1133 #endif
1134 va_list ap;
1135 diagnostic_context dc;
1137 VA_START (ap, msgid);
1139 #ifndef ANSI_PROTOTYPES
1140 msgid = va_arg (ap, const char *);
1141 #endif
1143 set_diagnostic_context
1144 (&dc, msgid, &ap, input_filename, lineno, !flag_pedantic_errors);
1145 report_diagnostic (&dc);
1146 va_end (ap);
1149 /* Issue a pedantic waring about DECL. */
1151 void
1152 pedwarn_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1154 #ifndef ANSI_PROTOTYPES
1155 tree decl;
1156 const char *msgid;
1157 #endif
1158 va_list ap;
1160 VA_START (ap, msgid);
1162 #ifndef ANSI_PROTOTYPES
1163 decl = va_arg (ap, tree);
1164 msgid = va_arg (ap, const char *);
1165 #endif
1166 /* We don't want -pedantic-errors to cause the compilation to fail from
1167 "errors" in system header files. Sometimes fixincludes can't fix what's
1168 broken (eg: unsigned char bitfields - fixing it may change the alignment
1169 which will cause programs to mysteriously fail because the C library
1170 or kernel uses the original layout). There's no point in issuing a
1171 warning either, it's just unnecessary noise. */
1172 if (!DECL_IN_SYSTEM_HEADER (decl))
1173 diagnostic_for_decl (decl, msgid, &ap, !flag_pedantic_errors);
1174 va_end (ap);
1177 /* Same as above but within the context FILE and LINE. */
1179 void
1180 pedwarn_with_file_and_line VPARAMS ((const char *file, int line,
1181 const char *msgid, ...))
1183 #ifndef ANSI_PROTOTYPES
1184 const char *file;
1185 int line;
1186 const char *msgid;
1187 #endif
1188 va_list ap;
1189 diagnostic_context dc;
1191 VA_START (ap, msgid);
1193 #ifndef ANSI_PROTOTYPES
1194 file = va_arg (ap, const char *);
1195 line = va_arg (ap, int);
1196 msgid = va_arg (ap, const char *);
1197 #endif
1199 set_diagnostic_context (&dc, msgid, &ap, file, line, !flag_pedantic_errors);
1200 report_diagnostic (&dc);
1201 va_end (ap);
1204 /* Just apologize with MSGID. */
1206 void
1207 sorry VPARAMS ((const char *msgid, ...))
1209 #ifndef ANSI_PROTOTYPES
1210 const char *msgid;
1211 #endif
1212 va_list ap;
1213 output_state os;
1215 os = output_buffer_state (diagnostic_buffer);
1216 VA_START (ap, msgid);
1218 #ifndef ANSI_PROTOTYPES
1219 msgid = va_arg (ap, const char *);
1220 #endif
1221 ++sorrycount;
1222 output_set_prefix
1223 (diagnostic_buffer, context_as_prefix (input_filename, lineno, 0));
1224 output_printf (diagnostic_buffer, "sorry, not implemented: ");
1225 output_buffer_ptr_to_format_args (diagnostic_buffer) = &ap;
1226 output_buffer_text_cursor (diagnostic_buffer) = _(msgid);
1227 output_format (diagnostic_buffer);
1228 finish_diagnostic ();
1229 output_buffer_state (diagnostic_buffer) = os;
1230 va_end (ap);
1233 /* Called when the start of a function definition is parsed,
1234 this function prints on stderr the name of the function. */
1236 void
1237 announce_function (decl)
1238 tree decl;
1240 if (! quiet_flag)
1242 if (rtl_dump_and_exit)
1243 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1244 else
1245 verbatim (" %s", (*decl_printable_name) (decl, 2));
1246 fflush (stderr);
1247 output_needs_newline (diagnostic_buffer) = 1;
1248 record_last_error_function ();
1252 /* The default function to print out name of current function that caused
1253 an error. */
1255 void
1256 default_print_error_function (file)
1257 const char *file;
1259 if (error_function_changed ())
1261 char *prefix = file ? build_message_string ("%s: ", file) : NULL;
1262 output_state os;
1264 os = output_buffer_state (diagnostic_buffer);
1265 output_set_prefix (diagnostic_buffer, prefix);
1267 if (current_function_decl == NULL)
1268 output_add_string (diagnostic_buffer, _("At top level:"));
1269 else
1271 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1272 output_printf
1273 (diagnostic_buffer, "In method `%s':",
1274 (*decl_printable_name) (current_function_decl, 2));
1275 else
1276 output_printf
1277 (diagnostic_buffer, "In function `%s':",
1278 (*decl_printable_name) (current_function_decl, 2));
1280 output_add_newline (diagnostic_buffer);
1282 record_last_error_function ();
1283 output_to_stream (diagnostic_buffer, stderr);
1284 output_buffer_state (diagnostic_buffer) = os;
1285 free ((char*) prefix);
1289 /* Prints out, if necessary, the name of the current function
1290 that caused an error. Called from all error and warning functions.
1291 We ignore the FILE parameter, as it cannot be relied upon. */
1293 void
1294 report_error_function (file)
1295 const char *file ATTRIBUTE_UNUSED;
1297 report_problematic_module (diagnostic_buffer);
1298 (*print_error_function) (input_filename);
1301 void
1302 error_with_file_and_line VPARAMS ((const char *file, int line,
1303 const char *msgid, ...))
1305 #ifndef ANSI_PROTOTYPES
1306 const char *file;
1307 int line;
1308 const char *msgid;
1309 #endif
1310 va_list ap;
1311 diagnostic_context dc;
1313 VA_START (ap, msgid);
1315 #ifndef ANSI_PROTOTYPES
1316 file = va_arg (ap, const char *);
1317 line = va_arg (ap, int);
1318 msgid = va_arg (ap, const char *);
1319 #endif
1321 set_diagnostic_context (&dc, msgid, &ap, file, line, /* warn = */ 0);
1322 report_diagnostic (&dc);
1323 va_end (ap);
1326 void
1327 error_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1329 #ifndef ANSI_PROTOTYPES
1330 tree decl;
1331 const char *msgid;
1332 #endif
1333 va_list ap;
1335 VA_START (ap, msgid);
1337 #ifndef ANSI_PROTOTYPES
1338 decl = va_arg (ap, tree);
1339 msgid = va_arg (ap, const char *);
1340 #endif
1342 diagnostic_for_decl (decl, msgid, &ap, /* warn = */ 0);
1343 va_end (ap);
1346 void
1347 error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1349 #ifndef ANSI_PROTOTYPES
1350 rtx insn;
1351 const char *msgid;
1352 #endif
1353 va_list ap;
1355 VA_START (ap, msgid);
1357 #ifndef ANSI_PROTOTYPES
1358 insn = va_arg (ap, rtx);
1359 msgid = va_arg (ap, const char *);
1360 #endif
1362 diagnostic_for_asm (insn, msgid, &ap, /* warn = */ 0);
1363 va_end (ap);
1366 /* Report an error message. The arguments are like that of printf. */
1368 void
1369 error VPARAMS ((const char *msgid, ...))
1371 #ifndef ANSI_PROTOTYPES
1372 const char *msgid;
1373 #endif
1374 va_list ap;
1375 diagnostic_context dc;
1377 VA_START (ap, msgid);
1379 #ifndef ANSI_PROTOTYPES
1380 msgid = va_arg (ap, const char *);
1381 #endif
1383 set_diagnostic_context
1384 (&dc, msgid, &ap, input_filename, lineno, /* warn = */ 0);
1385 report_diagnostic (&dc);
1386 va_end (ap);
1389 /* Likewise, except that the compilation is terminated after printing the
1390 error message. */
1392 void
1393 fatal_error VPARAMS ((const char *msgid, ...))
1395 #ifndef ANSI_PROTOTYPES
1396 const char *msgid;
1397 #endif
1398 va_list ap;
1399 diagnostic_context dc;
1401 VA_START (ap, msgid);
1403 #ifndef ANSI_PROTOTYPES
1404 msgid = va_arg (ap, const char *);
1405 #endif
1407 set_diagnostic_context
1408 (&dc, msgid, &ap, input_filename, lineno, /* warn = */ 0);
1409 report_diagnostic (&dc);
1410 va_end (ap);
1412 fnotice (stderr, "compilation terminated.\n");
1413 exit (FATAL_EXIT_CODE);
1416 /* Report a compiler error at the current line number. Allow a front end to
1417 intercept the message. */
1419 static void (*internal_error_function) PARAMS ((const char *, va_list *));
1421 /* Set the function to call when a compiler error occurs. */
1423 void
1424 set_internal_error_function (f)
1425 void (*f) PARAMS ((const char *, va_list *));
1427 internal_error_function = f;
1430 void
1431 internal_error VPARAMS ((const char *msgid, ...))
1433 #ifndef ANSI_PROTOTYPES
1434 const char *msgid;
1435 #endif
1436 va_list ap;
1437 diagnostic_context dc;
1439 VA_START (ap, msgid);
1441 #ifndef ANSI_PROTOTYPES
1442 msgid = va_arg (ap, const char *);
1443 #endif
1445 if (errorcount > 0 || sorrycount > 0)
1447 fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
1448 input_filename, lineno);
1449 exit (FATAL_EXIT_CODE);
1452 if (internal_error_function != 0)
1453 (*internal_error_function) (_(msgid), &ap);
1455 set_diagnostic_context
1456 (&dc, msgid, &ap, input_filename, lineno, /* warn = */0);
1457 report_diagnostic (&dc);
1458 va_end (ap);
1460 fnotice (stderr,
1461 "Please submit a full bug report,\n\
1462 with preprocessed source if appropriate.\n\
1463 See %s for instructions.\n", GCCBUGURL);
1464 exit (FATAL_EXIT_CODE);
1467 void
1468 _fatal_insn (msgid, insn, file, line, function)
1469 const char *msgid;
1470 rtx insn;
1471 const char *file;
1472 int line;
1473 const char *function;
1475 error ("%s", _(msgid));
1477 /* The above incremented error_count, but isn't an error that we want to
1478 count, so reset it here. */
1479 errorcount--;
1481 debug_rtx (insn);
1482 fancy_abort (file, line, function);
1485 void
1486 _fatal_insn_not_found (insn, file, line, function)
1487 rtx insn;
1488 const char *file;
1489 int line;
1490 const char *function;
1492 if (INSN_CODE (insn) < 0)
1493 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1494 else
1495 _fatal_insn ("Insn does not satisfy its constraints:",
1496 insn, file, line, function);
1499 void
1500 warning_with_file_and_line VPARAMS ((const char *file, int line,
1501 const char *msgid, ...))
1503 #ifndef ANSI_PROTOTYPES
1504 const char *file;
1505 int line;
1506 const char *msgid;
1507 #endif
1508 va_list ap;
1509 diagnostic_context dc;
1511 VA_START (ap, msgid);
1513 #ifndef ANSI_PROTOTYPES
1514 file = va_arg (ap, const char *);
1515 line = va_arg (ap, int);
1516 msgid = va_arg (ap, const char *);
1517 #endif
1519 set_diagnostic_context (&dc, msgid, &ap, file, line, /* warn = */ 1);
1520 report_diagnostic (&dc);
1521 va_end (ap);
1524 void
1525 warning_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1527 #ifndef ANSI_PROTOTYPES
1528 tree decl;
1529 const char *msgid;
1530 #endif
1531 va_list ap;
1533 VA_START (ap, msgid);
1535 #ifndef ANSI_PROTOTYPES
1536 decl = va_arg (ap, tree);
1537 msgid = va_arg (ap, const char *);
1538 #endif
1540 diagnostic_for_decl (decl, msgid, &ap, /* warn = */ 1);
1541 va_end (ap);
1544 void
1545 warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1547 #ifndef ANSI_PROTOTYPES
1548 rtx insn;
1549 const char *msgid;
1550 #endif
1551 va_list ap;
1553 VA_START (ap, msgid);
1555 #ifndef ANSI_PROTOTYPES
1556 insn = va_arg (ap, rtx);
1557 msgid = va_arg (ap, const char *);
1558 #endif
1560 diagnostic_for_asm (insn, msgid, &ap, /* warn = */ 1);
1561 va_end (ap);
1564 void
1565 warning VPARAMS ((const char *msgid, ...))
1567 #ifndef ANSI_PROTOTYPES
1568 const char *msgid;
1569 #endif
1570 va_list ap;
1571 diagnostic_context dc;
1573 VA_START (ap, msgid);
1575 #ifndef ANSI_PROTOTYPES
1576 msgid = va_arg (ap, const char *);
1577 #endif
1579 set_diagnostic_context
1580 (&dc, msgid, &ap, input_filename, lineno, /* warn = */ 1);
1581 report_diagnostic (&dc);
1582 va_end (ap);
1585 /* Flush diagnostic_buffer content on stderr. */
1587 static void
1588 finish_diagnostic ()
1590 output_to_stream (diagnostic_buffer, stderr);
1591 clear_diagnostic_info (diagnostic_buffer);
1592 fputc ('\n', stderr);
1593 fflush (stderr);
1596 /* Helper subroutine of output_verbatim and verbatim. Do the approriate
1597 settings needed by BUFFER for a verbatim formatting. */
1599 static void
1600 output_do_verbatim (buffer, msgid, args_ptr)
1601 output_buffer *buffer;
1602 const char *msgid;
1603 va_list *args_ptr;
1605 output_state os;
1607 os = output_buffer_state (buffer);
1608 output_prefix (buffer) = NULL;
1609 prefixing_policy (buffer) = DIAGNOSTICS_SHOW_PREFIX_NEVER;
1610 output_buffer_text_cursor (buffer) = _(msgid);
1611 output_buffer_ptr_to_format_args (buffer) = args_ptr;
1612 output_set_maximum_length (buffer, 0);
1613 output_format (buffer);
1614 output_buffer_state (buffer) = os;
1617 /* Output MESSAGE verbatim into BUFFER. */
1619 void
1620 output_verbatim VPARAMS ((output_buffer *buffer, const char *msgid, ...))
1622 #ifndef ANSI_PROTOTYPES
1623 output_buffer *buffer;
1624 const char *msgid;
1625 #endif
1626 va_list ap;
1628 VA_START (ap, msgid);
1629 #ifndef ANSI_PROTOTYPES
1630 buffer = va_arg (ap, output_buffer *);
1631 msgid = va_arg (ap, const char *);
1632 #endif
1633 output_do_verbatim (buffer, msgid, &ap);
1634 va_end (ap);
1637 /* Same as above but use diagnostic_buffer. */
1639 void
1640 verbatim VPARAMS ((const char *msgid, ...))
1642 #ifndef ANSI_PROTOTYPES
1643 const char *msgid;
1644 #endif
1645 va_list ap;
1647 VA_START (ap, msgid);
1648 #ifndef ANSI_PROTOTYPES
1649 msgid = va_arg (ap, const char *);
1650 #endif
1651 output_do_verbatim (diagnostic_buffer, msgid, &ap);
1652 output_to_stream (diagnostic_buffer, stderr);
1653 va_end (ap);
1656 /* Report a diagnostic message (an error or a warning) as specified by
1657 DC. This function is *the* subroutine in terms of which front-ends
1658 should implement their specific diagnostic handling modules. The
1659 front-end independent format specifiers are exactly those described
1660 in the documentation of output_format. */
1662 void
1663 report_diagnostic (dc)
1664 diagnostic_context *dc;
1666 output_state os;
1668 if (diagnostic_lock++)
1669 error_recursion ();
1671 if (count_error (diagnostic_is_warning (dc)))
1673 os = output_buffer_state (diagnostic_buffer);
1674 diagnostic_msg = diagnostic_message (dc);
1675 diagnostic_args = diagnostic_argument_list (dc);
1676 (*diagnostic_starter (dc)) (diagnostic_buffer, dc);
1677 output_format (diagnostic_buffer);
1678 (*diagnostic_finalizer (dc)) (diagnostic_buffer, dc);
1679 finish_diagnostic ();
1680 output_buffer_state (diagnostic_buffer) = os;
1683 diagnostic_lock--;
1686 /* Inform the user that an error occurred while trying to report some
1687 other error. This indicates catastrophic internal inconsistencies,
1688 so give up now. But do try to flush out the previous error.
1689 This mustn't use internal_error, that will cause infinite recursion. */
1691 static void
1692 error_recursion ()
1694 if (diagnostic_lock < 3)
1695 finish_diagnostic ();
1697 fnotice (stderr,
1698 "Internal compiler error: Error reporting routines re-entered.\n");
1699 fnotice (stderr,
1700 "Please submit a full bug report,\n\
1701 with preprocessed source if appropriate.\n\
1702 See %s for instructions.\n", GCCBUGURL);
1703 exit (FATAL_EXIT_CODE);
1706 /* Given a partial pathname as input, return another pathname that
1707 shares no directory elements with the pathname of __FILE__. This
1708 is used by fancy_abort() to print `Internal compiler error in expr.c'
1709 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
1711 const char *
1712 trim_filename (name)
1713 const char *name;
1715 static const char this_file[] = __FILE__;
1716 const char *p = name, *q = this_file;
1718 /* First skip any "../" in each filename. This allows us to give a proper
1719 reference to a file in a subdirectory. */
1720 while (p[0] == '.' && p[1] == '.'
1721 && (p[2] == DIR_SEPARATOR
1722 #ifdef DIR_SEPARATOR_2
1723 || p[2] == DIR_SEPARATOR_2
1724 #endif
1726 p += 3;
1728 while (q[0] == '.' && q[1] == '.'
1729 && (q[2] == DIR_SEPARATOR
1730 #ifdef DIR_SEPARATOR_2
1731 || p[2] == DIR_SEPARATOR_2
1732 #endif
1734 q += 3;
1736 /* Now skip any parts the two filenames have in common. */
1737 while (*p == *q && *p != 0 && *q != 0)
1738 p++, q++;
1740 /* Now go backwards until the previous directory separator. */
1741 while (p > name && p[-1] != DIR_SEPARATOR
1742 #ifdef DIR_SEPARATOR_2
1743 && p[-1] != DIR_SEPARATOR_2
1744 #endif
1746 p--;
1748 return p;
1751 /* Report an internal compiler error in a friendly manner and without
1752 dumping core. */
1754 void
1755 fancy_abort (file, line, function)
1756 const char *file;
1757 int line;
1758 const char *function;
1760 internal_error ("Internal compiler error in %s, at %s:%d",
1761 function, trim_filename (file), line);
1764 /* Setup DC for reporting a diagnostic MESSAGE (an error or a WARNING),
1765 using arguments pointed to by ARGS_PTR, issued at a location specified
1766 by FILE and LINE. */
1768 void
1769 set_diagnostic_context (dc, msgid, args_ptr, file, line, warn)
1770 diagnostic_context *dc;
1771 const char *msgid;
1772 va_list *args_ptr;
1773 const char *file;
1774 int line;
1775 int warn;
1777 memset (dc, 0, sizeof (diagnostic_context));
1778 diagnostic_message (dc) = _(msgid);
1779 diagnostic_argument_list (dc) = args_ptr;
1780 diagnostic_file_location (dc) = file;
1781 diagnostic_line_location (dc) = line;
1782 diagnostic_is_warning (dc) = warn;
1783 diagnostic_starter (dc) = lang_diagnostic_starter;
1784 diagnostic_finalizer (dc) = lang_diagnostic_finalizer;
1787 void
1788 report_problematic_module (buffer)
1789 output_buffer *buffer;
1791 struct file_stack *p;
1793 if (output_needs_newline (buffer))
1795 output_add_newline (buffer);
1796 output_needs_newline (buffer) = 0;
1799 if (input_file_stack && input_file_stack->next != 0
1800 && error_module_changed ())
1802 for (p = input_file_stack->next; p; p = p->next)
1803 if (p == input_file_stack->next)
1804 output_verbatim
1805 (buffer, "In file included from %s:%d", p->name, p->line);
1806 else
1807 output_verbatim
1808 (buffer, ",\n from %s:%d", p->name, p->line);
1809 output_verbatim (buffer, ":\n");
1810 record_last_error_module ();
1814 static void
1815 default_diagnostic_starter (buffer, dc)
1816 output_buffer *buffer;
1817 diagnostic_context *dc;
1819 report_error_function (diagnostic_file_location (dc));
1820 output_set_prefix (buffer,
1821 context_as_prefix (diagnostic_file_location (dc),
1822 diagnostic_line_location (dc),
1823 diagnostic_is_warning (dc)));
1826 static void
1827 default_diagnostic_finalizer (buffer, dc)
1828 output_buffer *buffer;
1829 diagnostic_context *dc __attribute__((__unused__));
1831 output_destroy_prefix (buffer);