1 /* Language-independent diagnostic subroutines for the GNU C compiler
2 Copyright (C) 1999, 2000 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)
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 independant aspect of diagnostic
27 #undef FLOAT /* This is for hpux. They should change hpux. */
28 #undef FFS /* Some systems define this in param.h. */
36 #include "insn-attr.h"
37 #include "insn-codes.h"
38 #include "insn-config.h"
41 #include "diagnostic.h"
43 #define obstack_chunk_alloc xmalloc
44 #define obstack_chunk_free free
46 #define output_formatted_integer(BUFFER, FORMAT, INTEGER) \
48 sprintf (digit_buffer, FORMAT, INTEGER); \
49 output_add_string (BUFFER, digit_buffer); \
52 #define output_text_length(BUFFER) (BUFFER)->line_length
53 #define is_starting_newline(BUFFER) (output_text_length (BUFFER) == 0)
54 #define output_prefix(BUFFER) (BUFFER)->state.prefix
55 #define line_wrap_cutoff(BUFFER) (BUFFER)->state.maximum_length
56 #define ideal_line_wrap_cutoff(BUFFER) (BUFFER)->state.ideal_maximum_length
57 #define prefix_was_emitted_for(BUFFER) (BUFFER)->state.emitted_prefix_p
58 #define prefixing_policy(BUFFER) (BUFFER)->state.prefixing_rule
59 #define output_buffer_ptr_to_format_args(BUFFER) (BUFFER)->state.format_args
61 #define diagnostic_args output_buffer_ptr_to_format_args (diagnostic_buffer)
62 #define diagnostic_msg output_buffer_text_cursor (diagnostic_buffer)
65 static void finish_diagnostic PARAMS ((void));
66 static void output_do_verbatim PARAMS ((output_buffer *,
67 const char *, va_list *));
68 static void output_to_stream PARAMS ((output_buffer *, FILE *));
69 static void output_format PARAMS ((output_buffer *));
71 static char *vbuild_message_string PARAMS ((const char *, va_list));
72 static char *build_message_string PARAMS ((const char *, ...))
74 static char *context_as_prefix PARAMS ((const char *, int, int));
75 static void output_do_printf PARAMS ((output_buffer *, const char *));
76 static void format_with_decl PARAMS ((output_buffer *, tree));
77 static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
78 static void diagnostic_for_asm PARAMS ((rtx, const char *, va_list *, int));
79 static void diagnostic_for_decl PARAMS ((tree, const char *, va_list *, int));
80 static void vnotice PARAMS ((FILE *, const char *, va_list));
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 *,
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 *,
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 *,
96 static void clear_text_info PARAMS ((output_buffer *));
97 static void clear_diagnostic_info PARAMS ((output_buffer *));
99 static void error_recursion PARAMS ((void)) ATTRIBUTE_NORETURN;
100 static const char *trim_filename PARAMS ((const char *));
102 extern int rtl_dump_and_exit;
103 extern int inhibit_warnings;
104 extern int warnings_are_errors;
105 extern int warningcount;
106 extern int errorcount;
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 static int need_error_newline;
121 /* Function of last error message;
122 more generally, function such that if next error message is in it
123 then we don't have to mention the function name. */
124 static tree last_error_function = NULL;
126 /* Used to detect when input_file_stack has changed since last described. */
127 static int last_error_tick;
129 /* Called by report_error_function to print out function name.
130 * Default may be overridden by language front-ends. */
132 void (*print_error_function) PARAMS ((const char *)) =
133 default_print_error_function;
135 /* Maximum characters per line in automatic line wrapping mode.
136 Zero means don't wrap lines. */
138 int diagnostic_message_length_per_line;
140 /* Used to control every diagnostic message formatting. Front-ends should
141 call set_message_prefixing_rule to set up their politics. */
142 static int current_prefixing_rule;
144 /* Prevent recursion into the error handler. */
145 static int diagnostic_lock;
148 /* Initialize the diagnostic message outputting machinery. */
151 initialize_diagnostics ()
153 /* By default, we don't line-wrap messages. */
154 diagnostic_message_length_per_line = 0;
155 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
156 /* Proceed to actual initialization. */
157 default_initialize_buffer (diagnostic_buffer);
161 set_message_prefixing_rule (rule)
164 current_prefixing_rule = rule;
167 /* Returns true if BUFFER is in line-wrappind mode. */
169 output_is_line_wrapping (buffer)
170 output_buffer *buffer;
172 return ideal_line_wrap_cutoff (buffer) > 0;
175 /* Return BUFFER's prefix. */
177 output_get_prefix (buffer)
178 const output_buffer *buffer;
180 return output_prefix (buffer);
183 /* Subroutine of output_set_maximum_length. Set up BUFFER's
184 internal maximum characters per line. */
186 set_real_maximum_length (buffer)
187 output_buffer *buffer;
189 /* If we're told not to wrap lines then do the obvious thing. */
190 if (! output_is_line_wrapping (buffer))
191 line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer);
195 output_prefix (buffer) ? strlen (output_prefix (buffer)) : 0;
196 /* If the prefix is ridiculously too long, output at least
198 if (ideal_line_wrap_cutoff (buffer) - prefix_length < 32)
199 line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer) + 32;
201 line_wrap_cutoff (buffer) = ideal_line_wrap_cutoff (buffer);
205 /* Sets the number of maximum characters per line BUFFER can output
206 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
208 output_set_maximum_length (buffer, length)
209 output_buffer *buffer;
212 ideal_line_wrap_cutoff (buffer) = length;
213 set_real_maximum_length (buffer);
216 /* Sets BUFFER's PREFIX. */
218 output_set_prefix (buffer, prefix)
219 output_buffer *buffer;
222 output_prefix (buffer) = prefix;
223 set_real_maximum_length (buffer);
224 prefix_was_emitted_for (buffer) = 0;
227 /* Free BUFFER's prefix, a previously malloc()'d string. */
230 output_destroy_prefix (buffer)
231 output_buffer *buffer;
233 if (output_prefix (buffer) != NULL)
235 free ((char *) output_prefix (buffer));
236 output_prefix (buffer) = NULL;
240 /* Zero out any text output so far in BUFFER. */
242 clear_text_info (buffer)
243 output_buffer *buffer;
245 obstack_free (&buffer->obstack, obstack_base (&buffer->obstack));
246 output_text_length (buffer) = 0;
249 /* Zero out any diagnostic data used so far by BUFFER. */
251 clear_diagnostic_info (buffer)
252 output_buffer *buffer;
254 output_buffer_text_cursor (buffer) = NULL;
255 output_buffer_ptr_to_format_args (buffer) = NULL;
256 prefix_was_emitted_for (buffer) = 0;
259 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
260 characters per line. */
262 init_output_buffer (buffer, prefix, maximum_length)
263 output_buffer *buffer;
267 obstack_init (&buffer->obstack);
268 ideal_line_wrap_cutoff (buffer) = maximum_length;
269 prefixing_policy (buffer) = current_prefixing_rule;
270 output_set_prefix (buffer, prefix);
271 output_text_length (buffer) = 0;
272 clear_diagnostic_info (buffer);
275 /* Initialize BUFFER with a NULL prefix and current diagnostic message
278 default_initialize_buffer (buffer)
279 output_buffer *buffer;
281 init_output_buffer (buffer, NULL, diagnostic_message_length_per_line);
284 /* Recompute diagnostic_buffer's attributes to reflect any change
285 in diagnostic formatting global options. */
287 reshape_diagnostic_buffer ()
289 ideal_line_wrap_cutoff (diagnostic_buffer) =
290 diagnostic_message_length_per_line;
291 prefixing_policy (diagnostic_buffer) = current_prefixing_rule;
292 set_real_maximum_length (diagnostic_buffer);
295 /* Reinitialize BUFFER. */
297 output_clear (buffer)
298 output_buffer *buffer;
300 clear_text_info (buffer);
301 clear_diagnostic_info (buffer);
304 /* Finishes to construct a NULL-terminated character string representing
305 the BUFFERed message. */
307 output_finish (buffer)
308 output_buffer *buffer;
310 obstack_1grow (&buffer->obstack, '\0');
311 return (const char *) obstack_finish (&buffer->obstack);
314 /* Return the amount of characters BUFFER can accept to
317 output_space_left (buffer)
318 const output_buffer *buffer;
320 return line_wrap_cutoff (buffer) - output_text_length (buffer);
323 /* Write out BUFFER's prefix. */
325 output_emit_prefix (buffer)
326 output_buffer *buffer;
328 if (output_prefix (buffer) != NULL)
330 switch (prefixing_policy (buffer))
333 case DIAGNOSTICS_SHOW_PREFIX_NEVER:
336 case DIAGNOSTICS_SHOW_PREFIX_ONCE:
337 if (prefix_was_emitted_for (buffer))
339 /* Else fall through. */
341 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE:
343 int prefix_length = strlen (output_prefix (buffer));
344 output_append_r (buffer, output_prefix (buffer), prefix_length);
345 prefix_was_emitted_for (buffer) = 1;
352 /* Have BUFFER start a new line. */
354 output_add_newline (buffer)
355 output_buffer *buffer;
357 obstack_1grow (&buffer->obstack, '\n');
358 output_text_length (buffer) = 0;
361 /* Appends a character to BUFFER. */
363 output_add_character (buffer, c)
364 output_buffer *buffer;
367 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
368 output_add_newline (buffer);
369 obstack_1grow (&buffer->obstack, c);
370 ++output_text_length (buffer);
373 /* Adds a space to BUFFER. */
375 output_add_space (buffer)
376 output_buffer *buffer;
378 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
380 output_add_newline (buffer);
383 obstack_1grow (&buffer->obstack, ' ');
384 ++output_text_length (buffer);
387 /* These functions format an INTEGER into BUFFER as suggested by their
390 output_decimal (buffer, i)
391 output_buffer *buffer;
394 output_formatted_integer (buffer, "%d", i);
398 output_long_decimal (buffer, i)
399 output_buffer *buffer;
402 output_formatted_integer (buffer, "%ld", i);
406 output_unsigned_decimal (buffer, i)
407 output_buffer *buffer;
410 output_formatted_integer (buffer, "%u", i);
414 output_long_unsigned_decimal (buffer, i)
415 output_buffer *buffer;
418 output_formatted_integer (buffer, "%lu", i);
422 output_octal (buffer, i)
423 output_buffer *buffer;
426 output_formatted_integer (buffer, "%o", i);
430 output_long_octal (buffer, i)
431 output_buffer *buffer;
434 output_formatted_integer (buffer, "%lo", i);
438 output_hexadecimal (buffer, i)
439 output_buffer *buffer;
442 output_formatted_integer (buffer, "%x", i);
446 output_long_hexadecimal (buffer, i)
447 output_buffer *buffer;
450 output_formatted_integer (buffer, "%lx", i);
453 /* Append to BUFFER a string specified by its STARTING character
456 output_append_r (buffer, start, length)
457 output_buffer *buffer;
461 obstack_grow (&buffer->obstack, start, length);
462 output_text_length (buffer) += length;
465 /* Append a string deliminated by START and END to BUFFER. No wrapping is
466 done. However, if beginning a new line then emit output_prefix (BUFFER)
467 and skip any leading whitespace if appropriate. The caller must ensure
468 that it is safe to do so. */
470 output_append (buffer, start, end)
471 output_buffer *buffer;
475 /* Emit prefix and skip whitespace if we're starting a new line. */
476 if (is_starting_newline (buffer))
478 output_emit_prefix (buffer);
479 if (output_is_line_wrapping (buffer))
480 while (start != end && *start == ' ')
483 output_append_r (buffer, start, end - start);
486 /* Wrap a text delimited by START and END into BUFFER. */
488 wrap_text (buffer, start, end)
489 output_buffer *buffer;
495 /* Dump anything bodered by whitespaces. */
497 const char *p = start;
498 while (p != end && *p != ' ' && *p != '\n')
500 if (p - start >= output_space_left (buffer))
501 output_add_newline (buffer);
502 output_append (buffer, start, p);
506 if (start != end && *start == ' ')
508 output_add_space (buffer);
511 if (start != end && *start == '\n')
513 output_add_newline (buffer);
519 /* Same as wrap_text but wrap text only when in line-wrapping mode. */
521 maybe_wrap_text (buffer, start, end)
522 output_buffer *buffer;
526 if (output_is_line_wrapping (buffer))
527 wrap_text (buffer, start, end);
529 output_append (buffer, start, end);
533 /* Append a STRING to BUFFER; the STRING maybe be line-wrapped if in
537 output_add_string (buffer, str)
538 output_buffer *buffer;
541 maybe_wrap_text (buffer, str, str + (str ? strlen (str) : 0));
544 /* Flush the content of BUFFER onto FILE and reinitialize BUFFER. */
547 output_to_stream (buffer, file)
548 output_buffer *buffer;
551 const char *text = output_finish (buffer);
553 clear_text_info (buffer);
556 /* Format a message pointed to by output_buffer_text_cursor (BUFFER) using
557 output_buffer_format_args (BUFFER) as appropriate. The following format
558 specifiers are recognized as being language independent:
559 %d, %i: (signed) integer in base ten.
560 %u: unsigned integer in base ten.
561 %o: unsigned integer in base eight.
562 %x: unsigned integer in base sixteen.
563 %ld, %li, %lo, %lu, %lx: long versions of the above.
567 %*.s: a substring the length of which is specified by an integer. */
569 output_format (buffer)
570 output_buffer *buffer;
572 for (; *output_buffer_text_cursor (buffer);
573 ++output_buffer_text_cursor (buffer))
575 int long_integer = 0;
578 const char *p = output_buffer_text_cursor (buffer);
579 while (*p && *p != '%')
581 maybe_wrap_text (buffer, output_buffer_text_cursor (buffer), p);
582 output_buffer_text_cursor (buffer) = p;
584 if (!*output_buffer_text_cursor (buffer))
587 /* We got a '%'. Let's see what happens. Record whether we're
588 parsing a long integer format specifier. */
589 if (*++output_buffer_text_cursor (buffer) == 'l')
592 ++output_buffer_text_cursor (buffer);
595 /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %o, %s, %u,
596 %x, %.*s; %%. And nothing else. Front-ends should install
597 printers to grok language specific format specifiers. */
598 switch (*output_buffer_text_cursor (buffer))
602 (buffer, va_arg (output_buffer_format_args (buffer), int));
609 (buffer, va_arg (output_buffer_format_args (buffer), long int));
612 (buffer, va_arg (output_buffer_format_args (buffer), int));
617 output_long_octal (buffer,
618 va_arg (output_buffer_format_args (buffer),
621 output_octal (buffer,
622 va_arg (output_buffer_format_args (buffer),
627 output_add_string (buffer,
628 va_arg (output_buffer_format_args (buffer),
634 output_long_unsigned_decimal
635 (buffer, va_arg (output_buffer_format_args (buffer),
638 output_unsigned_decimal
639 (buffer, va_arg (output_buffer_format_args (buffer),
644 output_long_hexadecimal
645 (buffer, va_arg (output_buffer_format_args (buffer),
649 (buffer, va_arg (output_buffer_format_args (buffer),
654 output_add_character (buffer, '%');
661 /* We handle no precision specifier but `%.*s'. */
662 if (*++output_buffer_text_cursor (buffer) != '*')
664 else if (*++output_buffer_text_cursor (buffer) != 's')
666 n = va_arg (output_buffer_format_args (buffer), int);
667 s = va_arg (output_buffer_format_args (buffer), const char *);
668 output_append (buffer, s, s + n);
673 if (!lang_printer || !(*lang_printer) (buffer))
675 /* Hmmm. The front-end failed to install a format translator
676 but called us with an unrecognized format. Sorry. */
684 vbuild_message_string (msgid, ap)
690 vasprintf (&str, msgid, ap);
694 /* Return a malloc'd string containing MSGID formatted a la
695 printf. The caller is reponsible for freeing the memory. */
698 build_message_string VPARAMS ((const char *msgid, ...))
700 #ifndef ANSI_PROTOTYPES
706 VA_START (ap, msgid);
708 #ifndef ANSI_PROTOTYPES
709 msgid = va_arg (ap, const char *);
712 str = vbuild_message_string (msgid, ap);
720 /* Return a malloc'd string describing a location. The caller is
721 responsible for freeing the memory. */
724 context_as_prefix (file, line, warn)
732 return build_message_string ("%s:%d: warning: ", file, line);
734 return build_message_string ("%s:%d: ", file, line);
739 return build_message_string ("%s: warning: ", progname);
741 return build_message_string ("%s: ", progname);
745 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
748 output_do_printf (buffer, msgid)
749 output_buffer *buffer;
752 char *message = vbuild_message_string (msgid,
753 output_buffer_format_args (buffer));
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, output_buffer *);
775 msgid = va_arg (ap, const char *);
777 old_args = output_buffer_ptr_to_format_args (buffer);
778 output_buffer_ptr_to_format_args (buffer) = ≈
779 output_do_printf (buffer, msgid);
780 output_buffer_ptr_to_format_args (buffer) = old_args;
784 /* Print the message MSGID in FILE. */
787 vnotice (file, msgid, ap)
792 vfprintf (file, _(msgid), ap);
795 /* Print a message relevant to the given DECL. */
798 format_with_decl (buffer, decl)
799 output_buffer *buffer;
804 /* Do magic to get around lack of varargs support for insertion
805 of arguments into existing list. We know that the decl is first;
806 we ass_u_me that it will be printed with "%s". */
807 for (p = output_buffer_text_cursor (buffer); *p; ++p)
813 else if (*(p + 1) != 's')
820 /* Print the left-hand substring. */
821 maybe_wrap_text (buffer, output_buffer_text_cursor (buffer), p);
823 if (*p == '%') /* Print the name. */
825 const char *n = (DECL_NAME (decl)
826 ? (*decl_printable_name) (decl, 2)
827 : _("((anonymous))"));
828 output_add_string (buffer, n);
832 if (ISALPHA (*(p - 1) & 0xFF))
837 if (*p) /* Print the rest of the message. */
839 output_buffer_text_cursor (buffer) = p;
840 output_format (buffer);
844 /* Figure file and line of the given INSN. */
847 file_and_line_for_asm (insn, pfile, pline)
852 rtx body = PATTERN (insn);
855 /* Find the (or one of the) ASM_OPERANDS in the insn. */
856 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
857 asmop = SET_SRC (body);
858 else if (GET_CODE (body) == ASM_OPERANDS)
860 else if (GET_CODE (body) == PARALLEL
861 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
862 asmop = SET_SRC (XVECEXP (body, 0, 0));
863 else if (GET_CODE (body) == PARALLEL
864 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
865 asmop = XVECEXP (body, 0, 0);
871 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
872 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
876 *pfile = input_filename;
881 /* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
882 of the insn INSN. This is used only when INSN is an `asm' with operands,
883 and each ASM_OPERANDS records its own source file and line. */
885 diagnostic_for_asm (insn, msg, args_ptr, warn)
894 file_and_line_for_asm (insn, &file, &line);
895 report_diagnostic (msg, args_ptr, file, line, warn);
898 /* Report a diagnostic MESSAGE at the declaration DECL.
899 MSG is a format string which uses %s to substitute the declaration
900 name; subsequent substitutions are a la output_format. */
902 diagnostic_for_decl (decl, msg, args_ptr, warn)
910 if (diagnostic_lock++)
913 if (count_error (warn))
915 os = diagnostic_buffer->state;
916 report_error_function (DECL_SOURCE_FILE (decl));
918 (diagnostic_buffer, context_as_prefix
919 (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn));
920 output_buffer_ptr_to_format_args (diagnostic_buffer) = args_ptr;
921 output_buffer_text_cursor (diagnostic_buffer) = msg;
922 format_with_decl (diagnostic_buffer, decl);
923 finish_diagnostic ();
924 output_destroy_prefix (diagnostic_buffer);
926 diagnostic_buffer->state = os;
932 /* Count an error or warning. Return 1 if the message should be printed. */
935 count_error (warningp)
938 if (warningp && inhibit_warnings)
941 if (warningp && !warnings_are_errors)
945 static int warning_message = 0;
947 if (warningp && !warning_message)
949 verbatim ("%s: warnings being treated as errors\n", progname);
958 /* Print a diagnistic MSGID on FILE. */
960 fnotice VPARAMS ((FILE *file, const char *msgid, ...))
962 #ifndef ANSI_PROTOTYPES
968 VA_START (ap, msgid);
970 #ifndef ANSI_PROTOTYPES
971 file = va_arg (ap, FILE *);
972 msgid = va_arg (ap, const char *);
975 vnotice (file, msgid, ap);
980 /* Print a fatal error message. NAME is the text.
981 Also include a system error message based on `errno'. */
984 pfatal_with_name (name)
987 fprintf (stderr, "%s: ", progname);
989 exit (FATAL_EXIT_CODE);
993 fatal_io_error (name)
996 verbatim ("%s: %s: I/O error\n", progname, name);
997 exit (FATAL_EXIT_CODE);
1000 /* Issue a pedantic warning MSGID. */
1002 pedwarn VPARAMS ((const char *msgid, ...))
1004 #ifndef ANSI_PROTOTYPES
1009 VA_START (ap, msgid);
1011 #ifndef ANSI_PROTOTYPES
1012 msgid = va_arg (ap, const char *);
1015 report_diagnostic (msgid, &ap, input_filename, lineno,
1016 !flag_pedantic_errors);
1020 /* Issue a pedantic waring about DECL. */
1022 pedwarn_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1024 #ifndef ANSI_PROTOTYPES
1030 VA_START (ap, msgid);
1032 #ifndef ANSI_PROTOTYPES
1033 decl = va_arg (ap, tree);
1034 msgid = va_arg (ap, const char *);
1036 /* We don't want -pedantic-errors to cause the compilation to fail from
1037 "errors" in system header files. Sometimes fixincludes can't fix what's
1038 broken (eg: unsigned char bitfields - fixing it may change the alignment
1039 which will cause programs to mysteriously fail because the C library
1040 or kernel uses the original layout). There's no point in issuing a
1041 warning either, it's just unnecessary noise. */
1042 if (!DECL_IN_SYSTEM_HEADER (decl))
1043 diagnostic_for_decl (decl, msgid, &ap, !flag_pedantic_errors);
1047 /* Same as above but within the context FILE and LINE. */
1049 pedwarn_with_file_and_line VPARAMS ((const char *file, int line,
1050 const char *msgid, ...))
1052 #ifndef ANSI_PROTOTYPES
1059 VA_START (ap, msgid);
1061 #ifndef ANSI_PROTOTYPES
1062 file = va_arg (ap, const char *);
1063 line = va_arg (ap, int);
1064 msgid = va_arg (ap, const char *);
1067 report_diagnostic (msgid, &ap, file, line, !flag_pedantic_errors);
1071 /* Just apologize with MSGID. */
1073 sorry VPARAMS ((const char *msgid, ...))
1075 #ifndef ANSI_PROTOTYPES
1081 os = diagnostic_buffer->state;
1082 VA_START (ap, msgid);
1084 #ifndef ANSI_PROTOTYPES
1085 msgid = va_arg (ap, const char *);
1089 (diagnostic_buffer, context_as_prefix (input_filename, lineno, 0));
1090 output_printf (diagnostic_buffer, "sorry, not implemented: ");
1091 output_buffer_ptr_to_format_args (diagnostic_buffer) = ≈
1092 output_buffer_text_cursor (diagnostic_buffer) = msgid;
1093 output_format (diagnostic_buffer);
1094 finish_diagnostic ();
1095 diagnostic_buffer->state = os;
1099 /* Called when the start of a function definition is parsed,
1100 this function prints on stderr the name of the function. */
1103 announce_function (decl)
1108 if (rtl_dump_and_exit)
1109 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1111 verbatim (" %s", (*decl_printable_name) (decl, 2));
1113 need_error_newline = 1;
1114 last_error_function = current_function_decl;
1118 /* The default function to print out name of current function that caused
1122 default_print_error_function (file)
1125 if (last_error_function != current_function_decl)
1127 char *prefix = file ? build_message_string ("%s: ", file) : NULL;
1130 os = diagnostic_buffer->state;
1131 output_set_prefix (diagnostic_buffer, prefix);
1133 if (current_function_decl == NULL)
1135 output_add_string (diagnostic_buffer, "At top level:");
1136 output_add_newline (diagnostic_buffer);
1140 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1142 (diagnostic_buffer, "In method `%s':\n",
1143 (*decl_printable_name) (current_function_decl, 2));
1146 (diagnostic_buffer, "In function `%s':\n",
1147 (*decl_printable_name) (current_function_decl, 2));
1150 last_error_function = current_function_decl;
1151 output_to_stream (diagnostic_buffer, stderr);
1152 diagnostic_buffer->state = os;
1153 free ((char*) prefix);
1157 /* Prints out, if necessary, the name of the current function
1158 that caused an error. Called from all error and warning functions.
1159 We ignore the FILE parameter, as it cannot be relied upon. */
1162 report_error_function (file)
1163 const char *file ATTRIBUTE_UNUSED;
1165 struct file_stack *p;
1167 if (need_error_newline)
1170 need_error_newline = 0;
1173 if (input_file_stack && input_file_stack->next != 0
1174 && input_file_stack_tick != last_error_tick)
1176 for (p = input_file_stack->next; p; p = p->next)
1177 if (p == input_file_stack->next)
1178 verbatim ("In file included from %s:%d", p->name, p->line);
1180 verbatim (",\n from %s:%d", p->name, p->line);
1182 last_error_tick = input_file_stack_tick;
1185 (*print_error_function) (input_filename);
1189 error_with_file_and_line VPARAMS ((const char *file, int line,
1190 const char *msgid, ...))
1192 #ifndef ANSI_PROTOTYPES
1199 VA_START (ap, msgid);
1201 #ifndef ANSI_PROTOTYPES
1202 file = va_arg (ap, const char *);
1203 line = va_arg (ap, int);
1204 msgid = va_arg (ap, const char *);
1207 report_diagnostic (msgid, &ap, file, line, /* warn = */ 0);
1212 error_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1214 #ifndef ANSI_PROTOTYPES
1220 VA_START (ap, msgid);
1222 #ifndef ANSI_PROTOTYPES
1223 decl = va_arg (ap, tree);
1224 msgid = va_arg (ap, const char *);
1227 diagnostic_for_decl (decl, msgid, &ap, /* warn = */ 0);
1232 error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1234 #ifndef ANSI_PROTOTYPES
1240 VA_START (ap, msgid);
1242 #ifndef ANSI_PROTOTYPES
1243 insn = va_arg (ap, rtx);
1244 msgid = va_arg (ap, const char *);
1247 diagnostic_for_asm (insn, msgid, &ap, /* warn = */ 0);
1252 error VPARAMS ((const char *msgid, ...))
1254 #ifndef ANSI_PROTOTYPES
1259 VA_START (ap, msgid);
1261 #ifndef ANSI_PROTOTYPES
1262 msgid = va_arg (ap, const char *);
1265 report_diagnostic (msgid, &ap, input_filename, lineno, /* warn = */ 0);
1269 /* Report a fatal error at the current line number. Allow a front end to
1270 intercept the message. */
1272 fatal VPARAMS ((const char *msgid, ...))
1274 #ifndef ANSI_PROTOTYPES
1279 VA_START (ap, msgid);
1281 #ifndef ANSI_PROTOTYPES
1282 msgid = va_arg (ap, const char *);
1285 report_diagnostic (msgid, &ap, input_filename, lineno, 0);
1287 exit (FATAL_EXIT_CODE);
1291 _fatal_insn (msgid, insn, file, line, function)
1296 const char *function;
1298 error ("%s", msgid);
1300 fancy_abort (file, line, function);
1304 _fatal_insn_not_found (insn, file, line, function)
1308 const char *function;
1310 if (INSN_CODE (insn) < 0)
1311 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1313 _fatal_insn ("Insn does not satisfy its constraints:",
1314 insn, file, line, function);
1318 warning_with_file_and_line VPARAMS ((const char *file, int line,
1319 const char *msgid, ...))
1321 #ifndef ANSI_PROTOTYPES
1328 VA_START (ap, msgid);
1330 #ifndef ANSI_PROTOTYPES
1331 file = va_arg (ap, const char *);
1332 line = va_arg (ap, int);
1333 msgid = va_arg (ap, const char *);
1336 report_diagnostic (msgid, &ap, file, line, /* warn = */ 1);
1341 warning_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1343 #ifndef ANSI_PROTOTYPES
1349 VA_START (ap, msgid);
1351 #ifndef ANSI_PROTOTYPES
1352 decl = va_arg (ap, tree);
1353 msgid = va_arg (ap, const char *);
1356 diagnostic_for_decl (decl, msgid, &ap, /* warn = */ 1);
1361 warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1363 #ifndef ANSI_PROTOTYPES
1369 VA_START (ap, msgid);
1371 #ifndef ANSI_PROTOTYPES
1372 insn = va_arg (ap, rtx);
1373 msgid = va_arg (ap, const char *);
1376 diagnostic_for_asm (insn, msgid, &ap, /* warn = */ 1);
1381 warning VPARAMS ((const char *msgid, ...))
1383 #ifndef ANSI_PROTOTYPES
1388 VA_START (ap, msgid);
1390 #ifndef ANSI_PROTOTYPES
1391 msgid = va_arg (ap, const char *);
1394 report_diagnostic (msgid, &ap, input_filename, lineno, /* warn = */ 1);
1398 /* Flush diagnostic_buffer content on stderr. */
1400 finish_diagnostic ()
1402 output_to_stream (diagnostic_buffer, stderr);
1403 clear_diagnostic_info (diagnostic_buffer);
1404 fputc ('\n', stderr);
1408 /* Helper subroutine of output_verbatim and verbatim. Do the approriate
1409 settings needed by BUFFER for a verbatim formatting. */
1411 output_do_verbatim (buffer, msg, args_ptr)
1412 output_buffer *buffer;
1419 output_prefix (buffer) = NULL;
1420 prefixing_policy (buffer) = DIAGNOSTICS_SHOW_PREFIX_NEVER;
1421 output_buffer_text_cursor (buffer) = msg;
1422 output_buffer_ptr_to_format_args (buffer) = args_ptr;
1423 output_set_maximum_length (buffer, 0);
1424 output_format (buffer);
1428 /* Output MESSAGE verbatim into BUFFER. */
1430 output_verbatim VPARAMS ((output_buffer *buffer, const char *msg, ...))
1432 #ifndef ANSI_PROTOTYPES
1433 output_buffer *buffer;
1439 #ifndef ANSI_PROTOTYPES
1440 buffer = va_arg (ap, output_buffer *);
1441 msg = va_arg (ap, const char *);
1443 output_do_verbatim (buffer, msg, &ap);
1447 /* Same as above but use diagnostic_buffer. */
1449 verbatim VPARAMS ((const char *msg, ...))
1451 #ifndef ANSI_PROTOTYPES
1457 #ifndef ANSI_PROTOTYPES
1458 msg = va_arg (ap, const char *);
1460 output_do_verbatim (diagnostic_buffer, msg, &ap);
1461 output_to_stream (diagnostic_buffer, stderr);
1465 /* Report a diagnostic MESSAGE (an error or a WARNING) involving
1466 entities in ARGUMENTS. FILE and LINE indicate where the diagnostic
1467 occurs. This function is *the* subroutine in terms of which front-ends
1468 should implement their specific diagnostic handling modules.
1469 The front-end independent format specifiers are exactly those described
1470 in the documentation of output_format. */
1472 report_diagnostic (msg, args_ptr, file, line, warn)
1481 if (diagnostic_lock++)
1484 if (count_error (warn))
1486 os = diagnostic_buffer->state;
1487 diagnostic_msg = msg;
1488 diagnostic_args = args_ptr;
1489 report_error_function (file);
1491 (diagnostic_buffer, context_as_prefix (file, line, warn));
1492 output_format (diagnostic_buffer);
1493 finish_diagnostic ();
1494 output_destroy_prefix (diagnostic_buffer);
1495 diagnostic_buffer->state = os;
1501 /* Inform the user that an error occurred while trying to report some
1502 other error. This indicates catastrophic internal inconsistencies,
1503 so give up now. But do try to flush out the previous error. */
1507 if (diagnostic_lock < 3)
1508 finish_diagnostic ();
1511 "Internal compiler error: Error reporting routines re-entered.\n\
1512 Please submit a full bug report.\n\
1513 See %s for instructions.\n", GCCBUGURL);
1515 exit (FATAL_EXIT_CODE);
1518 /* Given a partial pathname as input, return another pathname that
1519 shares no directory elements with the pathname of __FILE__. This
1520 is used by fancy_abort() to print `Internal compiler error in expr.c'
1521 instead of `Internal compiler error in ../../egcs/gcc/expr.c'. */
1523 trim_filename (name)
1526 static const char this_file[] = __FILE__;
1527 const char *p = name, *q = this_file;
1529 while (*p == *q && *p != 0 && *q != 0) p++, q++;
1530 while (p > name && p[-1] != DIR_SEPARATOR
1531 #ifdef DIR_SEPARATOR_2
1532 && p[-1] != DIR_SEPARATOR_2
1540 /* Report an internal compiler error in a friendly manner and without
1544 fancy_abort (file, line, function)
1547 const char *function;
1550 "Internal compiler error in %s, at %s:%d\n\
1551 Please submit a full bug report.\n\
1552 See %s for instructions.",
1553 function, trim_filename (file), line, GCCBUGURL);