1 /* Language-independent diagnostic subroutines for the GNU C compiler
2 Copyright (C) 1999, 2000 Free Software Foundation, Inc.
4 This file is part of GNU CC.
6 GNU CC is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU CC is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU CC; see the file COPYING. If not, write to
18 the Free Software Foundation, 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA. */
22 /* This file implements the language independant aspect of diagnostic
26 #undef FLOAT /* This is for hpux. They should change hpux. */
27 #undef FFS /* Some systems define this in param.h. */
35 #include "insn-attr.h"
36 #include "insn-codes.h"
37 #include "insn-config.h"
40 #include "diagnostic.h"
42 #define obstack_chunk_alloc xmalloc
43 #define obstack_chunk_free free
45 #define diagnostic_args diagnostic_buffer->format_args
46 #define diagnostic_msg diagnostic_buffer->cursor
48 #define output_formatted_integer(BUFFER, FORMAT, INTEGER) \
50 sprintf (digit_buffer, FORMAT, INTEGER); \
51 output_add_string (BUFFER, digit_buffer); \
54 /* This data structure serves to save/restore an output_buffer state. */
59 int ideal_maximum_length;
68 static int doing_line_wrapping PARAMS ((void));
70 static void finish_diagnostic PARAMS ((void));
71 static void output_do_verbatim PARAMS ((output_buffer *,
72 const char *, va_list));
73 static void output_to_stream PARAMS ((output_buffer *, FILE *));
74 static void output_format PARAMS ((output_buffer *));
76 static char *vbuild_message_string PARAMS ((const char *, va_list));
77 static char *build_message_string PARAMS ((const char *, ...))
79 static char *context_as_prefix PARAMS ((const char *, int, int));
80 static void output_do_printf PARAMS ((output_buffer *, const char *));
81 static void line_wrapper_printf PARAMS ((FILE *, const char *, ...))
83 static void vline_wrapper_message_with_location PARAMS ((const char *, int,
86 static void notice PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1;
87 static void v_message_with_file_and_line PARAMS ((const char *, int, int,
88 const char *, va_list));
89 static void v_message_with_decl PARAMS ((tree, int, const char *, va_list));
90 static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
91 static void v_error_with_file_and_line PARAMS ((const char *, int,
92 const char *, va_list));
93 static void v_error_with_decl PARAMS ((tree, const char *, va_list));
94 static void v_error_for_asm PARAMS ((rtx, const char *, va_list));
95 static void vfatal PARAMS ((const char *, va_list)) ATTRIBUTE_NORETURN;
96 static void v_warning_with_file_and_line PARAMS ((const char *, int,
97 const char *, va_list));
98 static void v_warning_with_decl PARAMS ((tree, const char *, va_list));
99 static void v_warning_for_asm PARAMS ((rtx, const char *, va_list));
100 static void v_pedwarn_with_decl PARAMS ((tree, const char *, va_list));
101 static void v_pedwarn_with_file_and_line PARAMS ((const char *, int,
102 const char *, va_list));
103 static void vsorry PARAMS ((const char *, va_list));
104 static void report_file_and_line PARAMS ((const char *, int, int));
105 static void vnotice PARAMS ((FILE *, const char *, va_list));
106 static void set_real_maximum_length PARAMS ((output_buffer *));
108 static void save_output_state PARAMS ((const output_buffer *, output_state *));
109 static void restore_output_state PARAMS ((const output_state *,
112 static void output_unsigned_decimal PARAMS ((output_buffer *, unsigned int));
113 static void output_long_decimal PARAMS ((output_buffer *, long int));
114 static void output_long_unsigned_decimal PARAMS ((output_buffer *,
116 static void output_octal PARAMS ((output_buffer *, unsigned int));
117 static void output_long_octal PARAMS ((output_buffer *, unsigned long int));
118 static void output_hexadecimal PARAMS ((output_buffer *, unsigned int));
119 static void output_long_hexadecimal PARAMS ((output_buffer *,
121 static void output_append_r PARAMS ((output_buffer *, const char *, int));
122 static void wrap_text PARAMS ((output_buffer *, const char *, const char *));
123 static void maybe_wrap_text PARAMS ((output_buffer *, const char *,
126 extern int rtl_dump_and_exit;
127 extern int inhibit_warnings;
128 extern int warnings_are_errors;
129 extern int warningcount;
130 extern int errorcount;
132 /* Front-end specific tree formatter, if non-NULL. */
133 printer_fn lang_printer = NULL;
135 /* This must be large enough to hold any printed integer or
136 floating-point value. */
137 static char digit_buffer[128];
139 /* An output_buffer surrogate for stderr. */
140 static output_buffer global_output_buffer;
141 output_buffer *diagnostic_buffer = &global_output_buffer;
143 static int need_error_newline;
145 /* Function of last error message;
146 more generally, function such that if next error message is in it
147 then we don't have to mention the function name. */
148 static tree last_error_function = NULL;
150 /* Used to detect when input_file_stack has changed since last described. */
151 static int last_error_tick;
153 /* Called by report_error_function to print out function name.
154 * Default may be overridden by language front-ends. */
156 void (*print_error_function) PARAMS ((const char *)) =
157 default_print_error_function;
159 /* Maximum characters per line in automatic line wrapping mode.
160 Zero means don't wrap lines. */
162 int diagnostic_message_length_per_line;
164 /* Used to control every diagnostic message formatting. Front-ends should
165 call set_message_prefixing_rule to set up their politics. */
166 static int current_prefixing_rule;
168 /* Initialize the diagnostic message outputting machinery. */
171 initialize_diagnostics ()
173 /* By default, we don't line-wrap messages. */
174 diagnostic_message_length_per_line = 0;
175 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
176 /* Proceed to actual initialization. */
177 default_initialize_buffer (diagnostic_buffer);
180 /* Predicate. Return 1 if we're in automatic line wrapping mode. */
183 doing_line_wrapping ()
185 return diagnostic_message_length_per_line > 0;
189 set_message_prefixing_rule (rule)
192 current_prefixing_rule = rule;
195 /* Returns true if BUFFER is in line-wrappind mode. */
197 output_is_line_wrapping (buffer)
198 output_buffer *buffer;
200 return buffer->ideal_maximum_length > 0;
203 /* Return BUFFER's prefix. */
205 output_get_prefix (buffer)
206 const output_buffer *buffer;
208 return buffer->prefix;
211 /* Subroutine of output_set_maximum_length. Set up BUFFER's
212 internal maximum characters per line. */
214 set_real_maximum_length (buffer)
215 output_buffer *buffer;
217 /* If we're told not to wrap lines then do the obvious thing. */
218 if (! output_is_line_wrapping (buffer))
219 buffer->maximum_length = buffer->ideal_maximum_length;
222 int prefix_length = buffer->prefix ? strlen (buffer->prefix) : 0;
223 /* If the prefix is ridiculously too long, output at least
225 if (buffer->ideal_maximum_length - prefix_length < 32)
226 buffer->maximum_length = buffer->ideal_maximum_length + 32;
228 buffer->maximum_length = buffer->ideal_maximum_length;
232 /* Sets the number of maximum characters per line BUFFER can output
233 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
235 output_set_maximum_length (buffer, length)
236 output_buffer *buffer;
239 buffer->ideal_maximum_length = length;
240 set_real_maximum_length (buffer);
243 /* Sets BUFFER's PREFIX. */
245 output_set_prefix (buffer, prefix)
246 output_buffer *buffer;
249 buffer->prefix = prefix;
250 set_real_maximum_length (buffer);
251 buffer->emitted_prefix_p = 0;
254 /* Free BUFFER's prefix, a previously malloc()'d string. */
257 output_destroy_prefix (buffer)
258 output_buffer *buffer;
262 free ((char *) buffer->prefix);
263 buffer->prefix = NULL;
267 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
268 characters per line. */
270 init_output_buffer (buffer, prefix, maximum_length)
271 output_buffer *buffer;
275 obstack_init (&buffer->obstack);
276 buffer->ideal_maximum_length = maximum_length;
277 buffer->line_length = 0;
278 output_set_prefix (buffer, prefix);
279 buffer->emitted_prefix_p = 0;
280 buffer->prefixing_rule = current_prefixing_rule;
282 buffer->cursor = NULL;
285 /* Initialize BUFFER with a NULL prefix and current diagnostic message
288 default_initialize_buffer (buffer)
289 output_buffer *buffer;
291 init_output_buffer (buffer, NULL, diagnostic_message_length_per_line);
294 /* Recompute diagnostic_buffer's attributes to reflect any change
295 in diagnostic formatting global options. */
297 reshape_diagnostic_buffer ()
299 diagnostic_buffer->ideal_maximum_length = diagnostic_message_length_per_line;
300 diagnostic_buffer->prefixing_rule = current_prefixing_rule;
301 set_real_maximum_length (diagnostic_buffer);
304 /* Reinitialize BUFFER. */
306 output_clear (buffer)
307 output_buffer *buffer;
309 obstack_free (&buffer->obstack, obstack_base (&buffer->obstack));
310 buffer->line_length = 0;
311 buffer->cursor = NULL;
312 buffer->emitted_prefix_p = 0;
315 /* Finishes to construct a NULL-terminated character string representing
316 the BUFFERed message. */
318 output_finish (buffer)
319 output_buffer *buffer;
321 obstack_1grow (&buffer->obstack, '\0');
322 return (const char *) obstack_finish (&buffer->obstack);
325 /* Return the amount of characters BUFFER can accept to
328 output_space_left (buffer)
329 const output_buffer *buffer;
331 return buffer->maximum_length - buffer->line_length;
334 /* Write out BUFFER's prefix. */
336 output_emit_prefix (buffer)
337 output_buffer *buffer;
341 switch (buffer->prefixing_rule)
344 case DIAGNOSTICS_SHOW_PREFIX_NEVER:
347 case DIAGNOSTICS_SHOW_PREFIX_ONCE:
348 if (buffer->emitted_prefix_p)
351 buffer->emitted_prefix_p = 1;
354 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE:
355 buffer->line_length += strlen (buffer->prefix);
357 (&buffer->obstack, buffer->prefix, buffer->line_length);
363 /* Have BUFFER start a new line. */
365 output_add_newline (buffer)
366 output_buffer *buffer;
368 obstack_1grow (&buffer->obstack, '\n');
369 buffer->line_length = 0;
372 /* Appends a character to BUFFER. */
374 output_add_character (buffer, c)
375 output_buffer *buffer;
378 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
379 output_add_newline (buffer);
380 obstack_1grow (&buffer->obstack, c);
381 ++buffer->line_length;
384 /* Adds a space to BUFFER. */
386 output_add_space (buffer)
387 output_buffer *buffer;
389 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
391 output_add_newline (buffer);
394 obstack_1grow (&buffer->obstack, ' ');
395 ++buffer->line_length;
398 /* These functions format an INTEGER into BUFFER as suggested by their
401 output_decimal (buffer, i)
402 output_buffer *buffer;
405 output_formatted_integer (buffer, "%d", i);
409 output_long_decimal (buffer, i)
410 output_buffer *buffer;
413 output_formatted_integer (buffer, "%ld", i);
417 output_unsigned_decimal (buffer, i)
418 output_buffer *buffer;
421 output_formatted_integer (buffer, "%u", i);
425 output_long_unsigned_decimal (buffer, i)
426 output_buffer *buffer;
429 output_formatted_integer (buffer, "%lu", i);
433 output_octal (buffer, i)
434 output_buffer *buffer;
437 output_formatted_integer (buffer, "%o", i);
441 output_long_octal (buffer, i)
442 output_buffer *buffer;
445 output_formatted_integer (buffer, "%lo", i);
449 output_hexadecimal (buffer, i)
450 output_buffer *buffer;
453 output_formatted_integer (buffer, "%x", i);
457 output_long_hexadecimal (buffer, i)
458 output_buffer *buffer;
461 output_formatted_integer (buffer, "%lx", i);
464 /* Append to BUFFER a string specified by its STARTING character
467 output_append_r (buffer, start, length)
468 output_buffer *buffer;
472 obstack_grow (&buffer->obstack, start, length);
473 buffer->line_length += length;
476 /* Append a string deliminated by START and END to BUFFER. No wrapping is
477 done. However, if beginning a new line then emit BUFFER->PREFIX and
478 skip any leading whitespace if appropriate. The caller must ensure
479 that it is safe to do so. */
481 output_append (buffer, start, end)
482 output_buffer *buffer;
486 /* Emit prefix and skip whitespace if we're starting a new line. */
487 if (buffer->line_length == 0)
489 output_emit_prefix (buffer);
490 if (output_is_line_wrapping (buffer))
491 while (start != end && *start == ' ')
494 output_append_r (buffer, start, end - start);
497 /* Wrap a text delimited by START and END into BUFFER. */
499 wrap_text (buffer, start, end)
500 output_buffer *buffer;
506 /* Dump anything bodered by whitespaces. */
508 const char *p = start;
509 while (p != end && *p != ' ' && *p != '\n')
511 if (p - start >= output_space_left (buffer))
512 output_add_newline (buffer);
513 output_append (buffer, start, p);
517 if (start != end && *start == ' ')
519 output_add_space (buffer);
522 if (start != end && *start == '\n')
524 output_add_newline (buffer);
530 /* Same as wrap_text but wrap text only when in line-wrapping mode. */
532 maybe_wrap_text (buffer, start, end)
533 output_buffer *buffer;
537 if (output_is_line_wrapping (buffer))
538 wrap_text (buffer, start, end);
540 output_append (buffer, start, end);
544 /* Append a STRING to BUFFER; the STRING maybe be line-wrapped if in
548 output_add_string (buffer, str)
549 output_buffer *buffer;
552 maybe_wrap_text (buffer, str, str + (str ? strlen (str) : 0));
555 /* Flush the content of BUFFER onto FILE and reinitialize BUFFER. */
558 output_to_stream (buffer, file)
559 output_buffer *buffer;
562 const char *text = output_finish (buffer);
564 output_clear (buffer);
567 /* Format a message pointed to by BUFFER->CURSOR using BUFFER->CURSOR
568 as appropriate. The following format specifiers are recognized as
569 being language independent:
570 %d, %i: (signed) integer in base ten.
571 %u: unsigned integer in base ten.
572 %o: (signed) integer in base eight.
573 %x: (signged) integer in base sixteen.
574 %ld, %li, %lo, %lu, %lx: long versions of the above.
578 %*.s: a substring the length of which is specified by an integer. */
580 output_format (buffer)
581 output_buffer *buffer;
583 for (; *buffer->cursor; ++buffer->cursor)
585 int long_integer = 0;
588 const char *p = buffer->cursor;
589 while (*p && *p != '%')
591 maybe_wrap_text (buffer, buffer->cursor, p);
594 if (!*buffer->cursor)
597 /* We got a '%'. Let's see what happens. Record whether we're
598 parsing a long integer format specifier. */
599 if (*++buffer->cursor == 'l')
605 /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %o, %s, %u,
606 %x, %.*s; %%. And nothing else. Front-ends should install
607 printers to grok language specific format specifiers. */
608 switch (*buffer->cursor)
612 (buffer, va_arg (buffer->format_args, int));
619 (buffer, va_arg (buffer->format_args, long int));
621 output_decimal (buffer, va_arg (buffer->format_args, int));
627 (buffer, va_arg (buffer->format_args, unsigned long int));
629 output_octal (buffer, va_arg (buffer->format_args, unsigned int));
634 (buffer, va_arg (buffer->format_args, const char *));
639 output_long_unsigned_decimal
640 (buffer, va_arg (buffer->format_args, long unsigned int));
642 output_unsigned_decimal
643 (buffer, va_arg (buffer->format_args, unsigned int));
647 output_long_hexadecimal
648 (buffer, va_arg (buffer->format_args, unsigned long int));
651 (buffer, va_arg (buffer->format_args, unsigned int));
655 output_add_character (buffer, '%');
662 /* We handle no precision specifier but `%.*s'. */
663 if (*++buffer->cursor != '*')
665 else if (*++buffer->cursor != 's')
667 n = va_arg (buffer->format_args, int);
668 s = va_arg (buffer->format_args, const char *);
669 output_append (buffer, s, s + n);
674 if (!lang_printer || !(*lang_printer) (buffer))
676 /* Hmmm. The front-end failed to install a format translator
677 but called us with an unrecognized format. Sorry. */
685 vbuild_message_string (msgid, ap)
691 vasprintf (&str, msgid, ap);
695 /* Return a malloc'd string containing MSGID formatted a la
696 printf. The caller is reponsible for freeing the memory. */
699 build_message_string VPARAMS ((const char *msgid, ...))
701 #ifndef ANSI_PROTOTYPES
707 VA_START (ap, msgid);
709 #ifndef ANSI_PROTOTYPES
710 msgid = va_arg (ap, const char *);
713 str = vbuild_message_string (msgid, ap);
721 /* Return a malloc'd string describing a location. The caller is
722 responsible for freeing the memory. */
725 context_as_prefix (file, line, warn)
733 return build_message_string ("%s:%d: warning: ", file, line);
735 return build_message_string ("%s:%d: ", file, line);
740 return build_message_string ("%s: warning: ", progname);
742 return build_message_string ("%s: ", progname);
746 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
749 output_do_printf (buffer, msgid)
750 output_buffer *buffer;
753 char *message = vbuild_message_string (msgid, buffer->format_args);
755 output_add_string (buffer, message);
760 /* Format a message into BUFFER a la printf. */
763 output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
765 #ifndef ANSI_PROTOTYPES
766 struct output_buffer *buffer;
772 VA_START (ap, msgid);
773 #ifndef ANSI_PROTOTYPES
774 buffer = va_arg (ap, struct output_buffer *);
775 msgid = va_arg (ap, const char *);
777 va_copy (old_args, buffer->format_args);
779 va_copy (buffer->format_args, ap);
780 output_do_printf (buffer, msgid);
781 va_end (buffer->format_args);
783 va_copy (buffer->format_args, old_args);
787 /* Format a MESSAGE into FILE. Do line wrapping, starting new lines
791 line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...))
793 #ifndef ANSI_PROTOTYPES
797 output_buffer buffer;
799 default_initialize_buffer (&buffer);
800 VA_START (buffer.format_args, msgid);
802 #ifndef ANSI_PROTOTYPES
803 file = va_arg (buffer.format_args, FILE *);
804 msgid = va_arg (buffer.format_args, const char *);
807 output_do_printf (&buffer, msgid);
808 output_to_stream (&buffer, file);
810 va_end (buffer.format_args);
815 vline_wrapper_message_with_location (file, line, warn, msgid, ap)
822 output_buffer buffer;
824 init_output_buffer (&buffer, context_as_prefix (file, line, warn),
825 diagnostic_message_length_per_line);
826 va_copy (buffer.format_args, ap);
827 output_do_printf (&buffer, msgid);
828 output_to_stream (&buffer, stderr);
830 output_destroy_prefix (&buffer);
831 fputc ('\n', stderr);
835 /* Print the message MSGID in FILE. */
838 vnotice (file, msgid, ap)
843 vfprintf (file, _(msgid), ap);
846 /* Print MSGID on stderr. */
849 notice VPARAMS ((const char *msgid, ...))
851 #ifndef ANSI_PROTOTYPES
856 VA_START (ap, msgid);
858 #ifndef ANSI_PROTOTYPES
859 msgid = va_arg (ap, char *);
862 vnotice (stderr, msgid, ap);
866 /* Report FILE and LINE (or program name), and optionally just WARN. */
869 report_file_and_line (file, line, warn)
875 fprintf (stderr, "%s:%d: ", file, line);
877 fprintf (stderr, "%s: ", progname);
880 notice ("warning: ");
883 /* Print a message relevant to line LINE of file FILE. */
886 v_message_with_file_and_line (file, line, warn, msgid, ap)
893 report_file_and_line (file, line, warn);
894 vnotice (stderr, msgid, ap);
895 fputc ('\n', stderr);
898 /* Print a message relevant to the given DECL. */
901 v_message_with_decl (decl, warn, msgid, ap)
908 output_buffer buffer;
910 if (doing_line_wrapping ())
913 (&buffer, context_as_prefix
914 (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn),
915 diagnostic_message_length_per_line);
918 report_file_and_line (DECL_SOURCE_FILE (decl),
919 DECL_SOURCE_LINE (decl), warn);
921 /* Do magic to get around lack of varargs support for insertion
922 of arguments into existing list. We know that the decl is first;
923 we ass_u_me that it will be printed with "%s". */
925 for (p = _(msgid); *p; ++p)
931 else if (*(p + 1) != 's')
938 if (p > _(msgid)) /* Print the left-hand substring. */
940 if (doing_line_wrapping ())
941 output_printf (&buffer, "%.*s", (int)(p - _(msgid)), _(msgid));
943 fprintf (stderr, "%.*s", (int)(p - _(msgid)), _(msgid));
946 if (*p == '%') /* Print the name. */
948 const char *n = (DECL_NAME (decl)
949 ? (*decl_printable_name) (decl, 2)
950 : _("((anonymous))"));
951 if (doing_line_wrapping ())
952 output_add_string (&buffer, n);
958 if (ISALPHA (*(p - 1) & 0xFF))
963 if (*p) /* Print the rest of the message. */
965 if (doing_line_wrapping ())
967 va_copy (buffer.format_args, ap);
968 output_do_printf (&buffer, p);
969 va_copy (ap, buffer.format_args);
972 vfprintf (stderr, p, ap);
975 if (doing_line_wrapping())
977 output_to_stream (&buffer, stderr);
978 output_destroy_prefix (&buffer);
981 fputc ('\n', stderr);
984 /* Figure file and line of the given INSN. */
987 file_and_line_for_asm (insn, pfile, pline)
992 rtx body = PATTERN (insn);
995 /* Find the (or one of the) ASM_OPERANDS in the insn. */
996 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
997 asmop = SET_SRC (body);
998 else if (GET_CODE (body) == ASM_OPERANDS)
1000 else if (GET_CODE (body) == PARALLEL
1001 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
1002 asmop = SET_SRC (XVECEXP (body, 0, 0));
1003 else if (GET_CODE (body) == PARALLEL
1004 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
1005 asmop = XVECEXP (body, 0, 0);
1011 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
1012 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
1016 *pfile = input_filename;
1021 /* Report an error at line LINE of file FILE. */
1024 v_error_with_file_and_line (file, line, msgid, ap)
1031 report_error_function (file);
1032 if (doing_line_wrapping ())
1033 vline_wrapper_message_with_location (file, line, 0, msgid, ap);
1035 v_message_with_file_and_line (file, line, 0, msgid, ap);
1038 /* Report an error at the declaration DECL.
1039 MSGID is a format string which uses %s to substitute the declaration
1040 name; subsequent substitutions are a la printf. */
1043 v_error_with_decl (decl, msgid, ap)
1049 report_error_function (DECL_SOURCE_FILE (decl));
1050 v_message_with_decl (decl, 0, msgid, ap);
1054 /* Report an error at the line number of the insn INSN.
1055 This is used only when INSN is an `asm' with operands,
1056 and each ASM_OPERANDS records its own source file and line. */
1059 v_error_for_asm (insn, msgid, ap)
1068 file_and_line_for_asm (insn, &file, &line);
1069 report_error_function (file);
1070 v_message_with_file_and_line (file, line, 0, msgid, ap);
1074 /* Report an error at the current line number. */
1081 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
1085 /* Report a fatal error at the current line number. Allow a front end to
1086 intercept the message. */
1088 static void (*fatal_function) PARAMS ((const char *, va_list));
1095 if (fatal_function != 0)
1096 (*fatal_function) (_(msgid), ap);
1099 exit (FATAL_EXIT_CODE);
1102 /* Report a warning at line LINE of file FILE. */
1105 v_warning_with_file_and_line (file, line, msgid, ap)
1111 if (count_error (1))
1113 report_error_function (file);
1114 if (doing_line_wrapping ())
1115 vline_wrapper_message_with_location (file, line, 1, msgid, ap);
1117 v_message_with_file_and_line (file, line, 1, msgid, ap);
1122 /* Report a warning at the declaration DECL.
1123 MSGID is a format string which uses %s to substitute the declaration
1124 name; subsequent substitutions are a la printf. */
1127 v_warning_with_decl (decl, msgid, ap)
1132 if (count_error (1))
1134 report_error_function (DECL_SOURCE_FILE (decl));
1135 v_message_with_decl (decl, 1, msgid, ap);
1140 /* Report a warning at the line number of the insn INSN.
1141 This is used only when INSN is an `asm' with operands,
1142 and each ASM_OPERANDS records its own source file and line. */
1145 v_warning_for_asm (insn, msgid, ap)
1150 if (count_error (1))
1155 file_and_line_for_asm (insn, &file, &line);
1156 report_error_function (file);
1157 v_message_with_file_and_line (file, line, 1, msgid, ap);
1162 /* Report a warning at the current line number. */
1165 vwarning (msgid, ap)
1169 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
1172 /* These functions issue either warnings or errors depending on
1173 -pedantic-errors. */
1176 vpedwarn (msgid, ap)
1180 if (flag_pedantic_errors)
1183 vwarning (msgid, ap);
1188 v_pedwarn_with_decl (decl, msgid, ap)
1193 /* We don't want -pedantic-errors to cause the compilation to fail from
1194 "errors" in system header files. Sometimes fixincludes can't fix what's
1195 broken (eg: unsigned char bitfields - fixing it may change the alignment
1196 which will cause programs to mysteriously fail because the C library
1197 or kernel uses the original layout). There's no point in issuing a
1198 warning either, it's just unnecessary noise. */
1200 if (! DECL_IN_SYSTEM_HEADER (decl))
1202 if (flag_pedantic_errors)
1203 v_error_with_decl (decl, msgid, ap);
1205 v_warning_with_decl (decl, msgid, ap);
1211 v_pedwarn_with_file_and_line (file, line, msgid, ap)
1217 if (flag_pedantic_errors)
1218 v_error_with_file_and_line (file, line, msgid, ap);
1220 v_warning_with_file_and_line (file, line, msgid, ap);
1224 /* Apologize for not implementing some feature. */
1233 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1235 fprintf (stderr, "%s: ", progname);
1236 notice ("sorry, not implemented: ");
1237 vnotice (stderr, msgid, ap);
1238 fputc ('\n', stderr);
1242 /* Count an error or warning. Return 1 if the message should be printed. */
1245 count_error (warningp)
1248 if (warningp && inhibit_warnings)
1251 if (warningp && !warnings_are_errors)
1255 static int warning_message = 0;
1257 if (warningp && !warning_message)
1259 verbatim ("%s: warnings being treated as errors\n", progname);
1260 warning_message = 1;
1268 /* Print a diagnistic MSGID on FILE. */
1270 fnotice VPARAMS ((FILE *file, const char *msgid, ...))
1272 #ifndef ANSI_PROTOTYPES
1278 VA_START (ap, msgid);
1280 #ifndef ANSI_PROTOTYPES
1281 file = va_arg (ap, FILE *);
1282 msgid = va_arg (ap, const char *);
1285 vnotice (file, msgid, ap);
1290 /* Print a fatal error message. NAME is the text.
1291 Also include a system error message based on `errno'. */
1294 pfatal_with_name (name)
1297 fprintf (stderr, "%s: ", progname);
1299 exit (FATAL_EXIT_CODE);
1303 fatal_io_error (name)
1306 notice ("%s: %s: I/O error\n", progname, name);
1307 exit (FATAL_EXIT_CODE);
1310 /* Issue a pedantic warning MSGID. */
1312 pedwarn VPARAMS ((const char *msgid, ...))
1314 #ifndef ANSI_PROTOTYPES
1319 VA_START (ap, msgid);
1321 #ifndef ANSI_PROTOTYPES
1322 msgid = va_arg (ap, const char *);
1325 vpedwarn (msgid, ap);
1329 /* Issue a pedantic waring about DECL. */
1331 pedwarn_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1333 #ifndef ANSI_PROTOTYPES
1339 VA_START (ap, msgid);
1341 #ifndef ANSI_PROTOTYPES
1342 decl = va_arg (ap, tree);
1343 msgid = va_arg (ap, const char *);
1346 v_pedwarn_with_decl (decl, msgid, ap);
1350 /* Same as above but within the context FILE and LINE. */
1352 pedwarn_with_file_and_line VPARAMS ((const char *file, int line,
1353 const char *msgid, ...))
1355 #ifndef ANSI_PROTOTYPES
1362 VA_START (ap, msgid);
1364 #ifndef ANSI_PROTOTYPES
1365 file = va_arg (ap, const char *);
1366 line = va_arg (ap, int);
1367 msgid = va_arg (ap, const char *);
1370 v_pedwarn_with_file_and_line (file, line, msgid, ap);
1374 /* Just apologize with MSGID. */
1376 sorry VPARAMS ((const char *msgid, ...))
1378 #ifndef ANSI_PROTOTYPES
1383 VA_START (ap, msgid);
1385 #ifndef ANSI_PROTOTYPES
1386 msgid = va_arg (ap, const char *);
1393 /* Called when the start of a function definition is parsed,
1394 this function prints on stderr the name of the function. */
1397 announce_function (decl)
1402 if (rtl_dump_and_exit)
1403 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1406 if (doing_line_wrapping ())
1408 (stderr, " %s", (*decl_printable_name) (decl, 2));
1410 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1413 need_error_newline = 1;
1414 last_error_function = current_function_decl;
1418 /* The default function to print out name of current function that caused
1422 default_print_error_function (file)
1425 if (last_error_function != current_function_decl)
1427 char *prefix = NULL;
1428 output_buffer buffer;
1431 prefix = build_message_string ("%s: ", file);
1433 if (doing_line_wrapping ())
1435 (&buffer, prefix, diagnostic_message_length_per_line);
1439 fprintf (stderr, "%s: ", file);
1442 if (current_function_decl == NULL)
1444 if (doing_line_wrapping ())
1445 output_printf (&buffer, "At top level:\n");
1447 notice ("At top level:\n");
1451 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1453 if (doing_line_wrapping ())
1455 (&buffer, "In method `%s':\n",
1456 (*decl_printable_name) (current_function_decl, 2));
1458 notice ("In method `%s':\n",
1459 (*decl_printable_name) (current_function_decl, 2));
1463 if (doing_line_wrapping ())
1465 (&buffer, "In function `%s':\n",
1466 (*decl_printable_name) (current_function_decl, 2));
1468 notice ("In function `%s':\n",
1469 (*decl_printable_name) (current_function_decl, 2));
1473 last_error_function = current_function_decl;
1475 if (doing_line_wrapping ())
1476 output_to_stream (&buffer, stderr);
1478 free ((char*) prefix);
1482 /* Prints out, if necessary, the name of the current function
1483 that caused an error. Called from all error and warning functions.
1484 We ignore the FILE parameter, as it cannot be relied upon. */
1487 report_error_function (file)
1488 const char *file ATTRIBUTE_UNUSED;
1490 struct file_stack *p;
1492 if (need_error_newline)
1495 need_error_newline = 0;
1498 if (input_file_stack && input_file_stack->next != 0
1499 && input_file_stack_tick != last_error_tick)
1501 for (p = input_file_stack->next; p; p = p->next)
1502 if (p == input_file_stack->next)
1503 verbatim ("In file included from %s:%d", p->name, p->line);
1505 verbatim (",\n from %s:%d", p->name, p->line);
1507 last_error_tick = input_file_stack_tick;
1510 (*print_error_function) (input_filename);
1514 error_with_file_and_line VPARAMS ((const char *file, int line,
1515 const char *msgid, ...))
1517 #ifndef ANSI_PROTOTYPES
1524 VA_START (ap, msgid);
1526 #ifndef ANSI_PROTOTYPES
1527 file = va_arg (ap, const char *);
1528 line = va_arg (ap, int);
1529 msgid = va_arg (ap, const char *);
1532 v_error_with_file_and_line (file, line, msgid, ap);
1537 error_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1539 #ifndef ANSI_PROTOTYPES
1545 VA_START (ap, msgid);
1547 #ifndef ANSI_PROTOTYPES
1548 decl = va_arg (ap, tree);
1549 msgid = va_arg (ap, const char *);
1552 v_error_with_decl (decl, msgid, ap);
1557 error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1559 #ifndef ANSI_PROTOTYPES
1565 VA_START (ap, msgid);
1567 #ifndef ANSI_PROTOTYPES
1568 insn = va_arg (ap, rtx);
1569 msgid = va_arg (ap, const char *);
1572 v_error_for_asm (insn, msgid, ap);
1577 error VPARAMS ((const char *msgid, ...))
1579 #ifndef ANSI_PROTOTYPES
1584 VA_START (ap, msgid);
1586 #ifndef ANSI_PROTOTYPES
1587 msgid = va_arg (ap, const char *);
1594 /* Set the function to call when a fatal error occurs. */
1597 set_fatal_function (f)
1598 void (*f) PARAMS ((const char *, va_list));
1604 fatal VPARAMS ((const char *msgid, ...))
1606 #ifndef ANSI_PROTOTYPES
1611 VA_START (ap, msgid);
1613 #ifndef ANSI_PROTOTYPES
1614 msgid = va_arg (ap, const char *);
1622 _fatal_insn (msgid, insn, file, line, function)
1627 const char *function;
1629 error ("%s", msgid);
1631 fancy_abort (file, line, function);
1635 _fatal_insn_not_found (insn, file, line, function)
1639 const char *function;
1641 if (INSN_CODE (insn) < 0)
1642 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1644 _fatal_insn ("Insn does not satisfy its constraints:",
1645 insn, file, line, function);
1649 warning_with_file_and_line VPARAMS ((const char *file, int line,
1650 const char *msgid, ...))
1652 #ifndef ANSI_PROTOTYPES
1659 VA_START (ap, msgid);
1661 #ifndef ANSI_PROTOTYPES
1662 file = va_arg (ap, const char *);
1663 line = va_arg (ap, int);
1664 msgid = va_arg (ap, const char *);
1667 v_warning_with_file_and_line (file, line, msgid, ap);
1672 warning_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1674 #ifndef ANSI_PROTOTYPES
1680 VA_START (ap, msgid);
1682 #ifndef ANSI_PROTOTYPES
1683 decl = va_arg (ap, tree);
1684 msgid = va_arg (ap, const char *);
1687 v_warning_with_decl (decl, msgid, ap);
1692 warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1694 #ifndef ANSI_PROTOTYPES
1700 VA_START (ap, msgid);
1702 #ifndef ANSI_PROTOTYPES
1703 insn = va_arg (ap, rtx);
1704 msgid = va_arg (ap, const char *);
1707 v_warning_for_asm (insn, msgid, ap);
1712 warning VPARAMS ((const char *msgid, ...))
1714 #ifndef ANSI_PROTOTYPES
1719 VA_START (ap, msgid);
1721 #ifndef ANSI_PROTOTYPES
1722 msgid = va_arg (ap, const char *);
1725 vwarning (msgid, ap);
1729 /* Save BUFFER's STATE. */
1731 save_output_state (buffer, state)
1732 const output_buffer *buffer;
1733 output_state *state;
1735 state->prefix = buffer->prefix;
1736 state->maximum_length = buffer->maximum_length;
1737 state->ideal_maximum_length = buffer->ideal_maximum_length;
1738 state->emitted_prefix_p = buffer->emitted_prefix_p;
1739 state->prefixing_rule = buffer->prefixing_rule;
1740 state->cursor = buffer->cursor;
1741 va_copy (state->format_args, buffer->format_args);
1744 /* Restore BUFFER's previously saved STATE. */
1746 restore_output_state (state, buffer)
1747 const output_state *state;
1748 output_buffer *buffer;
1750 buffer->prefix = state->prefix;
1751 buffer->maximum_length = state->maximum_length;
1752 buffer->ideal_maximum_length = state->ideal_maximum_length;
1753 buffer->emitted_prefix_p = state->emitted_prefix_p;
1754 buffer->prefixing_rule = state->prefixing_rule;
1755 buffer->cursor = state->cursor;
1756 va_copy (buffer->format_args, state->format_args);
1759 /* Flush diagnostic_buffer content on stderr. */
1761 finish_diagnostic ()
1763 output_to_stream (diagnostic_buffer, stderr);
1764 fputc ('\n', stderr);
1768 /* Helper subroutine of output_verbatim and verbatim. Do the approriate
1769 settings needed by BUFFER for a verbatim formatting. */
1771 output_do_verbatim (buffer, msg, args)
1772 output_buffer *buffer;
1778 save_output_state (buffer, &os);
1779 buffer->prefix = NULL;
1780 buffer->prefixing_rule = DIAGNOSTICS_SHOW_PREFIX_NEVER;
1781 buffer->cursor = msg;
1782 va_copy (buffer->format_args, args);
1783 output_set_maximum_length (buffer, 0);
1784 output_format (buffer);
1785 va_end (buffer->format_args);
1786 restore_output_state (&os, buffer);
1789 /* Output MESSAGE verbatim into BUFFER. */
1791 output_verbatim VPARAMS ((output_buffer *buffer, const char *msg, ...))
1793 #ifndef ANSI_PROTOTYPES
1794 output_buffer *buffer;
1800 #ifndef ANSI_PROTOTYPES
1801 buffer = va_arg (ap, output_buffer *);
1802 msg = va_arg (ap, const char *);
1804 output_do_verbatim (buffer, msg, ap);
1808 /* Same as above but use diagnostic_buffer. */
1810 verbatim VPARAMS ((const char *msg, ...))
1812 #ifndef ANSI_PROTOTYPES
1818 #ifndef ANSI_PROTOTYPES
1819 msg = va_arg (ap, const char *);
1821 output_do_verbatim (diagnostic_buffer, msg, ap);
1822 output_to_stream (diagnostic_buffer, stderr);
1826 /* Report a diagnostic MESSAGE (an error or a WARNING) involving
1827 entities in ARGUMENTS. FILE and LINE indicate where the diagnostic
1828 occurs. This function is *the* subroutine in terms of which front-ends
1829 should implement their specific diagnostic handling modules.
1830 The front-end independent format specifiers are exactly those described
1831 in the documentation of output_format. */
1833 report_diagnostic (msg, args, file, line, warn)
1842 save_output_state (diagnostic_buffer, &os);
1843 diagnostic_msg = msg;
1844 va_copy (diagnostic_args, args);
1845 if (count_error (warn))
1847 report_error_function (file);
1849 (diagnostic_buffer, context_as_prefix (file, line, warn));
1850 output_format (diagnostic_buffer);
1851 finish_diagnostic();
1852 output_destroy_prefix (diagnostic_buffer);
1854 va_end (diagnostic_args);
1855 restore_output_state (&os, diagnostic_buffer);