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 output_do_verbatim PARAMS ((output_buffer *));
71 static void output_to_stream PARAMS ((output_buffer *, FILE *));
72 static void output_format PARAMS ((output_buffer *));
74 static char *vbuild_message_string PARAMS ((const char *, va_list));
75 static char *build_message_string PARAMS ((const char *, ...))
77 static char *context_as_prefix PARAMS ((const char *, int, int));
78 static void output_do_printf PARAMS ((output_buffer *, const char *));
79 static void line_wrapper_printf PARAMS ((FILE *, const char *, ...))
81 static void vline_wrapper_message_with_location PARAMS ((const char *, int,
84 static void notice PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1;
85 static void v_message_with_file_and_line PARAMS ((const char *, int, int,
86 const char *, va_list));
87 static void v_message_with_decl PARAMS ((tree, int, const char *, va_list));
88 static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
89 static void v_error_with_file_and_line PARAMS ((const char *, int,
90 const char *, va_list));
91 static void v_error_with_decl PARAMS ((tree, const char *, va_list));
92 static void v_error_for_asm PARAMS ((rtx, const char *, va_list));
93 static void vfatal PARAMS ((const char *, va_list)) ATTRIBUTE_NORETURN;
94 static void v_warning_with_file_and_line PARAMS ((const char *, int,
95 const char *, va_list));
96 static void v_warning_with_decl PARAMS ((tree, const char *, va_list));
97 static void v_warning_for_asm PARAMS ((rtx, const char *, va_list));
98 static void v_pedwarn_with_decl PARAMS ((tree, const char *, va_list));
99 static void v_pedwarn_with_file_and_line PARAMS ((const char *, int,
100 const char *, va_list));
101 static void vsorry PARAMS ((const char *, va_list));
102 static void report_file_and_line PARAMS ((const char *, int, int));
103 static void vnotice PARAMS ((FILE *, const char *, va_list));
104 static void set_real_maximum_length PARAMS ((output_buffer *));
106 static void save_output_state PARAMS ((const output_buffer *, output_state *));
107 static void restore_output_state PARAMS ((const output_state *,
110 static void output_unsigned_decimal PARAMS ((output_buffer *, unsigned int));
111 static void output_long_decimal PARAMS ((output_buffer *, long int));
112 static void output_long_unsigned_decimal PARAMS ((output_buffer *,
114 static void output_octal PARAMS ((output_buffer *, int));
115 static void output_long_octal PARAMS ((output_buffer *, long int));
116 static void output_hexadecimal PARAMS ((output_buffer *, int));
117 static void output_long_hexadecimal PARAMS ((output_buffer *, long int));
118 static void output_append_r PARAMS ((output_buffer *, const char *, int));
120 extern int rtl_dump_and_exit;
121 extern int inhibit_warnings;
122 extern int warnings_are_errors;
123 extern int warningcount;
124 extern int errorcount;
126 /* Front-end specific tree formatter, if non-NULL. */
127 printer_fn lang_printer = NULL;
129 /* This must be large enough to hold any printed integer or
130 floating-point value. */
131 static char digit_buffer[128];
133 /* An output_buffer surrogate for stderr. */
134 static output_buffer global_output_buffer;
135 output_buffer *diagnostic_buffer = &global_output_buffer;
137 static int need_error_newline;
139 /* Function of last error message;
140 more generally, function such that if next error message is in it
141 then we don't have to mention the function name. */
142 static tree last_error_function = NULL;
144 /* Used to detect when input_file_stack has changed since last described. */
145 static int last_error_tick;
147 /* Called by report_error_function to print out function name.
148 * Default may be overridden by language front-ends. */
150 void (*print_error_function) PARAMS ((const char *)) =
151 default_print_error_function;
153 /* Maximum characters per line in automatic line wrapping mode.
154 Zero means don't wrap lines. */
156 int diagnostic_message_length_per_line;
158 /* Used to control every diagnostic message formatting. Front-ends should
159 call set_message_prefixing_rule to set up their politics. */
160 static int current_prefixing_rule;
162 /* Initialize the diagnostic message outputting machinery. */
165 initialize_diagnostics ()
167 /* By default, we don't line-wrap messages. */
168 diagnostic_message_length_per_line = 0;
169 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
170 /* Proceed to actual initialization. */
171 default_initialize_buffer (diagnostic_buffer);
174 /* Predicate. Return 1 if we're in automatic line wrapping mode. */
177 doing_line_wrapping ()
179 return diagnostic_message_length_per_line > 0;
183 set_message_prefixing_rule (rule)
186 current_prefixing_rule = rule;
189 /* Returns true if BUFFER is in line-wrappind mode. */
191 output_is_line_wrapping (buffer)
192 output_buffer *buffer;
194 return buffer->ideal_maximum_length > 0;
197 /* Return BUFFER's prefix. */
199 output_get_prefix (buffer)
200 const output_buffer *buffer;
202 return buffer->prefix;
205 /* Subroutine of output_set_maximum_length. Set up BUFFER's
206 internal maximum characters per line. */
208 set_real_maximum_length (buffer)
209 output_buffer *buffer;
211 /* If we're told not to wrap lines then do the obvious thing. */
212 if (! output_is_line_wrapping (buffer))
213 buffer->maximum_length = buffer->ideal_maximum_length;
216 int prefix_length = buffer->prefix ? strlen (buffer->prefix) : 0;
217 /* If the prefix is ridiculously too long, output at least
219 if (buffer->ideal_maximum_length - prefix_length < 32)
220 buffer->maximum_length = buffer->ideal_maximum_length + 32;
222 buffer->maximum_length = buffer->ideal_maximum_length;
226 /* Sets the number of maximum characters per line BUFFER can output
227 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
229 output_set_maximum_length (buffer, length)
230 output_buffer *buffer;
233 buffer->ideal_maximum_length = length;
234 set_real_maximum_length (buffer);
237 /* Sets BUFFER's PREFIX. */
239 output_set_prefix (buffer, prefix)
240 output_buffer *buffer;
243 buffer->prefix = prefix;
244 set_real_maximum_length (buffer);
245 buffer->emitted_prefix_p = 0;
248 /* Free BUFFER's prefix, a previously malloc()'d string. */
251 output_destroy_prefix (buffer)
252 output_buffer *buffer;
256 free ((char *) buffer->prefix);
257 buffer->prefix = NULL;
261 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
262 characters per line. */
264 init_output_buffer (buffer, prefix, maximum_length)
265 output_buffer *buffer;
269 obstack_init (&buffer->obstack);
270 buffer->ideal_maximum_length = maximum_length;
271 buffer->line_length = 0;
272 output_set_prefix (buffer, prefix);
273 buffer->emitted_prefix_p = 0;
274 buffer->prefixing_rule = current_prefixing_rule;
276 buffer->cursor = NULL;
279 /* Initialize BUFFER with a NULL prefix and current diagnostic message
282 default_initialize_buffer (buffer)
283 output_buffer *buffer;
285 init_output_buffer (buffer, NULL, diagnostic_message_length_per_line);
288 /* Recompute diagnostic_buffer's attributes to reflect any change
289 in diagnostic formatting global options. */
291 reshape_diagnostic_buffer ()
293 diagnostic_buffer->ideal_maximum_length = diagnostic_message_length_per_line;
294 diagnostic_buffer->prefixing_rule = current_prefixing_rule;
295 set_real_maximum_length (diagnostic_buffer);
298 /* Reinitialize BUFFER. */
300 output_clear (buffer)
301 output_buffer *buffer;
303 obstack_free (&buffer->obstack, obstack_base (&buffer->obstack));
304 buffer->line_length = 0;
305 buffer->cursor = NULL;
306 buffer->emitted_prefix_p = 0;
309 /* Finishes to construct a NULL-terminated character string representing
310 the BUFFERed message. */
312 output_finish (buffer)
313 output_buffer *buffer;
315 obstack_1grow (&buffer->obstack, '\0');
316 return (const char *) obstack_finish (&buffer->obstack);
319 /* Return the amount of characters BUFFER can accept to
322 output_space_left (buffer)
323 const output_buffer *buffer;
325 return buffer->maximum_length - buffer->line_length;
328 /* Write out BUFFER's prefix. */
330 output_emit_prefix (buffer)
331 output_buffer *buffer;
335 switch (buffer->prefixing_rule)
338 case DIAGNOSTICS_SHOW_PREFIX_NEVER:
341 case DIAGNOSTICS_SHOW_PREFIX_ONCE:
342 if (buffer->emitted_prefix_p)
345 buffer->emitted_prefix_p = 1;
348 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE:
349 buffer->line_length += strlen (buffer->prefix);
351 (&buffer->obstack, buffer->prefix, buffer->line_length);
357 /* Have BUFFER start a new line. */
359 output_add_newline (buffer)
360 output_buffer *buffer;
362 obstack_1grow (&buffer->obstack, '\n');
363 buffer->line_length = 0;
366 /* Appends a character to BUFFER. */
368 output_add_character (buffer, c)
369 output_buffer *buffer;
372 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
373 output_add_newline (buffer);
374 obstack_1grow (&buffer->obstack, c);
375 ++buffer->line_length;
378 /* Adds a space to BUFFER. */
380 output_add_space (buffer)
381 output_buffer *buffer;
383 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
385 output_add_newline (buffer);
388 obstack_1grow (&buffer->obstack, ' ');
389 ++buffer->line_length;
392 /* These functions format an INTEGER into BUFFER as suggested by their
395 output_decimal (buffer, i)
396 output_buffer *buffer;
399 output_formatted_integer (buffer, "%d", i);
403 output_long_decimal (buffer, i)
404 output_buffer *buffer;
407 output_formatted_integer (buffer, "%ld", i);
411 output_unsigned_decimal (buffer, i)
412 output_buffer *buffer;
415 output_formatted_integer (buffer, "%u", i);
419 output_long_unsigned_decimal (buffer, i)
420 output_buffer *buffer;
423 output_formatted_integer (buffer, "%lu", i);
427 output_octal (buffer, i)
428 output_buffer *buffer;
431 output_formatted_integer (buffer, "%o", i);
435 output_long_octal (buffer, i)
436 output_buffer *buffer;
439 output_formatted_integer (buffer, "%lo", i);
443 output_hexadecimal (buffer, i)
444 output_buffer *buffer;
447 output_formatted_integer (buffer, "%x", i);
451 output_long_hexadecimal (buffer, i)
452 output_buffer *buffer;
455 output_formatted_integer (buffer, "%lx", i);
458 /* Append to BUFFER a string specified by its STARTING character
461 output_append_r (buffer, start, length)
462 output_buffer *buffer;
466 obstack_grow (&buffer->obstack, start, length);
467 buffer->line_length += length;
470 /* Append a string deliminated by START and END to BUFFER. No wrapping is
471 done. However, if beginning a new line then emit BUFFER->PREFIX and
472 skip any leading whitespace if appropriate. The caller must ensure
473 that it is safe to do so. */
475 output_append (buffer, start, end)
476 output_buffer *buffer;
480 /* Emit prefix and skip whitespace if we're starting a new line. */
481 if (buffer->line_length == 0)
483 output_emit_prefix (buffer);
484 if (output_is_line_wrapping (buffer))
485 while (start != end && *start == ' ')
488 output_append_r (buffer, start, end - start);
491 /* Wrap a STRing into BUFFER. */
494 output_add_string (buffer, str)
495 output_buffer *buffer;
500 if (!output_is_line_wrapping (buffer))
501 output_append (buffer, str, str + strlen (str));
504 while (*p && *p != ' ' && *p != '\n')
507 if (p - str < output_space_left (buffer))
508 output_append (buffer, str, p);
511 output_add_newline (buffer);
512 output_append (buffer, str, p);
515 while (*p && *p == '\n')
517 output_add_newline (buffer);
525 /* Flush the content of BUFFER onto FILE and reinitialize BUFFER. */
528 output_to_stream (buffer, file)
529 output_buffer *buffer;
532 const char *text = output_finish (buffer);
534 output_clear (buffer);
537 /* Format a message pointed to by BUFFER->CURSOR using BUFFER->CURSOR
538 as appropriate. The following format specifiers are recognized as
539 being language independent:
540 %d, %i: (signed) integer in base ten.
541 %u: unsigned integer in base ten.
542 %o: (signed) integer in base eight.
543 %x: (signged) integer in base sixteen.
544 %ld, %li, %lo, %lu, %lx: long versions of the above.
548 %*.s: a substring the length of which is specified by an integer. */
550 output_format (buffer)
551 output_buffer *buffer;
553 const char *msg = buffer->cursor;
554 for (; *buffer->cursor; ++buffer->cursor)
556 int long_integer = 0;
558 if (*buffer->cursor != '%')
560 output_add_character (buffer, *buffer->cursor);
564 /* We got a '%'. Let's see what happens. Record whether we're
565 parsing a long integer format specifier. */
566 if (*++buffer->cursor == 'l')
572 /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %o, %s, %u,
573 %x, %.*s; %%. And nothing else. Front-ends should install
574 printers to grok language specific format specifiers. */
575 switch (*buffer->cursor)
579 (buffer, va_arg (buffer->format_args, int));
586 (buffer, va_arg (buffer->format_args, long int));
588 output_decimal (buffer, va_arg (buffer->format_args, int));
594 (buffer, va_arg (buffer->format_args, long int));
596 output_octal (buffer, va_arg (buffer->format_args, int));
601 (buffer, va_arg (buffer->format_args, const char *));
606 output_long_unsigned_decimal
607 (buffer, va_arg (buffer->format_args, long unsigned int));
609 output_unsigned_decimal
610 (buffer, va_arg (buffer->format_args, unsigned int));
614 output_long_hexadecimal
615 (buffer, va_arg (buffer->format_args, long int));
617 output_hexadecimal (buffer, va_arg (buffer->format_args, int));
621 output_add_character (buffer, '%');
627 /* We handle no precision specifier but `%.*s'. */
628 if (*++buffer->cursor != '*')
630 else if (*++buffer->cursor != 's')
632 n = va_arg (buffer->format_args, int);
633 output_append (buffer, msg, msg + n);
638 if (!lang_printer || !(*lang_printer) (buffer))
640 /* Hmmm. The front-end failed to install a format translator
641 but called us with an unrecognized format. Sorry. */
646 output_finish (buffer);
650 vbuild_message_string (msgid, ap)
656 vasprintf (&str, msgid, ap);
660 /* Return a malloc'd string containing MSGID formatted a la
661 printf. The caller is reponsible for freeing the memory. */
664 build_message_string VPARAMS ((const char *msgid, ...))
666 #ifndef ANSI_PROTOTYPES
672 VA_START (ap, msgid);
674 #ifndef ANSI_PROTOTYPES
675 msgid = va_arg (ap, const char *);
678 str = vbuild_message_string (msgid, ap);
686 /* Return a malloc'd string describing a location. The caller is
687 responsible for freeing the memory. */
690 context_as_prefix (file, line, warn)
698 return build_message_string ("%s:%d: warning: ", file, line);
700 return build_message_string ("%s:%d: ", file, line);
705 return build_message_string ("%s: warning: ", progname);
707 return build_message_string ("%s: ", progname);
711 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
714 output_do_printf (buffer, msgid)
715 output_buffer *buffer;
718 char *message = vbuild_message_string (msgid, buffer->format_args);
720 output_add_string (buffer, message);
725 /* Format a message into BUFFER a la printf. */
728 output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
730 #ifndef ANSI_PROTOTYPES
731 struct output_buffer *buffer;
737 VA_START (ap, msgid);
738 #ifndef ANSI_PROTOTYPES
739 buffer = va_arg (ap, struct output_buffer *);
740 msgid = va_arg (ap, const char *);
742 va_copy (old_args, buffer->format_args);
744 va_copy (buffer->format_args, ap);
745 output_do_printf (buffer, msgid);
746 va_end (buffer->format_args);
748 va_copy (buffer->format_args, old_args);
752 /* Format a MESSAGE into FILE. Do line wrapping, starting new lines
756 line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...))
758 #ifndef ANSI_PROTOTYPES
762 output_buffer buffer;
764 default_initialize_buffer (&buffer);
765 VA_START (buffer.format_args, msgid);
767 #ifndef ANSI_PROTOTYPES
768 file = va_arg (buffer.format_args, FILE *);
769 msgid = va_arg (buffer.format_args, const char *);
772 output_do_printf (&buffer, msgid);
773 output_to_stream (&buffer, file);
775 va_end (buffer.format_args);
780 vline_wrapper_message_with_location (file, line, warn, msgid, ap)
787 output_buffer buffer;
789 init_output_buffer (&buffer, context_as_prefix (file, line, warn),
790 diagnostic_message_length_per_line);
791 va_copy (buffer.format_args, ap);
792 output_do_printf (&buffer, msgid);
793 output_to_stream (&buffer, stderr);
795 output_destroy_prefix (&buffer);
796 fputc ('\n', stderr);
800 /* Print the message MSGID in FILE. */
803 vnotice (file, msgid, ap)
808 vfprintf (file, _(msgid), ap);
811 /* Print MSGID on stderr. */
814 notice VPARAMS ((const char *msgid, ...))
816 #ifndef ANSI_PROTOTYPES
821 VA_START (ap, msgid);
823 #ifndef ANSI_PROTOTYPES
824 msgid = va_arg (ap, char *);
827 vnotice (stderr, msgid, ap);
831 /* Report FILE and LINE (or program name), and optionally just WARN. */
834 report_file_and_line (file, line, warn)
840 fprintf (stderr, "%s:%d: ", file, line);
842 fprintf (stderr, "%s: ", progname);
845 notice ("warning: ");
848 /* Print a message relevant to line LINE of file FILE. */
851 v_message_with_file_and_line (file, line, warn, msgid, ap)
858 report_file_and_line (file, line, warn);
859 vnotice (stderr, msgid, ap);
860 fputc ('\n', stderr);
863 /* Print a message relevant to the given DECL. */
866 v_message_with_decl (decl, warn, msgid, ap)
873 output_buffer buffer;
875 if (doing_line_wrapping ())
878 (&buffer, context_as_prefix
879 (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn),
880 diagnostic_message_length_per_line);
883 report_file_and_line (DECL_SOURCE_FILE (decl),
884 DECL_SOURCE_LINE (decl), warn);
886 /* Do magic to get around lack of varargs support for insertion
887 of arguments into existing list. We know that the decl is first;
888 we ass_u_me that it will be printed with "%s". */
890 for (p = _(msgid); *p; ++p)
896 else if (*(p + 1) != 's')
903 if (p > _(msgid)) /* Print the left-hand substring. */
905 if (doing_line_wrapping ())
906 output_printf (&buffer, "%.*s", (int)(p - _(msgid)), _(msgid));
908 fprintf (stderr, "%.*s", (int)(p - _(msgid)), _(msgid));
911 if (*p == '%') /* Print the name. */
913 const char *n = (DECL_NAME (decl)
914 ? (*decl_printable_name) (decl, 2)
915 : _("((anonymous))"));
916 if (doing_line_wrapping ())
917 output_add_string (&buffer, n);
923 if (ISALPHA (*(p - 1) & 0xFF))
928 if (*p) /* Print the rest of the message. */
930 if (doing_line_wrapping ())
932 va_copy (buffer.format_args, ap);
933 output_do_printf (&buffer, p);
934 va_copy (ap, buffer.format_args);
937 vfprintf (stderr, p, ap);
940 if (doing_line_wrapping())
942 output_to_stream (&buffer, stderr);
943 output_destroy_prefix (&buffer);
946 fputc ('\n', stderr);
949 /* Figure file and line of the given INSN. */
952 file_and_line_for_asm (insn, pfile, pline)
957 rtx body = PATTERN (insn);
960 /* Find the (or one of the) ASM_OPERANDS in the insn. */
961 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
962 asmop = SET_SRC (body);
963 else if (GET_CODE (body) == ASM_OPERANDS)
965 else if (GET_CODE (body) == PARALLEL
966 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
967 asmop = SET_SRC (XVECEXP (body, 0, 0));
968 else if (GET_CODE (body) == PARALLEL
969 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
970 asmop = XVECEXP (body, 0, 0);
976 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
977 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
981 *pfile = input_filename;
986 /* Report an error at line LINE of file FILE. */
989 v_error_with_file_and_line (file, line, msgid, ap)
996 report_error_function (file);
997 if (doing_line_wrapping ())
998 vline_wrapper_message_with_location (file, line, 0, msgid, ap);
1000 v_message_with_file_and_line (file, line, 0, msgid, ap);
1003 /* Report an error at the declaration DECL.
1004 MSGID is a format string which uses %s to substitute the declaration
1005 name; subsequent substitutions are a la printf. */
1008 v_error_with_decl (decl, msgid, ap)
1014 report_error_function (DECL_SOURCE_FILE (decl));
1015 v_message_with_decl (decl, 0, msgid, ap);
1019 /* Report an error at the line number of the insn INSN.
1020 This is used only when INSN is an `asm' with operands,
1021 and each ASM_OPERANDS records its own source file and line. */
1024 v_error_for_asm (insn, msgid, ap)
1033 file_and_line_for_asm (insn, &file, &line);
1034 report_error_function (file);
1035 v_message_with_file_and_line (file, line, 0, msgid, ap);
1039 /* Report an error at the current line number. */
1046 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
1050 /* Report a fatal error at the current line number. Allow a front end to
1051 intercept the message. */
1053 static void (*fatal_function) PARAMS ((const char *, va_list));
1060 if (fatal_function != 0)
1061 (*fatal_function) (_(msgid), ap);
1064 exit (FATAL_EXIT_CODE);
1067 /* Report a warning at line LINE of file FILE. */
1070 v_warning_with_file_and_line (file, line, msgid, ap)
1076 if (count_error (1))
1078 report_error_function (file);
1079 if (doing_line_wrapping ())
1080 vline_wrapper_message_with_location (file, line, 1, msgid, ap);
1082 v_message_with_file_and_line (file, line, 1, msgid, ap);
1087 /* Report a warning at the declaration DECL.
1088 MSGID is a format string which uses %s to substitute the declaration
1089 name; subsequent substitutions are a la printf. */
1092 v_warning_with_decl (decl, msgid, ap)
1097 if (count_error (1))
1099 report_error_function (DECL_SOURCE_FILE (decl));
1100 v_message_with_decl (decl, 1, msgid, ap);
1105 /* Report a warning at the line number of the insn INSN.
1106 This is used only when INSN is an `asm' with operands,
1107 and each ASM_OPERANDS records its own source file and line. */
1110 v_warning_for_asm (insn, msgid, ap)
1115 if (count_error (1))
1120 file_and_line_for_asm (insn, &file, &line);
1121 report_error_function (file);
1122 v_message_with_file_and_line (file, line, 1, msgid, ap);
1127 /* Report a warning at the current line number. */
1130 vwarning (msgid, ap)
1134 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
1137 /* These functions issue either warnings or errors depending on
1138 -pedantic-errors. */
1141 vpedwarn (msgid, ap)
1145 if (flag_pedantic_errors)
1148 vwarning (msgid, ap);
1153 v_pedwarn_with_decl (decl, msgid, ap)
1158 /* We don't want -pedantic-errors to cause the compilation to fail from
1159 "errors" in system header files. Sometimes fixincludes can't fix what's
1160 broken (eg: unsigned char bitfields - fixing it may change the alignment
1161 which will cause programs to mysteriously fail because the C library
1162 or kernel uses the original layout). There's no point in issuing a
1163 warning either, it's just unnecessary noise. */
1165 if (! DECL_IN_SYSTEM_HEADER (decl))
1167 if (flag_pedantic_errors)
1168 v_error_with_decl (decl, msgid, ap);
1170 v_warning_with_decl (decl, msgid, ap);
1176 v_pedwarn_with_file_and_line (file, line, msgid, ap)
1182 if (flag_pedantic_errors)
1183 v_error_with_file_and_line (file, line, msgid, ap);
1185 v_warning_with_file_and_line (file, line, msgid, ap);
1189 /* Apologize for not implementing some feature. */
1198 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1200 fprintf (stderr, "%s: ", progname);
1201 notice ("sorry, not implemented: ");
1202 vnotice (stderr, msgid, ap);
1203 fputc ('\n', stderr);
1207 /* Count an error or warning. Return 1 if the message should be printed. */
1210 count_error (warningp)
1213 if (warningp && inhibit_warnings)
1216 if (warningp && !warnings_are_errors)
1220 static int warning_message = 0;
1222 if (warningp && !warning_message)
1224 notice ("%s: warnings being treated as errors\n", progname);
1225 warning_message = 1;
1233 /* Print a diagnistic MSGID on FILE. */
1235 fnotice VPARAMS ((FILE *file, const char *msgid, ...))
1237 #ifndef ANSI_PROTOTYPES
1243 VA_START (ap, msgid);
1245 #ifndef ANSI_PROTOTYPES
1246 file = va_arg (ap, FILE *);
1247 msgid = va_arg (ap, const char *);
1250 vnotice (file, msgid, ap);
1255 /* Print a fatal error message. NAME is the text.
1256 Also include a system error message based on `errno'. */
1259 pfatal_with_name (name)
1262 fprintf (stderr, "%s: ", progname);
1264 exit (FATAL_EXIT_CODE);
1268 fatal_io_error (name)
1271 notice ("%s: %s: I/O error\n", progname, name);
1272 exit (FATAL_EXIT_CODE);
1275 /* Issue a pedantic warning MSGID. */
1277 pedwarn VPARAMS ((const char *msgid, ...))
1279 #ifndef ANSI_PROTOTYPES
1284 VA_START (ap, msgid);
1286 #ifndef ANSI_PROTOTYPES
1287 msgid = va_arg (ap, const char *);
1290 vpedwarn (msgid, ap);
1294 /* Issue a pedantic waring about DECL. */
1296 pedwarn_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1298 #ifndef ANSI_PROTOTYPES
1304 VA_START (ap, msgid);
1306 #ifndef ANSI_PROTOTYPES
1307 decl = va_arg (ap, tree);
1308 msgid = va_arg (ap, const char *);
1311 v_pedwarn_with_decl (decl, msgid, ap);
1315 /* Same as above but within the context FILE and LINE. */
1317 pedwarn_with_file_and_line VPARAMS ((const char *file, int line,
1318 const char *msgid, ...))
1320 #ifndef ANSI_PROTOTYPES
1327 VA_START (ap, msgid);
1329 #ifndef ANSI_PROTOTYPES
1330 file = va_arg (ap, const char *);
1331 line = va_arg (ap, int);
1332 msgid = va_arg (ap, const char *);
1335 v_pedwarn_with_file_and_line (file, line, msgid, ap);
1339 /* Just apologize with MSGID. */
1341 sorry VPARAMS ((const char *msgid, ...))
1343 #ifndef ANSI_PROTOTYPES
1348 VA_START (ap, msgid);
1350 #ifndef ANSI_PROTOTYPES
1351 msgid = va_arg (ap, const char *);
1358 /* Called when the start of a function definition is parsed,
1359 this function prints on stderr the name of the function. */
1362 announce_function (decl)
1367 if (rtl_dump_and_exit)
1368 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1371 if (doing_line_wrapping ())
1373 (stderr, " %s", (*decl_printable_name) (decl, 2));
1375 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1378 need_error_newline = 1;
1379 last_error_function = current_function_decl;
1383 /* The default function to print out name of current function that caused
1387 default_print_error_function (file)
1390 if (last_error_function != current_function_decl)
1392 char *prefix = NULL;
1393 output_buffer buffer;
1396 prefix = build_message_string ("%s: ", file);
1398 if (doing_line_wrapping ())
1400 (&buffer, prefix, diagnostic_message_length_per_line);
1404 fprintf (stderr, "%s: ", file);
1407 if (current_function_decl == NULL)
1409 if (doing_line_wrapping ())
1410 output_printf (&buffer, "At top level:\n");
1412 notice ("At top level:\n");
1416 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1418 if (doing_line_wrapping ())
1420 (&buffer, "In method `%s':\n",
1421 (*decl_printable_name) (current_function_decl, 2));
1423 notice ("In method `%s':\n",
1424 (*decl_printable_name) (current_function_decl, 2));
1428 if (doing_line_wrapping ())
1430 (&buffer, "In function `%s':\n",
1431 (*decl_printable_name) (current_function_decl, 2));
1433 notice ("In function `%s':\n",
1434 (*decl_printable_name) (current_function_decl, 2));
1438 last_error_function = current_function_decl;
1440 if (doing_line_wrapping ())
1441 output_to_stream (&buffer, stderr);
1443 free ((char*) prefix);
1447 /* Prints out, if necessary, the name of the current function
1448 that caused an error. Called from all error and warning functions.
1449 We ignore the FILE parameter, as it cannot be relied upon. */
1452 report_error_function (file)
1453 const char *file ATTRIBUTE_UNUSED;
1455 struct file_stack *p;
1457 if (need_error_newline)
1459 fprintf (stderr, "\n");
1460 need_error_newline = 0;
1463 if (input_file_stack && input_file_stack->next != 0
1464 && input_file_stack_tick != last_error_tick)
1466 for (p = input_file_stack->next; p; p = p->next)
1467 if (p == input_file_stack->next)
1468 notice ("In file included from %s:%d", p->name, p->line);
1470 notice (",\n from %s:%d", p->name, p->line);
1471 fprintf (stderr, ":\n");
1472 last_error_tick = input_file_stack_tick;
1475 (*print_error_function) (input_filename);
1479 error_with_file_and_line VPARAMS ((const char *file, int line,
1480 const char *msgid, ...))
1482 #ifndef ANSI_PROTOTYPES
1489 VA_START (ap, msgid);
1491 #ifndef ANSI_PROTOTYPES
1492 file = va_arg (ap, const char *);
1493 line = va_arg (ap, int);
1494 msgid = va_arg (ap, const char *);
1497 v_error_with_file_and_line (file, line, msgid, ap);
1502 error_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1504 #ifndef ANSI_PROTOTYPES
1510 VA_START (ap, msgid);
1512 #ifndef ANSI_PROTOTYPES
1513 decl = va_arg (ap, tree);
1514 msgid = va_arg (ap, const char *);
1517 v_error_with_decl (decl, msgid, ap);
1522 error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1524 #ifndef ANSI_PROTOTYPES
1530 VA_START (ap, msgid);
1532 #ifndef ANSI_PROTOTYPES
1533 insn = va_arg (ap, rtx);
1534 msgid = va_arg (ap, const char *);
1537 v_error_for_asm (insn, msgid, ap);
1542 error VPARAMS ((const char *msgid, ...))
1544 #ifndef ANSI_PROTOTYPES
1549 VA_START (ap, msgid);
1551 #ifndef ANSI_PROTOTYPES
1552 msgid = va_arg (ap, const char *);
1559 /* Set the function to call when a fatal error occurs. */
1562 set_fatal_function (f)
1563 void (*f) PARAMS ((const char *, va_list));
1569 fatal VPARAMS ((const char *msgid, ...))
1571 #ifndef ANSI_PROTOTYPES
1576 VA_START (ap, msgid);
1578 #ifndef ANSI_PROTOTYPES
1579 msgid = va_arg (ap, const char *);
1587 _fatal_insn (msgid, insn, file, line, function)
1592 const char *function;
1594 error ("%s", msgid);
1596 fancy_abort (file, line, function);
1600 _fatal_insn_not_found (insn, file, line, function)
1604 const char *function;
1606 if (INSN_CODE (insn) < 0)
1607 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1609 _fatal_insn ("Insn does not satisfy its constraints:",
1610 insn, file, line, function);
1614 warning_with_file_and_line VPARAMS ((const char *file, int line,
1615 const char *msgid, ...))
1617 #ifndef ANSI_PROTOTYPES
1624 VA_START (ap, msgid);
1626 #ifndef ANSI_PROTOTYPES
1627 file = va_arg (ap, const char *);
1628 line = va_arg (ap, int);
1629 msgid = va_arg (ap, const char *);
1632 v_warning_with_file_and_line (file, line, msgid, ap);
1637 warning_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1639 #ifndef ANSI_PROTOTYPES
1645 VA_START (ap, msgid);
1647 #ifndef ANSI_PROTOTYPES
1648 decl = va_arg (ap, tree);
1649 msgid = va_arg (ap, const char *);
1652 v_warning_with_decl (decl, msgid, ap);
1657 warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1659 #ifndef ANSI_PROTOTYPES
1665 VA_START (ap, msgid);
1667 #ifndef ANSI_PROTOTYPES
1668 insn = va_arg (ap, rtx);
1669 msgid = va_arg (ap, const char *);
1672 v_warning_for_asm (insn, msgid, ap);
1677 warning VPARAMS ((const char *msgid, ...))
1679 #ifndef ANSI_PROTOTYPES
1684 VA_START (ap, msgid);
1686 #ifndef ANSI_PROTOTYPES
1687 msgid = va_arg (ap, const char *);
1690 vwarning (msgid, ap);
1694 /* Save BUFFER's STATE. */
1696 save_output_state (buffer, state)
1697 const output_buffer *buffer;
1698 output_state *state;
1700 state->prefix = buffer->prefix;
1701 state->maximum_length = buffer->maximum_length;
1702 state->ideal_maximum_length = buffer->ideal_maximum_length;
1703 state->emitted_prefix_p = buffer->emitted_prefix_p;
1704 state->prefixing_rule = buffer->prefixing_rule;
1705 state->cursor = buffer->cursor;
1706 va_copy (state->format_args, buffer->format_args);
1709 /* Restore BUFFER's previously saved STATE. */
1711 restore_output_state (state, buffer)
1712 const output_state *state;
1713 output_buffer *buffer;
1715 buffer->prefix = state->prefix;
1716 buffer->maximum_length = state->maximum_length;
1717 buffer->ideal_maximum_length = state->ideal_maximum_length;
1718 buffer->emitted_prefix_p = state->emitted_prefix_p;
1719 buffer->prefixing_rule = state->prefixing_rule;
1720 buffer->cursor = state->cursor;
1721 va_copy (buffer->format_args, state->format_args);
1724 /* Helper subroutine of output_verbatim and verbatim. Do the approriate
1725 settings needed by BUFFER for a verbatim formatting. */
1727 output_do_verbatim (buffer)
1728 output_buffer *buffer;
1730 buffer->prefix = NULL;
1731 buffer->prefixing_rule = DIAGNOSTICS_SHOW_PREFIX_NEVER;
1732 output_set_maximum_length (buffer, 0);
1733 output_format (buffer);
1736 /* Output MESSAGE verbatim into BUFFER. */
1738 output_verbatim VPARAMS ((output_buffer *buffer, const char *msg, ...))
1740 #ifndef ANSI_PROTOTYPES
1741 output_buffer *buffer;
1744 output_state previous_state;
1748 #ifndef ANSI_PROTOTYPES
1749 buffer = va_arg (ap, output_buffer *);
1750 msg = va_arg (ap, const char *);
1752 save_output_state (buffer, &previous_state);
1753 buffer->cursor = msg;
1754 va_copy (buffer->format_args, ap);
1755 output_do_verbatim(buffer);
1756 va_end (buffer->format_args);
1757 restore_output_state (&previous_state, buffer);
1760 /* Same as above but use diagnostic_buffer. */
1762 verbatim VPARAMS ((const char *msg, ...))
1764 #ifndef ANSI_PROTOTYPES
1767 output_state previous_state;
1768 save_output_state (diagnostic_buffer, &previous_state);
1769 VA_START (diagnostic_args, msg);
1770 #ifndef ANSI_PROTOTYPES
1771 msg = va_arg (diagnostic_args, const char *);
1773 diagnostic_msg = msg;
1774 output_do_verbatim (diagnostic_buffer);
1775 output_to_stream (diagnostic_buffer, stderr);
1776 va_end (diagnostic_args);
1777 restore_output_state (&previous_state, diagnostic_buffer);