* README: Replace with a cut-down and updated version of gcc/README.
[official-gcc.git] / gcc / diagnostic.c
blobbb75846c99b1fa8cabb55716f4557dad8c3a0bba
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_buffer_to_stream PARAMS ((output_buffer *));
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 warnings_are_errors;
108 /* Front-end specific tree formatter, if non-NULL. */
109 printer_fn lang_printer = NULL;
111 /* This must be large enough to hold any printed integer or
112 floating-point value. */
113 static char digit_buffer[128];
115 /* An output_buffer surrogate for stderr. */
116 static output_buffer global_output_buffer;
117 output_buffer *diagnostic_buffer = &global_output_buffer;
119 /* Function of last error message;
120 more generally, function such that if next error message is in it
121 then we don't have to mention the function name. */
122 static tree last_error_function = NULL;
124 /* Used to detect when input_file_stack has changed since last described. */
125 static int last_error_tick;
127 /* Called by report_error_function to print out function name.
128 Default may be overridden by language front-ends. */
130 void (*print_error_function) PARAMS ((const char *)) =
131 default_print_error_function;
133 /* Hooks for language specific diagnostic messages pager and finalizer. */
134 diagnostic_starter_fn lang_diagnostic_starter;
135 diagnostic_finalizer_fn lang_diagnostic_finalizer;
137 /* Maximum characters per line in automatic line wrapping mode.
138 Zero means don't wrap lines. */
140 int diagnostic_message_length_per_line;
142 /* Used to control every diagnostic message formatting. Front-ends should
143 call set_message_prefixing_rule to set up their policies. */
144 static int current_prefixing_rule;
146 /* Prevent recursion into the error handler. */
147 static int diagnostic_lock;
150 /* Return truthvalue if current input file is different from the most recent
151 file involved in a diagnostic message. */
154 error_module_changed ()
156 return last_error_tick != input_file_stack_tick;
159 /* Remember current file as being the most recent file involved in a
160 diagnostic message. */
162 void
163 record_last_error_module ()
165 last_error_tick = input_file_stack_tick;
168 /* Same as error_module_changed, but for function. */
171 error_function_changed ()
173 return last_error_function != current_function_decl;
176 /* Same as record_last_error_module, but for function. */
178 void
179 record_last_error_function ()
181 last_error_function = current_function_decl;
184 /* Initialize the diagnostic message outputting machinery. */
186 void
187 initialize_diagnostics ()
189 /* By default, we don't line-wrap messages. */
190 diagnostic_message_length_per_line = 0;
191 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
193 /* Proceed to actual initialization. */
194 default_initialize_buffer (diagnostic_buffer);
196 lang_diagnostic_starter = default_diagnostic_starter;
197 lang_diagnostic_finalizer = default_diagnostic_finalizer;
200 void
201 set_message_prefixing_rule (rule)
202 int rule;
204 current_prefixing_rule = rule;
207 /* Returns true if BUFFER is in line-wrappind mode. */
210 output_is_line_wrapping (buffer)
211 output_buffer *buffer;
213 return ideal_line_wrap_cutoff (buffer) > 0;
216 /* Return BUFFER's prefix. */
218 const char *
219 output_get_prefix (buffer)
220 const output_buffer *buffer;
222 return output_prefix (buffer);
225 /* Subroutine of output_set_maximum_length. Set up BUFFER's
226 internal maximum characters per line. */
228 static void
229 set_real_maximum_length (buffer)
230 output_buffer *buffer;
232 /* If we're told not to wrap lines then do the obvious thing. In case
233 we'll emit prefix only once per diagnostic message, it is appropriate
234 not to increase unncessarily the line-length cut-off. */
235 if (! output_is_line_wrapping (buffer)
236 || prefixing_policy (buffer) == DIAGNOSTICS_SHOW_PREFIX_ONCE
237 || prefixing_policy (buffer) == DIAGNOSTICS_SHOW_PREFIX_NEVER)
238 line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer);
239 else
241 int prefix_length =
242 output_prefix (buffer) ? strlen (output_prefix (buffer)) : 0;
243 /* If the prefix is ridiculously too long, output at least
244 32 characters. */
245 if (ideal_line_wrap_cutoff (buffer) - prefix_length < 32)
246 line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer) + 32;
247 else
248 line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer);
252 /* Sets the number of maximum characters per line BUFFER can output
253 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
255 void
256 output_set_maximum_length (buffer, length)
257 output_buffer *buffer;
258 int length;
260 ideal_line_wrap_cutoff (buffer) = length;
261 set_real_maximum_length (buffer);
264 /* Sets BUFFER's PREFIX. */
266 void
267 output_set_prefix (buffer, prefix)
268 output_buffer *buffer;
269 const char *prefix;
271 output_prefix (buffer) = prefix;
272 set_real_maximum_length (buffer);
273 prefix_was_emitted_for (buffer) = 0;
274 output_indentation (buffer) = 0;
277 /* Return a pointer to the last character emitted in the output
278 BUFFER area. A NULL pointer means no character available. */
279 const char *
280 output_last_position (buffer)
281 const output_buffer *buffer;
283 const char *p = NULL;
285 if (obstack_base (&buffer->obstack) != obstack_next_free (&buffer->obstack))
286 p = ((const char *) obstack_next_free (&buffer->obstack)) - 1;
287 return p;
290 /* Free BUFFER's prefix, a previously malloc'd string. */
292 void
293 output_destroy_prefix (buffer)
294 output_buffer *buffer;
296 if (output_prefix (buffer) != NULL)
298 free ((char *) output_prefix (buffer));
299 output_prefix (buffer) = NULL;
303 /* Zero out any text output so far in BUFFER. */
305 void
306 output_clear_message_text (buffer)
307 output_buffer *buffer;
309 obstack_free (&buffer->obstack, obstack_base (&buffer->obstack));
310 output_text_length (buffer) = 0;
313 /* Zero out any diagnostic data used so far by BUFFER. */
315 static void
316 clear_diagnostic_info (buffer)
317 output_buffer *buffer;
319 output_buffer_text_cursor (buffer) = NULL;
320 output_buffer_ptr_to_format_args (buffer) = NULL;
321 prefix_was_emitted_for (buffer) = 0;
322 output_indentation (buffer) = 0;
325 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
326 characters per line. */
328 void
329 init_output_buffer (buffer, prefix, maximum_length)
330 output_buffer *buffer;
331 const char *prefix;
332 int maximum_length;
334 memset (buffer, 0, sizeof (output_buffer));
335 obstack_init (&buffer->obstack);
336 output_buffer_attached_stream (buffer) = stderr;
337 ideal_line_wrap_cutoff (buffer) = maximum_length;
338 prefixing_policy (buffer) = current_prefixing_rule;
339 output_set_prefix (buffer, prefix);
340 output_text_length (buffer) = 0;
341 clear_diagnostic_info (buffer);
344 /* Initialize BUFFER with a NULL prefix and current diagnostic message
345 length cutoff. */
347 void
348 default_initialize_buffer (buffer)
349 output_buffer *buffer;
351 init_output_buffer (buffer, NULL, diagnostic_message_length_per_line);
354 /* Recompute diagnostic_buffer's attributes to reflect any change
355 in diagnostic formatting global options. */
357 void
358 reshape_diagnostic_buffer ()
360 ideal_line_wrap_cutoff (diagnostic_buffer) =
361 diagnostic_message_length_per_line;
362 prefixing_policy (diagnostic_buffer) = current_prefixing_rule;
363 set_real_maximum_length (diagnostic_buffer);
366 /* Reinitialize BUFFER. */
368 void
369 output_clear (buffer)
370 output_buffer *buffer;
372 output_clear_message_text (buffer);
373 clear_diagnostic_info (buffer);
376 /* Finishes constructing a NULL-terminated character string representing
377 the BUFFERed message. */
379 const char *
380 output_finalize_message (buffer)
381 output_buffer *buffer;
383 obstack_1grow (&buffer->obstack, '\0');
384 return output_message_text (buffer);
387 void
388 flush_diagnostic_buffer ()
390 output_buffer_to_stream (diagnostic_buffer);
391 fflush (output_buffer_attached_stream (diagnostic_buffer));
394 /* Return the amount of characters BUFFER can accept to
395 make a full line. */
398 output_space_left (buffer)
399 const output_buffer *buffer;
401 return line_wrap_cutoff (buffer) - output_text_length (buffer);
404 /* Write out BUFFER's prefix. */
406 void
407 output_emit_prefix (buffer)
408 output_buffer *buffer;
410 if (output_prefix (buffer) != NULL)
412 switch (prefixing_policy (buffer))
414 default:
415 case DIAGNOSTICS_SHOW_PREFIX_NEVER:
416 break;
418 case DIAGNOSTICS_SHOW_PREFIX_ONCE:
419 if (prefix_was_emitted_for (buffer))
421 output_indent (buffer);
422 break;
424 output_indentation (buffer) += 3;
425 /* Fall through. */
427 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE:
429 int prefix_length = strlen (output_prefix (buffer));
430 output_append_r (buffer, output_prefix (buffer), prefix_length);
431 prefix_was_emitted_for (buffer) = 1;
433 break;
438 /* Have BUFFER start a new line. */
440 void
441 output_add_newline (buffer)
442 output_buffer *buffer;
444 obstack_1grow (&buffer->obstack, '\n');
445 output_text_length (buffer) = 0;
448 /* Appends a character to BUFFER. */
450 void
451 output_add_character (buffer, c)
452 output_buffer *buffer;
453 int c;
455 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
456 output_add_newline (buffer);
457 obstack_1grow (&buffer->obstack, c);
458 ++output_text_length (buffer);
461 /* Adds a space to BUFFER. */
463 void
464 output_add_space (buffer)
465 output_buffer *buffer;
467 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
469 output_add_newline (buffer);
470 return;
472 obstack_1grow (&buffer->obstack, ' ');
473 ++output_text_length (buffer);
476 /* These functions format an INTEGER into BUFFER as suggested by their
477 names. */
479 void
480 output_decimal (buffer, i)
481 output_buffer *buffer;
482 int i;
484 output_formatted_integer (buffer, "%d", i);
487 static void
488 output_long_decimal (buffer, i)
489 output_buffer *buffer;
490 long int i;
492 output_formatted_integer (buffer, "%ld", i);
495 static void
496 output_unsigned_decimal (buffer, i)
497 output_buffer *buffer;
498 unsigned int i;
500 output_formatted_integer (buffer, "%u", i);
503 static void
504 output_long_unsigned_decimal (buffer, i)
505 output_buffer *buffer;
506 long unsigned int i;
508 output_formatted_integer (buffer, "%lu", i);
511 static void
512 output_octal (buffer, i)
513 output_buffer *buffer;
514 unsigned int i;
516 output_formatted_integer (buffer, "%o", i);
519 static void
520 output_long_octal (buffer, i)
521 output_buffer *buffer;
522 unsigned long int i;
524 output_formatted_integer (buffer, "%lo", i);
527 static void
528 output_hexadecimal (buffer, i)
529 output_buffer *buffer;
530 unsigned int i;
532 output_formatted_integer (buffer, "%x", i);
535 static void
536 output_long_hexadecimal (buffer, i)
537 output_buffer *buffer;
538 unsigned long int i;
540 output_formatted_integer (buffer, "%lx", i);
543 /* Append to BUFFER a string specified by its STARTING character
544 and LENGTH. */
546 static void
547 output_append_r (buffer, start, length)
548 output_buffer *buffer;
549 const char *start;
550 int length;
552 obstack_grow (&buffer->obstack, start, length);
553 output_text_length (buffer) += length;
556 /* Append a string deliminated by START and END to BUFFER. No wrapping is
557 done. However, if beginning a new line then emit output_prefix (BUFFER)
558 and skip any leading whitespace if appropriate. The caller must ensure
559 that it is safe to do so. */
561 void
562 output_append (buffer, start, end)
563 output_buffer *buffer;
564 const char *start;
565 const char *end;
567 /* Emit prefix and skip whitespace if we're starting a new line. */
568 if (is_starting_newline (buffer))
570 output_emit_prefix (buffer);
571 if (output_is_line_wrapping (buffer))
572 while (start != end && *start == ' ')
573 ++start;
575 output_append_r (buffer, start, end - start);
578 static void
579 output_indent (buffer)
580 output_buffer *buffer;
582 int n = output_indentation (buffer);
583 int i;
585 for (i = 0; i < n; ++i)
586 output_add_character (buffer, ' ');
589 /* Wrap a text delimited by START and END into BUFFER. */
591 static void
592 wrap_text (buffer, start, end)
593 output_buffer *buffer;
594 const char *start;
595 const char *end;
597 int is_wrapping = output_is_line_wrapping (buffer);
599 while (start != end)
601 /* Dump anything bodered by whitespaces. */
603 const char *p = start;
604 while (p != end && *p != ' ' && *p != '\n')
605 ++p;
606 if (is_wrapping && p - start >= output_space_left (buffer))
607 output_add_newline (buffer);
608 output_append (buffer, start, p);
609 start = p;
612 if (start != end && *start == ' ')
614 output_add_space (buffer);
615 ++start;
617 if (start != end && *start == '\n')
619 output_add_newline (buffer);
620 ++start;
625 /* Same as wrap_text but wrap text only when in line-wrapping mode. */
627 static void
628 maybe_wrap_text (buffer, start, end)
629 output_buffer *buffer;
630 const char *start;
631 const char *end;
633 if (output_is_line_wrapping (buffer))
634 wrap_text (buffer, start, end);
635 else
636 output_append (buffer, start, end);
640 /* Append a STRING to BUFFER; the STRING might be line-wrapped if in
641 appropriate mode. */
643 void
644 output_add_string (buffer, str)
645 output_buffer *buffer;
646 const char *str;
648 maybe_wrap_text (buffer, str, str + (str ? strlen (str) : 0));
651 /* Flush the content of BUFFER onto the attached stream,
652 and reinitialize. */
654 static void
655 output_buffer_to_stream (buffer)
656 output_buffer *buffer;
658 const char *text = output_finalize_message (buffer);
659 fputs (text, output_buffer_attached_stream (buffer));
660 output_clear_message_text (buffer);
663 /* Format a message pointed to by output_buffer_text_cursor (BUFFER) using
664 output_buffer_format_args (BUFFER) as appropriate. The following format
665 specifiers are recognized as being language independent:
666 %d, %i: (signed) integer in base ten.
667 %u: unsigned integer in base ten.
668 %o: unsigned integer in base eight.
669 %x: unsigned integer in base sixteen.
670 %ld, %li, %lo, %lu, %lx: long versions of the above.
671 %c: character.
672 %s: string.
673 %%: `%'.
674 %*.s: a substring the length of which is specified by an integer. */
676 static void
677 output_format (buffer)
678 output_buffer *buffer;
680 for (; *output_buffer_text_cursor (buffer);
681 ++output_buffer_text_cursor (buffer))
683 int long_integer = 0;
685 /* Ignore text. */
687 const char *p = output_buffer_text_cursor (buffer);
688 while (*p && *p != '%')
689 ++p;
690 wrap_text (buffer, output_buffer_text_cursor (buffer), p);
691 output_buffer_text_cursor (buffer) = p;
694 if (!*output_buffer_text_cursor (buffer))
695 break;
697 /* We got a '%'. Let's see what happens. Record whether we're
698 parsing a long integer format specifier. */
699 if (*++output_buffer_text_cursor (buffer) == 'l')
701 long_integer = 1;
702 ++output_buffer_text_cursor (buffer);
705 /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %o, %s, %u,
706 %x, %.*s; %%. And nothing else. Front-ends should install
707 printers to grok language specific format specifiers. */
708 switch (*output_buffer_text_cursor (buffer))
710 case 'c':
711 output_add_character
712 (buffer, va_arg (output_buffer_format_args (buffer), int));
713 break;
715 case 'd':
716 case 'i':
717 if (long_integer)
718 output_long_decimal
719 (buffer, va_arg (output_buffer_format_args (buffer), long int));
720 else
721 output_decimal
722 (buffer, va_arg (output_buffer_format_args (buffer), int));
723 break;
725 case 'o':
726 if (long_integer)
727 output_long_octal (buffer,
728 va_arg (output_buffer_format_args (buffer),
729 unsigned long int));
730 else
731 output_octal (buffer,
732 va_arg (output_buffer_format_args (buffer),
733 unsigned int));
734 break;
736 case 's':
737 output_add_string (buffer,
738 va_arg (output_buffer_format_args (buffer),
739 const char *));
740 break;
742 case 'u':
743 if (long_integer)
744 output_long_unsigned_decimal
745 (buffer, va_arg (output_buffer_format_args (buffer),
746 long unsigned int));
747 else
748 output_unsigned_decimal
749 (buffer, va_arg (output_buffer_format_args (buffer),
750 unsigned int));
751 break;
753 case 'x':
754 if (long_integer)
755 output_long_hexadecimal
756 (buffer, va_arg (output_buffer_format_args (buffer),
757 unsigned long int));
758 else
759 output_hexadecimal
760 (buffer, va_arg (output_buffer_format_args (buffer),
761 unsigned int));
762 break;
764 case '%':
765 output_add_character (buffer, '%');
766 break;
768 case '.':
770 int n;
771 const char *s;
772 /* We handle no precision specifier but `%.*s'. */
773 if (*++output_buffer_text_cursor (buffer) != '*')
774 abort ();
775 else if (*++output_buffer_text_cursor (buffer) != 's')
776 abort();
777 n = va_arg (output_buffer_format_args (buffer), int);
778 s = va_arg (output_buffer_format_args (buffer), const char *);
779 output_append (buffer, s, s + n);
781 break;
783 default:
784 if (! lang_printer || !(*lang_printer) (buffer))
786 /* Hmmm. The front-end failed to install a format translator
787 but called us with an unrecognized format. Sorry. */
788 abort ();
794 static char *
795 vbuild_message_string (msg, ap)
796 const char *msg;
797 va_list ap;
799 char *str;
801 vasprintf (&str, msg, ap);
802 return str;
805 /* Return a malloc'd string containing MSG formatted a la
806 printf. The caller is reponsible for freeing the memory. */
808 static char *
809 build_message_string VPARAMS ((const char *msg, ...))
811 #ifndef ANSI_PROTOTYPES
812 const char *msg;
813 #endif
814 va_list ap;
815 char *str;
817 VA_START (ap, msg);
819 #ifndef ANSI_PROTOTYPES
820 msg = va_arg (ap, const char *);
821 #endif
823 str = vbuild_message_string (msg, ap);
825 va_end (ap);
827 return str;
830 /* Return a malloc'd string describing a location. The caller is
831 responsible for freeing the memory. */
833 char *
834 context_as_prefix (file, line, warn)
835 const char *file;
836 int line;
837 int warn;
839 if (file)
841 if (warn)
842 return build_message_string (_("%s:%d: warning: "), file, line);
843 else
844 return build_message_string ("%s:%d: ", file, line);
846 else
848 if (warn)
849 return build_message_string (_("%s: warning: "), progname);
850 else
851 return build_message_string ("%s: ", progname);
855 /* Same as context_as_prefix, but only the source FILE is given. */
857 char *
858 file_name_as_prefix (f)
859 const char *f;
861 return build_message_string ("%s: ", f);
864 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
866 static void
867 output_do_printf (buffer, msg)
868 output_buffer *buffer;
869 const char *msg;
871 char *message = vbuild_message_string (msg,
872 output_buffer_format_args (buffer));
874 wrap_text (buffer, message, message + strlen (message));
875 free (message);
879 /* Format a message into BUFFER a la printf. */
881 void
882 output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
884 #ifndef ANSI_PROTOTYPES
885 struct output_buffer *buffer;
886 const char *msgid;
887 #endif
888 va_list ap;
889 va_list *old_args;
891 VA_START (ap, msgid);
892 #ifndef ANSI_PROTOTYPES
893 buffer = va_arg (ap, output_buffer *);
894 msgid = va_arg (ap, const char *);
895 #endif
896 old_args = output_buffer_ptr_to_format_args (buffer);
897 output_buffer_ptr_to_format_args (buffer) = &ap;
898 output_do_printf (buffer, _(msgid));
899 output_buffer_ptr_to_format_args (buffer) = old_args;
900 va_end (ap);
903 /* Print a message relevant to the given DECL. */
905 static void
906 format_with_decl (buffer, decl)
907 output_buffer *buffer;
908 tree decl;
910 const char *p;
912 /* Do magic to get around lack of varargs support for insertion
913 of arguments into existing list. We know that the decl is first;
914 we ass_u_me that it will be printed with "%s". */
915 for (p = output_buffer_text_cursor (buffer); *p; ++p)
917 if (*p == '%')
919 if (*(p + 1) == '%')
920 ++p;
921 else if (*(p + 1) != 's')
922 abort ();
923 else
924 break;
928 /* Print the left-hand substring. */
929 maybe_wrap_text (buffer, output_buffer_text_cursor (buffer), p);
931 if (*p == '%') /* Print the name. */
933 const char *n = (DECL_NAME (decl)
934 ? (*decl_printable_name) (decl, 2)
935 : _("((anonymous))"));
936 output_add_string (buffer, n);
937 while (*p)
939 ++p;
940 if (ISALPHA (*(p - 1) & 0xFF))
941 break;
945 if (*p) /* Print the rest of the message. */
947 output_buffer_text_cursor (buffer) = p;
948 output_format (buffer);
952 /* Figure file and line of the given INSN. */
954 static void
955 file_and_line_for_asm (insn, pfile, pline)
956 rtx insn;
957 const char **pfile;
958 int *pline;
960 rtx body = PATTERN (insn);
961 rtx asmop;
963 /* Find the (or one of the) ASM_OPERANDS in the insn. */
964 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
965 asmop = SET_SRC (body);
966 else if (GET_CODE (body) == ASM_OPERANDS)
967 asmop = body;
968 else if (GET_CODE (body) == PARALLEL
969 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
970 asmop = SET_SRC (XVECEXP (body, 0, 0));
971 else if (GET_CODE (body) == PARALLEL
972 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
973 asmop = XVECEXP (body, 0, 0);
974 else
975 asmop = NULL;
977 if (asmop)
979 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
980 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
982 else
984 *pfile = input_filename;
985 *pline = lineno;
989 /* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
990 of the insn INSN. This is used only when INSN is an `asm' with operands,
991 and each ASM_OPERANDS records its own source file and line. */
993 static void
994 diagnostic_for_asm (insn, msg, args_ptr, warn)
995 rtx insn;
996 const char *msg;
997 va_list *args_ptr;
998 int warn;
1000 diagnostic_context dc;
1002 set_diagnostic_context (&dc, msg, args_ptr, NULL, 0, warn);
1003 file_and_line_for_asm (insn, &diagnostic_file_location (&dc),
1004 &diagnostic_line_location (&dc));
1005 report_diagnostic (&dc);
1008 /* Report a diagnostic MESSAGE at the declaration DECL.
1009 MSG is a format string which uses %s to substitute the declaration
1010 name; subsequent substitutions are a la output_format. */
1012 static void
1013 diagnostic_for_decl (decl, msgid, args_ptr, warn)
1014 tree decl;
1015 const char *msgid;
1016 va_list *args_ptr;
1017 int warn;
1019 output_state os;
1021 if (diagnostic_lock++)
1022 error_recursion ();
1024 if (count_error (warn))
1026 os = output_buffer_state (diagnostic_buffer);
1027 report_error_function (DECL_SOURCE_FILE (decl));
1028 output_set_prefix
1029 (diagnostic_buffer, context_as_prefix
1030 (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn));
1031 output_buffer_ptr_to_format_args (diagnostic_buffer) = args_ptr;
1032 output_buffer_text_cursor (diagnostic_buffer) = _(msgid);
1033 format_with_decl (diagnostic_buffer, decl);
1034 finish_diagnostic ();
1035 output_destroy_prefix (diagnostic_buffer);
1037 output_buffer_state (diagnostic_buffer) = os;
1039 diagnostic_lock--;
1043 /* Count an error or warning. Return 1 if the message should be printed. */
1046 count_error (warningp)
1047 int warningp;
1049 if (warningp && !diagnostic_report_warnings_p ())
1050 return 0;
1052 if (warningp && !warnings_are_errors)
1053 warningcount++;
1054 else
1056 static int warning_message = 0;
1058 if (warningp && !warning_message)
1060 verbatim ("%s: warnings being treated as errors\n", progname);
1061 warning_message = 1;
1063 errorcount++;
1066 return 1;
1069 /* Print a diagnostic MSGID on FILE. This is just fprintf, except it
1070 runs its second argument through gettext. */
1072 void
1073 fnotice VPARAMS ((FILE *file, const char *msgid, ...))
1075 #ifndef ANSI_PROTOTYPES
1076 FILE *file;
1077 const char *msgid;
1078 #endif
1079 va_list ap;
1081 VA_START (ap, msgid);
1083 #ifndef ANSI_PROTOTYPES
1084 file = va_arg (ap, FILE *);
1085 msgid = va_arg (ap, const char *);
1086 #endif
1088 vfprintf (file, _(msgid), ap);
1089 va_end (ap);
1093 /* Print a fatal I/O error message. Argument are like printf.
1094 Also include a system error message based on `errno'. */
1096 void
1097 fatal_io_error VPARAMS ((const char *msgid, ...))
1099 #ifndef ANSI_PROTOTYPES
1100 const char *msgid;
1101 #endif
1102 va_list ap;
1103 output_state os;
1105 os = output_buffer_state (diagnostic_buffer);
1106 VA_START (ap, msgid);
1108 #ifndef ANSI_PROTOTYPES
1109 msgid = va_arg (ap, const char *);
1110 #endif
1112 output_printf (diagnostic_buffer, "%s: %s: ", progname, xstrerror (errno));
1113 output_buffer_ptr_to_format_args (diagnostic_buffer) = &ap;
1114 output_buffer_text_cursor (diagnostic_buffer) = _(msgid);
1115 output_format (diagnostic_buffer);
1116 finish_diagnostic ();
1117 output_buffer_state (diagnostic_buffer) = os;
1118 va_end (ap);
1119 exit (FATAL_EXIT_CODE);
1122 /* Issue a pedantic warning MSGID. */
1124 void
1125 pedwarn VPARAMS ((const char *msgid, ...))
1127 #ifndef ANSI_PROTOTYPES
1128 const char *msgid;
1129 #endif
1130 va_list ap;
1131 diagnostic_context dc;
1133 VA_START (ap, msgid);
1135 #ifndef ANSI_PROTOTYPES
1136 msgid = va_arg (ap, const char *);
1137 #endif
1139 set_diagnostic_context
1140 (&dc, msgid, &ap, input_filename, lineno, !flag_pedantic_errors);
1141 report_diagnostic (&dc);
1142 va_end (ap);
1145 /* Issue a pedantic waring about DECL. */
1147 void
1148 pedwarn_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1150 #ifndef ANSI_PROTOTYPES
1151 tree decl;
1152 const char *msgid;
1153 #endif
1154 va_list ap;
1156 VA_START (ap, msgid);
1158 #ifndef ANSI_PROTOTYPES
1159 decl = va_arg (ap, tree);
1160 msgid = va_arg (ap, const char *);
1161 #endif
1162 /* We don't want -pedantic-errors to cause the compilation to fail from
1163 "errors" in system header files. Sometimes fixincludes can't fix what's
1164 broken (eg: unsigned char bitfields - fixing it may change the alignment
1165 which will cause programs to mysteriously fail because the C library
1166 or kernel uses the original layout). There's no point in issuing a
1167 warning either, it's just unnecessary noise. */
1168 if (!DECL_IN_SYSTEM_HEADER (decl))
1169 diagnostic_for_decl (decl, msgid, &ap, !flag_pedantic_errors);
1170 va_end (ap);
1173 /* Same as above but within the context FILE and LINE. */
1175 void
1176 pedwarn_with_file_and_line VPARAMS ((const char *file, int line,
1177 const char *msgid, ...))
1179 #ifndef ANSI_PROTOTYPES
1180 const char *file;
1181 int line;
1182 const char *msgid;
1183 #endif
1184 va_list ap;
1185 diagnostic_context dc;
1187 VA_START (ap, msgid);
1189 #ifndef ANSI_PROTOTYPES
1190 file = va_arg (ap, const char *);
1191 line = va_arg (ap, int);
1192 msgid = va_arg (ap, const char *);
1193 #endif
1195 set_diagnostic_context (&dc, msgid, &ap, file, line, !flag_pedantic_errors);
1196 report_diagnostic (&dc);
1197 va_end (ap);
1200 /* Just apologize with MSGID. */
1202 void
1203 sorry VPARAMS ((const char *msgid, ...))
1205 #ifndef ANSI_PROTOTYPES
1206 const char *msgid;
1207 #endif
1208 va_list ap;
1209 output_state os;
1211 os = output_buffer_state (diagnostic_buffer);
1212 VA_START (ap, msgid);
1214 #ifndef ANSI_PROTOTYPES
1215 msgid = va_arg (ap, const char *);
1216 #endif
1217 ++sorrycount;
1218 output_set_prefix
1219 (diagnostic_buffer, context_as_prefix (input_filename, lineno, 0));
1220 output_printf (diagnostic_buffer, "sorry, not implemented: ");
1221 output_buffer_ptr_to_format_args (diagnostic_buffer) = &ap;
1222 output_buffer_text_cursor (diagnostic_buffer) = _(msgid);
1223 output_format (diagnostic_buffer);
1224 finish_diagnostic ();
1225 output_buffer_state (diagnostic_buffer) = os;
1226 va_end (ap);
1229 /* Called when the start of a function definition is parsed,
1230 this function prints on stderr the name of the function. */
1232 void
1233 announce_function (decl)
1234 tree decl;
1236 if (! quiet_flag)
1238 if (rtl_dump_and_exit)
1239 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1240 else
1241 verbatim (" %s", (*decl_printable_name) (decl, 2));
1242 fflush (stderr);
1243 output_needs_newline (diagnostic_buffer) = 1;
1244 record_last_error_function ();
1248 /* The default function to print out name of current function that caused
1249 an error. */
1251 void
1252 default_print_error_function (file)
1253 const char *file;
1255 if (error_function_changed ())
1257 char *prefix = file ? build_message_string ("%s: ", file) : NULL;
1258 output_state os;
1260 os = output_buffer_state (diagnostic_buffer);
1261 output_set_prefix (diagnostic_buffer, prefix);
1263 if (current_function_decl == NULL)
1264 output_add_string (diagnostic_buffer, _("At top level:"));
1265 else
1267 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1268 output_printf
1269 (diagnostic_buffer, "In method `%s':",
1270 (*decl_printable_name) (current_function_decl, 2));
1271 else
1272 output_printf
1273 (diagnostic_buffer, "In function `%s':",
1274 (*decl_printable_name) (current_function_decl, 2));
1276 output_add_newline (diagnostic_buffer);
1278 record_last_error_function ();
1279 output_buffer_to_stream (diagnostic_buffer);
1280 output_buffer_state (diagnostic_buffer) = os;
1281 free ((char*) prefix);
1285 /* Prints out, if necessary, the name of the current function
1286 that caused an error. Called from all error and warning functions.
1287 We ignore the FILE parameter, as it cannot be relied upon. */
1289 void
1290 report_error_function (file)
1291 const char *file ATTRIBUTE_UNUSED;
1293 report_problematic_module (diagnostic_buffer);
1294 (*print_error_function) (input_filename);
1297 void
1298 error_with_file_and_line VPARAMS ((const char *file, int line,
1299 const char *msgid, ...))
1301 #ifndef ANSI_PROTOTYPES
1302 const char *file;
1303 int line;
1304 const char *msgid;
1305 #endif
1306 va_list ap;
1307 diagnostic_context dc;
1309 VA_START (ap, msgid);
1311 #ifndef ANSI_PROTOTYPES
1312 file = va_arg (ap, const char *);
1313 line = va_arg (ap, int);
1314 msgid = va_arg (ap, const char *);
1315 #endif
1317 set_diagnostic_context (&dc, msgid, &ap, file, line, /* warn = */ 0);
1318 report_diagnostic (&dc);
1319 va_end (ap);
1322 void
1323 error_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1325 #ifndef ANSI_PROTOTYPES
1326 tree decl;
1327 const char *msgid;
1328 #endif
1329 va_list ap;
1331 VA_START (ap, msgid);
1333 #ifndef ANSI_PROTOTYPES
1334 decl = va_arg (ap, tree);
1335 msgid = va_arg (ap, const char *);
1336 #endif
1338 diagnostic_for_decl (decl, msgid, &ap, /* warn = */ 0);
1339 va_end (ap);
1342 void
1343 error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1345 #ifndef ANSI_PROTOTYPES
1346 rtx insn;
1347 const char *msgid;
1348 #endif
1349 va_list ap;
1351 VA_START (ap, msgid);
1353 #ifndef ANSI_PROTOTYPES
1354 insn = va_arg (ap, rtx);
1355 msgid = va_arg (ap, const char *);
1356 #endif
1358 diagnostic_for_asm (insn, msgid, &ap, /* warn = */ 0);
1359 va_end (ap);
1362 /* Report an error message. The arguments are like that of printf. */
1364 void
1365 error VPARAMS ((const char *msgid, ...))
1367 #ifndef ANSI_PROTOTYPES
1368 const char *msgid;
1369 #endif
1370 va_list ap;
1371 diagnostic_context dc;
1373 VA_START (ap, msgid);
1375 #ifndef ANSI_PROTOTYPES
1376 msgid = va_arg (ap, const char *);
1377 #endif
1379 set_diagnostic_context
1380 (&dc, msgid, &ap, input_filename, lineno, /* warn = */ 0);
1381 report_diagnostic (&dc);
1382 va_end (ap);
1385 /* Likewise, except that the compilation is terminated after printing the
1386 error message. */
1388 void
1389 fatal_error VPARAMS ((const char *msgid, ...))
1391 #ifndef ANSI_PROTOTYPES
1392 const char *msgid;
1393 #endif
1394 va_list ap;
1395 diagnostic_context dc;
1397 VA_START (ap, msgid);
1399 #ifndef ANSI_PROTOTYPES
1400 msgid = va_arg (ap, const char *);
1401 #endif
1403 set_diagnostic_context
1404 (&dc, msgid, &ap, input_filename, lineno, /* warn = */ 0);
1405 report_diagnostic (&dc);
1406 va_end (ap);
1408 fnotice (stderr, "compilation terminated.\n");
1409 exit (FATAL_EXIT_CODE);
1412 /* Report a compiler error at the current line number. Allow a front end to
1413 intercept the message. */
1415 static void (*internal_error_function) PARAMS ((const char *, va_list *));
1417 /* Set the function to call when a compiler error occurs. */
1419 void
1420 set_internal_error_function (f)
1421 void (*f) PARAMS ((const char *, va_list *));
1423 internal_error_function = f;
1426 void
1427 internal_error VPARAMS ((const char *msgid, ...))
1429 #ifndef ANSI_PROTOTYPES
1430 const char *msgid;
1431 #endif
1432 va_list ap;
1433 diagnostic_context dc;
1435 VA_START (ap, msgid);
1437 #ifndef ANSI_PROTOTYPES
1438 msgid = va_arg (ap, const char *);
1439 #endif
1441 if (errorcount > 0 || sorrycount > 0)
1443 fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
1444 input_filename, lineno);
1445 exit (FATAL_EXIT_CODE);
1448 if (internal_error_function != 0)
1449 (*internal_error_function) (_(msgid), &ap);
1451 set_diagnostic_context
1452 (&dc, msgid, &ap, input_filename, lineno, /* warn = */0);
1453 report_diagnostic (&dc);
1454 va_end (ap);
1456 fnotice (stderr,
1457 "Please submit a full bug report,\n\
1458 with preprocessed source if appropriate.\n\
1459 See %s for instructions.\n", GCCBUGURL);
1460 exit (FATAL_EXIT_CODE);
1463 void
1464 _fatal_insn (msgid, insn, file, line, function)
1465 const char *msgid;
1466 rtx insn;
1467 const char *file;
1468 int line;
1469 const char *function;
1471 error ("%s", _(msgid));
1473 /* The above incremented error_count, but isn't an error that we want to
1474 count, so reset it here. */
1475 errorcount--;
1477 debug_rtx (insn);
1478 fancy_abort (file, line, function);
1481 void
1482 _fatal_insn_not_found (insn, file, line, function)
1483 rtx insn;
1484 const char *file;
1485 int line;
1486 const char *function;
1488 if (INSN_CODE (insn) < 0)
1489 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1490 else
1491 _fatal_insn ("Insn does not satisfy its constraints:",
1492 insn, file, line, function);
1495 void
1496 warning_with_file_and_line VPARAMS ((const char *file, int line,
1497 const char *msgid, ...))
1499 #ifndef ANSI_PROTOTYPES
1500 const char *file;
1501 int line;
1502 const char *msgid;
1503 #endif
1504 va_list ap;
1505 diagnostic_context dc;
1507 VA_START (ap, msgid);
1509 #ifndef ANSI_PROTOTYPES
1510 file = va_arg (ap, const char *);
1511 line = va_arg (ap, int);
1512 msgid = va_arg (ap, const char *);
1513 #endif
1515 set_diagnostic_context (&dc, msgid, &ap, file, line, /* warn = */ 1);
1516 report_diagnostic (&dc);
1517 va_end (ap);
1520 void
1521 warning_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1523 #ifndef ANSI_PROTOTYPES
1524 tree decl;
1525 const char *msgid;
1526 #endif
1527 va_list ap;
1529 VA_START (ap, msgid);
1531 #ifndef ANSI_PROTOTYPES
1532 decl = va_arg (ap, tree);
1533 msgid = va_arg (ap, const char *);
1534 #endif
1536 diagnostic_for_decl (decl, msgid, &ap, /* warn = */ 1);
1537 va_end (ap);
1540 void
1541 warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1543 #ifndef ANSI_PROTOTYPES
1544 rtx insn;
1545 const char *msgid;
1546 #endif
1547 va_list ap;
1549 VA_START (ap, msgid);
1551 #ifndef ANSI_PROTOTYPES
1552 insn = va_arg (ap, rtx);
1553 msgid = va_arg (ap, const char *);
1554 #endif
1556 diagnostic_for_asm (insn, msgid, &ap, /* warn = */ 1);
1557 va_end (ap);
1560 void
1561 warning VPARAMS ((const char *msgid, ...))
1563 #ifndef ANSI_PROTOTYPES
1564 const char *msgid;
1565 #endif
1566 va_list ap;
1567 diagnostic_context dc;
1569 VA_START (ap, msgid);
1571 #ifndef ANSI_PROTOTYPES
1572 msgid = va_arg (ap, const char *);
1573 #endif
1575 set_diagnostic_context
1576 (&dc, msgid, &ap, input_filename, lineno, /* warn = */ 1);
1577 report_diagnostic (&dc);
1578 va_end (ap);
1581 /* Flush diagnostic_buffer content on stderr. */
1583 static void
1584 finish_diagnostic ()
1586 output_buffer_to_stream (diagnostic_buffer);
1587 clear_diagnostic_info (diagnostic_buffer);
1588 fputc ('\n', output_buffer_attached_stream (diagnostic_buffer));
1589 fflush (output_buffer_attached_stream (diagnostic_buffer));
1592 /* Helper subroutine of output_verbatim and verbatim. Do the approriate
1593 settings needed by BUFFER for a verbatim formatting. */
1595 static void
1596 output_do_verbatim (buffer, msgid, args_ptr)
1597 output_buffer *buffer;
1598 const char *msgid;
1599 va_list *args_ptr;
1601 output_state os;
1603 os = output_buffer_state (buffer);
1604 output_prefix (buffer) = NULL;
1605 prefixing_policy (buffer) = DIAGNOSTICS_SHOW_PREFIX_NEVER;
1606 output_buffer_text_cursor (buffer) = _(msgid);
1607 output_buffer_ptr_to_format_args (buffer) = args_ptr;
1608 output_set_maximum_length (buffer, 0);
1609 output_format (buffer);
1610 output_buffer_state (buffer) = os;
1613 /* Output MESSAGE verbatim into BUFFER. */
1615 void
1616 output_verbatim VPARAMS ((output_buffer *buffer, const char *msgid, ...))
1618 #ifndef ANSI_PROTOTYPES
1619 output_buffer *buffer;
1620 const char *msgid;
1621 #endif
1622 va_list ap;
1624 VA_START (ap, msgid);
1625 #ifndef ANSI_PROTOTYPES
1626 buffer = va_arg (ap, output_buffer *);
1627 msg = va_arg (ap, const char *);
1628 #endif
1629 output_do_verbatim (buffer, msgid, &ap);
1630 va_end (ap);
1633 /* Same as above but use diagnostic_buffer. */
1635 void
1636 verbatim VPARAMS ((const char *msgid, ...))
1638 #ifndef ANSI_PROTOTYPES
1639 const char *msgid;
1640 #endif
1641 va_list ap;
1643 VA_START (ap, msgid);
1644 #ifndef ANSI_PROTOTYPES
1645 msgid = va_arg (ap, const char *);
1646 #endif
1647 output_do_verbatim (diagnostic_buffer, msgid, &ap);
1648 output_buffer_to_stream (diagnostic_buffer);
1649 va_end (ap);
1652 /* Report a diagnostic message (an error or a warning) as specified by
1653 DC. This function is *the* subroutine in terms of which front-ends
1654 should implement their specific diagnostic handling modules. The
1655 front-end independent format specifiers are exactly those described
1656 in the documentation of output_format. */
1658 void
1659 report_diagnostic (dc)
1660 diagnostic_context *dc;
1662 output_state os;
1664 if (diagnostic_lock++)
1665 error_recursion ();
1667 if (count_error (diagnostic_is_warning (dc)))
1669 os = output_buffer_state (diagnostic_buffer);
1670 diagnostic_msg = diagnostic_message (dc);
1671 diagnostic_args = diagnostic_argument_list (dc);
1672 (*diagnostic_starter (dc)) (diagnostic_buffer, dc);
1673 output_format (diagnostic_buffer);
1674 (*diagnostic_finalizer (dc)) (diagnostic_buffer, dc);
1675 finish_diagnostic ();
1676 output_buffer_state (diagnostic_buffer) = os;
1679 diagnostic_lock--;
1682 /* Inform the user that an error occurred while trying to report some
1683 other error. This indicates catastrophic internal inconsistencies,
1684 so give up now. But do try to flush out the previous error.
1685 This mustn't use internal_error, that will cause infinite recursion. */
1687 static void
1688 error_recursion ()
1690 if (diagnostic_lock < 3)
1691 finish_diagnostic ();
1693 fnotice (stderr,
1694 "Internal compiler error: Error reporting routines re-entered.\n");
1695 fnotice (stderr,
1696 "Please submit a full bug report,\n\
1697 with preprocessed source if appropriate.\n\
1698 See %s for instructions.\n", GCCBUGURL);
1699 exit (FATAL_EXIT_CODE);
1702 /* Given a partial pathname as input, return another pathname that
1703 shares no directory elements with the pathname of __FILE__. This
1704 is used by fancy_abort() to print `Internal compiler error in expr.c'
1705 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
1707 const char *
1708 trim_filename (name)
1709 const char *name;
1711 static const char this_file[] = __FILE__;
1712 const char *p = name, *q = this_file;
1714 /* First skip any "../" in each filename. This allows us to give a proper
1715 reference to a file in a subdirectory. */
1716 while (p[0] == '.' && p[1] == '.'
1717 && (p[2] == DIR_SEPARATOR
1718 #ifdef DIR_SEPARATOR_2
1719 || p[2] == DIR_SEPARATOR_2
1720 #endif
1722 p += 3;
1724 while (q[0] == '.' && q[1] == '.'
1725 && (q[2] == DIR_SEPARATOR
1726 #ifdef DIR_SEPARATOR_2
1727 || p[2] == DIR_SEPARATOR_2
1728 #endif
1730 q += 3;
1732 /* Now skip any parts the two filenames have in common. */
1733 while (*p == *q && *p != 0 && *q != 0)
1734 p++, q++;
1736 /* Now go backwards until the previous directory separator. */
1737 while (p > name && p[-1] != DIR_SEPARATOR
1738 #ifdef DIR_SEPARATOR_2
1739 && p[-1] != DIR_SEPARATOR_2
1740 #endif
1742 p--;
1744 return p;
1747 /* Report an internal compiler error in a friendly manner and without
1748 dumping core. */
1750 void
1751 fancy_abort (file, line, function)
1752 const char *file;
1753 int line;
1754 const char *function;
1756 internal_error ("Internal compiler error in %s, at %s:%d",
1757 function, trim_filename (file), line);
1760 /* Setup DC for reporting a diagnostic MESSAGE (an error or a WARNING),
1761 using arguments pointed to by ARGS_PTR, issued at a location specified
1762 by FILE and LINE. */
1764 void
1765 set_diagnostic_context (dc, msgid, args_ptr, file, line, warn)
1766 diagnostic_context *dc;
1767 const char *msgid;
1768 va_list *args_ptr;
1769 const char *file;
1770 int line;
1771 int warn;
1773 memset (dc, 0, sizeof (diagnostic_context));
1774 diagnostic_message (dc) = _(msgid);
1775 diagnostic_argument_list (dc) = args_ptr;
1776 diagnostic_file_location (dc) = file;
1777 diagnostic_line_location (dc) = line;
1778 diagnostic_is_warning (dc) = warn;
1779 diagnostic_starter (dc) = lang_diagnostic_starter;
1780 diagnostic_finalizer (dc) = lang_diagnostic_finalizer;
1783 void
1784 report_problematic_module (buffer)
1785 output_buffer *buffer;
1787 struct file_stack *p;
1789 if (output_needs_newline (buffer))
1791 output_add_newline (buffer);
1792 output_needs_newline (buffer) = 0;
1795 if (input_file_stack && input_file_stack->next != 0
1796 && error_module_changed ())
1798 for (p = input_file_stack->next; p; p = p->next)
1799 if (p == input_file_stack->next)
1800 output_verbatim
1801 (buffer, "In file included from %s:%d", p->name, p->line);
1802 else
1803 output_verbatim
1804 (buffer, ",\n from %s:%d", p->name, p->line);
1805 output_verbatim (buffer, ":\n");
1806 record_last_error_module ();
1810 static void
1811 default_diagnostic_starter (buffer, dc)
1812 output_buffer *buffer;
1813 diagnostic_context *dc;
1815 report_error_function (diagnostic_file_location (dc));
1816 output_set_prefix (buffer,
1817 context_as_prefix (diagnostic_file_location (dc),
1818 diagnostic_line_location (dc),
1819 diagnostic_is_warning (dc)));
1822 static void
1823 default_diagnostic_finalizer (buffer, dc)
1824 output_buffer *buffer;
1825 diagnostic_context *dc __attribute__((__unused__));
1827 output_destroy_prefix (buffer);