Use new tail-calling mechanism on ARM.
[official-gcc.git] / gcc / diagnostic.c
blob369d4a3a73d4124d57042bb42e3dbc34b4c15f44
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)
9 any later version.
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
23 message module. */
25 #include "config.h"
26 #undef FLOAT /* This is for hpux. They should change hpux. */
27 #undef FFS /* Some systems define this in param.h. */
28 #include "system.h"
30 #include "tree.h"
31 #include "rtl.h"
32 #include "tm_p.h"
33 #include "flags.h"
34 #include "input.h"
35 #include "insn-attr.h"
36 #include "insn-codes.h"
37 #include "insn-config.h"
38 #include "toplev.h"
39 #include "intl.h"
40 #include "diagnostic.h"
42 #define obstack_chunk_alloc xmalloc
43 #define obstack_chunk_free free
45 /* Prototypes. */
46 static int doing_line_wrapping PARAMS ((void));
48 static char *vbuild_message_string PARAMS ((const char *, va_list));
49 static char *build_message_string PARAMS ((const char *, ...))
50 ATTRIBUTE_PRINTF_1;
51 static char *build_location_prefix PARAMS ((const char *, int, int));
52 static void output_notice PARAMS ((output_buffer *, const char *));
53 static void line_wrapper_printf PARAMS ((FILE *, const char *, ...))
54 ATTRIBUTE_PRINTF_2;
55 static void vline_wrapper_message_with_location PARAMS ((const char *, int,
56 int, const char *,
57 va_list));
58 static void notice PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1;
59 static void v_message_with_file_and_line PARAMS ((const char *, int, int,
60 const char *, va_list));
61 static void v_message_with_decl PARAMS ((tree, int, const char *, va_list));
62 static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
63 static void v_error_with_file_and_line PARAMS ((const char *, int,
64 const char *, va_list));
65 static void v_error_with_decl PARAMS ((tree, const char *, va_list));
66 static void v_error_for_asm PARAMS ((rtx, const char *, va_list));
67 static void verror PARAMS ((const char *, va_list));
68 static void vfatal PARAMS ((const char *, va_list)) ATTRIBUTE_NORETURN;
69 static void v_warning_with_file_and_line PARAMS ((const char *, int,
70 const char *, va_list));
71 static void v_warning_with_decl PARAMS ((tree, const char *, va_list));
72 static void v_warning_for_asm PARAMS ((rtx, const char *, va_list));
73 static void vwarning PARAMS ((const char *, va_list));
74 static void vpedwarn PARAMS ((const char *, va_list));
75 static void v_pedwarn_with_decl PARAMS ((tree, const char *, va_list));
76 static void v_pedwarn_with_file_and_line PARAMS ((const char *, int,
77 const char *, va_list));
78 static void vsorry PARAMS ((const char *, va_list));
79 static void report_file_and_line PARAMS ((const char *, int, int));
80 static void vnotice PARAMS ((FILE *, const char *, va_list));
81 static void set_real_maximum_length PARAMS ((output_buffer *));
83 extern int rtl_dump_and_exit;
84 extern int inhibit_warnings;
85 extern int warnings_are_errors;
86 extern int warningcount;
87 extern int errorcount;
89 /* Front-end specific tree formatter, if non-NULL. */
90 printer_fn lang_printer = NULL;
92 static int need_error_newline;
94 /* Function of last error message;
95 more generally, function such that if next error message is in it
96 then we don't have to mention the function name. */
97 static tree last_error_function = NULL;
99 /* Used to detect when input_file_stack has changed since last described. */
100 static int last_error_tick;
102 /* Called by report_error_function to print out function name.
103 * Default may be overridden by language front-ends. */
105 void (*print_error_function) PARAMS ((const char *)) =
106 default_print_error_function;
108 /* Maximum characters per line in automatic line wrapping mode.
109 Zero means don't wrap lines. */
111 static int output_maximum_width = 0;
113 /* Predicate. Return 1 if we're in automatic line wrapping mode. */
115 static int
116 doing_line_wrapping ()
118 return output_maximum_width > 0;
121 /* Set Maximum characters per line in automatic line wrapping mode. */
123 void
124 set_message_length (n)
125 int n;
127 output_maximum_width = n;
130 /* Returns true if BUFFER is in line-wrappind mode. */
132 output_is_line_wrapping (buffer)
133 output_buffer *buffer;
135 return buffer->ideal_maximum_length > 0;
138 /* Return BUFFER's prefix. */
139 char *
140 output_get_prefix (buffer)
141 const output_buffer *buffer;
143 return buffer->prefix;
146 /* Subroutine of output_set_maximum_length. Set up BUFFER's
147 internal maximum characters per line. */
148 static void
149 set_real_maximum_length (buffer)
150 output_buffer *buffer;
152 /* If we're told not to wrap lines then do the obvious thing. */
153 if (! output_is_line_wrapping (buffer))
154 buffer->maximum_length = buffer->ideal_maximum_length;
155 else
157 int prefix_length = buffer->prefix ? strlen (buffer->prefix) : 0;
158 /* If the prefix is ridiculously too long, output at least
159 32 characters. */
160 if (buffer->ideal_maximum_length - prefix_length < 32)
161 buffer->maximum_length = buffer->ideal_maximum_length + 32;
162 else
163 buffer->maximum_length = buffer->ideal_maximum_length;
167 /* Sets the number of maximum characters per line BUFFER can output
168 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
169 void
170 output_set_maximum_length (buffer, length)
171 output_buffer *buffer;
172 int length;
174 buffer->ideal_maximum_length = length;
175 set_real_maximum_length (buffer);
178 /* Sets BUFFER's PREFIX. */
179 void
180 output_set_prefix (buffer, prefix)
181 output_buffer *buffer;
182 char *prefix;
184 buffer->prefix = prefix;
185 set_real_maximum_length (buffer);
188 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
189 characters per line. */
190 void
191 init_output_buffer (buffer, prefix, maximum_length)
192 output_buffer *buffer;
193 char *prefix;
194 int maximum_length;
196 obstack_init (&buffer->obstack);
197 buffer->ideal_maximum_length = maximum_length;
198 buffer->line_length = 0;
199 output_set_prefix (buffer, prefix);
201 buffer->cursor = NULL;
204 /* Reinitialize BUFFER. */
205 void
206 output_clear (buffer)
207 output_buffer *buffer;
209 obstack_free (&buffer->obstack, obstack_base (&buffer->obstack));
210 buffer->line_length = 0;
211 buffer->cursor = NULL;
214 /* Finishes to construct a NULL-terminated character string representing
215 the BUFFERed message. */
216 const char *
217 output_finish (buffer)
218 output_buffer *buffer;
220 obstack_1grow (&buffer->obstack, '\0');
221 return (const char *) obstack_finish (&buffer->obstack);
224 /* Return the amount of characters BUFFER can accept to
225 make a full line. */
227 output_space_left (buffer)
228 const output_buffer *buffer;
230 return buffer->maximum_length - buffer->line_length;
233 /* Write out BUFFER's prefix. */
234 void
235 output_emit_prefix (buffer)
236 output_buffer *buffer;
238 if (buffer->prefix)
240 buffer->line_length = strlen (buffer->prefix);
241 obstack_grow (&buffer->obstack, buffer->prefix, buffer->line_length);
245 /* Have BUFFER start a new line. */
246 void
247 output_add_newline (buffer)
248 output_buffer *buffer;
250 obstack_1grow (&buffer->obstack, '\n');
251 buffer->line_length = 0;
254 /* Appends a character to BUFFER. */
255 void
256 output_add_character (buffer, c)
257 output_buffer *buffer;
258 int c;
260 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
261 output_add_newline (buffer);
262 obstack_1grow (&buffer->obstack, c);
263 ++buffer->line_length;
266 /* Adds a space to BUFFER. */
267 void
268 output_add_space (buffer)
269 output_buffer *buffer;
271 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
273 output_add_newline (buffer);
274 return;
276 obstack_1grow (&buffer->obstack, ' ');
277 ++buffer->line_length;
280 /* Add the stringified version of an integer to BUFFER. */
281 void
282 output_add_integer (buffer, i)
283 output_buffer *buffer;
284 HOST_WIDE_INT i;
286 /* This must be large enough to hold any printed integer or
287 floating-point value. */
288 static char digit_buffer[128];
290 sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, i);
291 output_add_string (buffer, digit_buffer);
294 /* Append a string deliminated by START and END to BUFFER. No wrapping is
295 done. The caller must ensure that it is safe to do so. */
297 void
298 output_append (buffer, start, end)
299 output_buffer *buffer;
300 const char *start;
301 const char *end;
303 int n;
305 /* Emit prefix and skip whitespace if we're starting a new line. */
306 if (buffer->line_length == 0)
308 output_emit_prefix (buffer);
309 while (start != end && *start == ' ')
310 ++start;
312 n = end - start;
313 obstack_grow (&buffer->obstack, start, n);
314 buffer->line_length += n;
317 /* Wrap a STRing into BUFFER. */
319 void
320 output_add_string (buffer, str)
321 output_buffer *buffer;
322 const char *str;
324 const char *p = str;
326 if (!output_is_line_wrapping (buffer))
327 output_append (buffer, str, str + strlen (str));
328 else while (*str)
330 while (*p && *p != ' ' && *p != '\n')
331 ++p;
333 if (p - str < output_space_left (buffer))
334 output_append (buffer, str, p);
335 else
337 output_add_newline (buffer);
338 output_append (buffer, str, p);
341 while (*p && *p == '\n')
343 output_add_newline (buffer);
344 ++p;
347 str = p++;
351 /* Flush the content of BUFFER onto FILE and reinitialize BUFFER. */
353 void
354 output_flush_on (buffer, file)
355 output_buffer *buffer;
356 FILE *file;
358 const char *text = output_finish (buffer);
359 fputs (text, file);
360 output_clear (buffer);
363 /* Format MESSAGE into BUFFER. */
364 void
365 output_format (buffer, msg)
366 output_buffer *buffer;
367 const char *msg;
369 for (buffer->cursor = msg; *buffer->cursor; ++buffer->cursor)
371 /* Ignore text. */
372 if (*buffer->cursor != '%')
374 output_add_character (buffer, *buffer->cursor);
375 continue;
378 /* We got a '%'. Let's see what happens. */
379 ++buffer->cursor;
381 /* Let's handle the traditional cases. */
382 if (*buffer->cursor == 's')
383 output_add_string (buffer, va_arg (buffer->format_args, const char *));
384 else if (*buffer->cursor == 'd')
385 output_add_integer (buffer, va_arg (buffer->format_args, int));
386 else if (*buffer->cursor == '%')
387 /* It was a '%%'. Just output a '%'. */
388 output_add_character (buffer, '%');
389 else if (lang_printer)
390 (*lang_printer) (buffer);
391 else
393 /* Hmmm. The front-end failed to install a format translator
394 but called us with an unrecognized format. Sorry. */
395 abort();
398 output_finish (buffer);
401 static char *
402 vbuild_message_string (msgid, ap)
403 const char *msgid;
404 va_list ap;
406 char *str;
408 vasprintf (&str, msgid, ap);
409 return str;
412 /* Return a malloc'd string containing MSGID formatted a la
413 printf. The caller is reponsible for freeing the memory. */
415 static char *
416 build_message_string VPARAMS ((const char *msgid, ...))
418 #ifndef ANSI_PROTOTYPES
419 const char *msgid;
420 #endif
421 va_list ap;
422 char *str;
424 VA_START (ap, msgid);
426 #ifndef ANSI_PROTOTYPES
427 msgid = va_arg (ap, const char *);
428 #endif
430 str = vbuild_message_string (msgid, ap);
432 va_end (ap);
434 return str;
438 /* Return a malloc'd string describing a location. The caller is
439 responsible for freeing the memory. */
441 static char *
442 build_location_prefix (file, line, warn)
443 const char *file;
444 int line;
445 int warn;
447 if (file)
449 if (warn)
450 return build_message_string ("%s:%d: warning: ", file, line);
451 else
452 return build_message_string ("%s:%d: ", file, line);
454 else
456 if (warn)
457 return build_message_string ("%s: warning: ", progname);
458 else
459 return build_message_string ("%s: ", progname);
463 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
465 static void
466 output_notice (buffer, msgid)
467 output_buffer *buffer;
468 const char *msgid;
470 char *message = vbuild_message_string (msgid, buffer->format_args);
472 output_add_string (buffer, message);
473 free (message);
477 /* Format a message into BUFFER a la printf. */
479 void
480 output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
482 #ifndef ANSI_PROTOTYPES
483 struct output_buffer *buffer;
484 const char *msgid;
485 #endif
486 va_list ap;
488 VA_START (ap, msgid);
490 #ifndef ANSI_PROTOTYPES
491 buffer = va_arg (ap, struct output_buffer *);
492 msgid = va_arg (ap, const char *);
493 #endif
495 va_copy (buffer->format_args, ap);
496 output_notice (buffer, msgid);
497 va_end (buffer->format_args);
501 /* Format a MESSAGE into FILE. Do line wrapping, starting new lines
502 with PREFIX. */
504 static void
505 line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...))
507 #ifndef ANSI_PROTOTYPES
508 FILE *file;
509 const char *msgid;
510 #endif
511 output_buffer buffer;
513 init_output_buffer (&buffer, NULL, output_maximum_width);
514 VA_START (buffer.format_args, msgid);
516 #ifndef ANSI_PROTOTYPES
517 file = va_arg (buffer.format_args, FILE *);
518 msgid = va_arg (buffer.format_args, const char *);
519 #endif
521 output_notice (&buffer, msgid);
522 output_flush_on (&buffer, file);
524 va_end (buffer.format_args);
528 static void
529 vline_wrapper_message_with_location (file, line, warn, msgid, ap)
530 const char *file;
531 int line;
532 int warn;
533 const char *msgid;
534 va_list ap;
536 output_buffer buffer;
538 init_output_buffer (&buffer, build_location_prefix (file, line, warn),
539 output_maximum_width);
540 va_copy (buffer.format_args, ap);
541 output_notice (&buffer, msgid);
542 output_flush_on (&buffer, stderr);
544 free (output_get_prefix (&buffer));
545 fputc ('\n', stderr);
549 /* Print the message MSGID in FILE. */
551 static void
552 vnotice (file, msgid, ap)
553 FILE *file;
554 const char *msgid;
555 va_list ap;
557 vfprintf (file, _(msgid), ap);
560 /* Print MSGID on stderr. */
562 static void
563 notice VPARAMS ((const char *msgid, ...))
565 #ifndef ANSI_PROTOTYPES
566 char *msgid;
567 #endif
568 va_list ap;
570 VA_START (ap, msgid);
572 #ifndef ANSI_PROTOTYPES
573 msgid = va_arg (ap, char *);
574 #endif
576 vnotice (stderr, msgid, ap);
577 va_end (ap);
580 /* Report FILE and LINE (or program name), and optionally just WARN. */
582 static void
583 report_file_and_line (file, line, warn)
584 const char *file;
585 int line;
586 int warn;
588 if (file)
589 fprintf (stderr, "%s:%d: ", file, line);
590 else
591 fprintf (stderr, "%s: ", progname);
593 if (warn)
594 notice ("warning: ");
597 /* Print a message relevant to line LINE of file FILE. */
599 static void
600 v_message_with_file_and_line (file, line, warn, msgid, ap)
601 const char *file;
602 int line;
603 int warn;
604 const char *msgid;
605 va_list ap;
607 report_file_and_line (file, line, warn);
608 vnotice (stderr, msgid, ap);
609 fputc ('\n', stderr);
612 /* Print a message relevant to the given DECL. */
614 static void
615 v_message_with_decl (decl, warn, msgid, ap)
616 tree decl;
617 int warn;
618 const char *msgid;
619 va_list ap;
621 const char *p;
622 output_buffer buffer;
624 if (doing_line_wrapping ())
626 init_output_buffer
627 (&buffer, build_location_prefix
628 (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn),
629 output_maximum_width);
631 else
632 report_file_and_line (DECL_SOURCE_FILE (decl),
633 DECL_SOURCE_LINE (decl), warn);
635 /* Do magic to get around lack of varargs support for insertion
636 of arguments into existing list. We know that the decl is first;
637 we ass_u_me that it will be printed with "%s". */
639 for (p = _(msgid); *p; ++p)
641 if (*p == '%')
643 if (*(p + 1) == '%')
644 ++p;
645 else if (*(p + 1) != 's')
646 abort ();
647 else
648 break;
652 if (p > _(msgid)) /* Print the left-hand substring. */
654 if (doing_line_wrapping ())
655 output_printf (&buffer, "%.*s", (int)(p - _(msgid)), _(msgid));
656 else
657 fprintf (stderr, "%.*s", (int)(p - _(msgid)), _(msgid));
660 if (*p == '%') /* Print the name. */
662 const char *n = (DECL_NAME (decl)
663 ? (*decl_printable_name) (decl, 2)
664 : "((anonymous))");
665 if (doing_line_wrapping ())
666 output_add_string (&buffer, n);
667 else
668 fputs (n, stderr);
669 while (*p)
671 ++p;
672 if (ISALPHA (*(p - 1) & 0xFF))
673 break;
677 if (*p) /* Print the rest of the message. */
679 if (doing_line_wrapping ())
681 va_copy (buffer.format_args, ap);
682 output_notice (&buffer, p);
683 va_copy (ap, buffer.format_args);
685 else
686 vfprintf (stderr, p, ap);
689 if (doing_line_wrapping())
691 output_flush_on (&buffer, stderr);
692 free (output_get_prefix (&buffer));
695 fputc ('\n', stderr);
698 /* Figure file and line of the given INSN. */
700 static void
701 file_and_line_for_asm (insn, pfile, pline)
702 rtx insn;
703 const char **pfile;
704 int *pline;
706 rtx body = PATTERN (insn);
707 rtx asmop;
709 /* Find the (or one of the) ASM_OPERANDS in the insn. */
710 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
711 asmop = SET_SRC (body);
712 else if (GET_CODE (body) == ASM_OPERANDS)
713 asmop = body;
714 else if (GET_CODE (body) == PARALLEL
715 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
716 asmop = SET_SRC (XVECEXP (body, 0, 0));
717 else if (GET_CODE (body) == PARALLEL
718 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
719 asmop = XVECEXP (body, 0, 0);
720 else
721 asmop = NULL;
723 if (asmop)
725 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
726 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
728 else
730 *pfile = input_filename;
731 *pline = lineno;
735 /* Report an error at line LINE of file FILE. */
737 static void
738 v_error_with_file_and_line (file, line, msgid, ap)
739 const char *file;
740 int line;
741 const char *msgid;
742 va_list ap;
744 count_error (0);
745 report_error_function (file);
746 if (doing_line_wrapping ())
747 vline_wrapper_message_with_location (file, line, 0, msgid, ap);
748 else
749 v_message_with_file_and_line (file, line, 0, msgid, ap);
752 /* Report an error at the declaration DECL.
753 MSGID is a format string which uses %s to substitute the declaration
754 name; subsequent substitutions are a la printf. */
756 static void
757 v_error_with_decl (decl, msgid, ap)
758 tree decl;
759 const char *msgid;
760 va_list ap;
762 count_error (0);
763 report_error_function (DECL_SOURCE_FILE (decl));
764 v_message_with_decl (decl, 0, msgid, ap);
768 /* Report an error at the line number of the insn INSN.
769 This is used only when INSN is an `asm' with operands,
770 and each ASM_OPERANDS records its own source file and line. */
772 static void
773 v_error_for_asm (insn, msgid, ap)
774 rtx insn;
775 const char *msgid;
776 va_list ap;
778 const char *file;
779 int line;
781 count_error (0);
782 file_and_line_for_asm (insn, &file, &line);
783 report_error_function (file);
784 v_message_with_file_and_line (file, line, 0, msgid, ap);
788 /* Report an error at the current line number. */
790 static void
791 verror (msgid, ap)
792 const char *msgid;
793 va_list ap;
795 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
799 /* Report a fatal error at the current line number. Allow a front end to
800 intercept the message. */
802 static void (*fatal_function) PARAMS ((const char *, va_list));
804 static void
805 vfatal (msgid, ap)
806 const char *msgid;
807 va_list ap;
809 if (fatal_function != 0)
810 (*fatal_function) (_(msgid), ap);
812 verror (msgid, ap);
813 exit (FATAL_EXIT_CODE);
816 /* Report a warning at line LINE of file FILE. */
818 static void
819 v_warning_with_file_and_line (file, line, msgid, ap)
820 const char *file;
821 int line;
822 const char *msgid;
823 va_list ap;
825 if (count_error (1))
827 report_error_function (file);
828 if (doing_line_wrapping ())
829 vline_wrapper_message_with_location (file, line, 1, msgid, ap);
830 else
831 v_message_with_file_and_line (file, line, 1, msgid, ap);
836 /* Report a warning at the declaration DECL.
837 MSGID is a format string which uses %s to substitute the declaration
838 name; subsequent substitutions are a la printf. */
840 static void
841 v_warning_with_decl (decl, msgid, ap)
842 tree decl;
843 const char *msgid;
844 va_list ap;
846 if (count_error (1))
848 report_error_function (DECL_SOURCE_FILE (decl));
849 v_message_with_decl (decl, 1, msgid, ap);
854 /* Report a warning at the line number of the insn INSN.
855 This is used only when INSN is an `asm' with operands,
856 and each ASM_OPERANDS records its own source file and line. */
858 static void
859 v_warning_for_asm (insn, msgid, ap)
860 rtx insn;
861 const char *msgid;
862 va_list ap;
864 if (count_error (1))
866 const char *file;
867 int line;
869 file_and_line_for_asm (insn, &file, &line);
870 report_error_function (file);
871 v_message_with_file_and_line (file, line, 1, msgid, ap);
876 /* Report a warning at the current line number. */
878 static void
879 vwarning (msgid, ap)
880 const char *msgid;
881 va_list ap;
883 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
886 /* These functions issue either warnings or errors depending on
887 -pedantic-errors. */
889 static void
890 vpedwarn (msgid, ap)
891 const char *msgid;
892 va_list ap;
894 if (flag_pedantic_errors)
895 verror (msgid, ap);
896 else
897 vwarning (msgid, ap);
901 static void
902 v_pedwarn_with_decl (decl, msgid, ap)
903 tree decl;
904 const char *msgid;
905 va_list ap;
907 /* We don't want -pedantic-errors to cause the compilation to fail from
908 "errors" in system header files. Sometimes fixincludes can't fix what's
909 broken (eg: unsigned char bitfields - fixing it may change the alignment
910 which will cause programs to mysteriously fail because the C library
911 or kernel uses the original layout). There's no point in issuing a
912 warning either, it's just unnecessary noise. */
914 if (! DECL_IN_SYSTEM_HEADER (decl))
916 if (flag_pedantic_errors)
917 v_error_with_decl (decl, msgid, ap);
918 else
919 v_warning_with_decl (decl, msgid, ap);
924 static void
925 v_pedwarn_with_file_and_line (file, line, msgid, ap)
926 const char *file;
927 int line;
928 const char *msgid;
929 va_list ap;
931 if (flag_pedantic_errors)
932 v_error_with_file_and_line (file, line, msgid, ap);
933 else
934 v_warning_with_file_and_line (file, line, msgid, ap);
938 /* Apologize for not implementing some feature. */
940 static void
941 vsorry (msgid, ap)
942 const char *msgid;
943 va_list ap;
945 sorrycount++;
946 if (input_filename)
947 fprintf (stderr, "%s:%d: ", input_filename, lineno);
948 else
949 fprintf (stderr, "%s: ", progname);
950 notice ("sorry, not implemented: ");
951 vnotice (stderr, msgid, ap);
952 fputc ('\n', stderr);
956 /* Count an error or warning. Return 1 if the message should be printed. */
959 count_error (warningp)
960 int warningp;
962 if (warningp && inhibit_warnings)
963 return 0;
965 if (warningp && !warnings_are_errors)
966 warningcount++;
967 else
969 static int warning_message = 0;
971 if (warningp && !warning_message)
973 notice ("%s: warnings being treated as errors\n", progname);
974 warning_message = 1;
976 errorcount++;
979 return 1;
982 /* Print a diagnistic MSGID on FILE. */
983 void
984 fnotice VPARAMS ((FILE *file, const char *msgid, ...))
986 #ifndef ANSI_PROTOTYPES
987 FILE *file;
988 const char *msgid;
989 #endif
990 va_list ap;
992 VA_START (ap, msgid);
994 #ifndef ANSI_PROTOTYPES
995 file = va_arg (ap, FILE *);
996 msgid = va_arg (ap, const char *);
997 #endif
999 vnotice (file, msgid, ap);
1000 va_end (ap);
1004 /* Print a fatal error message. NAME is the text.
1005 Also include a system error message based on `errno'. */
1007 void
1008 pfatal_with_name (name)
1009 const char *name;
1011 fprintf (stderr, "%s: ", progname);
1012 perror (name);
1013 exit (FATAL_EXIT_CODE);
1016 void
1017 fatal_io_error (name)
1018 const char *name;
1020 notice ("%s: %s: I/O error\n", progname, name);
1021 exit (FATAL_EXIT_CODE);
1024 /* Issue a pedantic warning MSGID. */
1025 void
1026 pedwarn VPARAMS ((const char *msgid, ...))
1028 #ifndef ANSI_PROTOTYPES
1029 const char *msgid;
1030 #endif
1031 va_list ap;
1033 VA_START (ap, msgid);
1035 #ifndef ANSI_PROTOTYPES
1036 msgid = va_arg (ap, const char *);
1037 #endif
1039 vpedwarn (msgid, ap);
1040 va_end (ap);
1043 /* Issue a pedantic waring about DECL. */
1044 void
1045 pedwarn_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1047 #ifndef ANSI_PROTOTYPES
1048 tree decl;
1049 const char *msgid;
1050 #endif
1051 va_list ap;
1053 VA_START (ap, msgid);
1055 #ifndef ANSI_PROTOTYPES
1056 decl = va_arg (ap, tree);
1057 msgid = va_arg (ap, const char *);
1058 #endif
1060 v_pedwarn_with_decl (decl, msgid, ap);
1061 va_end (ap);
1064 /* Same as above but within the context FILE and LINE. */
1065 void
1066 pedwarn_with_file_and_line VPARAMS ((const char *file, int line,
1067 const char *msgid, ...))
1069 #ifndef ANSI_PROTOTYPES
1070 const char *file;
1071 int line;
1072 const char *msgid;
1073 #endif
1074 va_list ap;
1076 VA_START (ap, msgid);
1078 #ifndef ANSI_PROTOTYPES
1079 file = va_arg (ap, const char *);
1080 line = va_arg (ap, int);
1081 msgid = va_arg (ap, const char *);
1082 #endif
1084 v_pedwarn_with_file_and_line (file, line, msgid, ap);
1085 va_end (ap);
1088 /* Just apologize with MSGID. */
1089 void
1090 sorry VPARAMS ((const char *msgid, ...))
1092 #ifndef ANSI_PROTOTYPES
1093 const char *msgid;
1094 #endif
1095 va_list ap;
1097 VA_START (ap, msgid);
1099 #ifndef ANSI_PROTOTYPES
1100 msgid = va_arg (ap, const char *);
1101 #endif
1103 vsorry (msgid, ap);
1104 va_end (ap);
1107 /* Called when the start of a function definition is parsed,
1108 this function prints on stderr the name of the function. */
1110 void
1111 announce_function (decl)
1112 tree decl;
1114 if (! quiet_flag)
1116 if (rtl_dump_and_exit)
1117 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1118 else
1120 if (doing_line_wrapping ())
1121 line_wrapper_printf
1122 (stderr, " %s", (*decl_printable_name) (decl, 2));
1123 else
1124 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1126 fflush (stderr);
1127 need_error_newline = 1;
1128 last_error_function = current_function_decl;
1132 /* The default function to print out name of current function that caused
1133 an error. */
1135 void
1136 default_print_error_function (file)
1137 const char *file;
1139 if (last_error_function != current_function_decl)
1141 char *prefix = NULL;
1142 output_buffer buffer;
1144 if (file)
1145 prefix = build_message_string ("%s: ", file);
1147 if (doing_line_wrapping ())
1148 init_output_buffer (&buffer, prefix, output_maximum_width);
1149 else
1151 if (file)
1152 fprintf (stderr, "%s: ", file);
1155 if (current_function_decl == NULL)
1157 if (doing_line_wrapping ())
1158 output_printf (&buffer, "At top level:\n");
1159 else
1160 notice ("At top level:\n");
1162 else
1164 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1166 if (doing_line_wrapping ())
1167 output_printf
1168 (&buffer, "In method `%s':\n",
1169 (*decl_printable_name) (current_function_decl, 2));
1170 else
1171 notice ("In method `%s':\n",
1172 (*decl_printable_name) (current_function_decl, 2));
1174 else
1176 if (doing_line_wrapping ())
1177 output_printf
1178 (&buffer, "In function `%s':\n",
1179 (*decl_printable_name) (current_function_decl, 2));
1180 else
1181 notice ("In function `%s':\n",
1182 (*decl_printable_name) (current_function_decl, 2));
1186 last_error_function = current_function_decl;
1188 if (doing_line_wrapping ())
1189 output_flush_on (&buffer, stderr);
1191 free ((char*) prefix);
1195 /* Prints out, if necessary, the name of the current function
1196 that caused an error. Called from all error and warning functions.
1197 We ignore the FILE parameter, as it cannot be relied upon. */
1199 void
1200 report_error_function (file)
1201 const char *file ATTRIBUTE_UNUSED;
1203 struct file_stack *p;
1205 if (need_error_newline)
1207 fprintf (stderr, "\n");
1208 need_error_newline = 0;
1211 if (input_file_stack && input_file_stack->next != 0
1212 && input_file_stack_tick != last_error_tick)
1214 for (p = input_file_stack->next; p; p = p->next)
1215 if (p == input_file_stack->next)
1216 notice ("In file included from %s:%d", p->name, p->line);
1217 else
1218 notice (",\n from %s:%d", p->name, p->line);
1219 fprintf (stderr, ":\n");
1220 last_error_tick = input_file_stack_tick;
1223 (*print_error_function) (input_filename);
1226 void
1227 error_with_file_and_line VPARAMS ((const char *file, int line,
1228 const char *msgid, ...))
1230 #ifndef ANSI_PROTOTYPES
1231 const char *file;
1232 int line;
1233 const char *msgid;
1234 #endif
1235 va_list ap;
1237 VA_START (ap, msgid);
1239 #ifndef ANSI_PROTOTYPES
1240 file = va_arg (ap, const char *);
1241 line = va_arg (ap, int);
1242 msgid = va_arg (ap, const char *);
1243 #endif
1245 v_error_with_file_and_line (file, line, msgid, ap);
1246 va_end (ap);
1249 void
1250 error_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1252 #ifndef ANSI_PROTOTYPES
1253 tree decl;
1254 const char *msgid;
1255 #endif
1256 va_list ap;
1258 VA_START (ap, msgid);
1260 #ifndef ANSI_PROTOTYPES
1261 decl = va_arg (ap, tree);
1262 msgid = va_arg (ap, const char *);
1263 #endif
1265 v_error_with_decl (decl, msgid, ap);
1266 va_end (ap);
1269 void
1270 error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1272 #ifndef ANSI_PROTOTYPES
1273 rtx insn;
1274 const char *msgid;
1275 #endif
1276 va_list ap;
1278 VA_START (ap, msgid);
1280 #ifndef ANSI_PROTOTYPES
1281 insn = va_arg (ap, rtx);
1282 msgid = va_arg (ap, const char *);
1283 #endif
1285 v_error_for_asm (insn, msgid, ap);
1286 va_end (ap);
1289 void
1290 error VPARAMS ((const char *msgid, ...))
1292 #ifndef ANSI_PROTOTYPES
1293 const char *msgid;
1294 #endif
1295 va_list ap;
1297 VA_START (ap, msgid);
1299 #ifndef ANSI_PROTOTYPES
1300 msgid = va_arg (ap, const char *);
1301 #endif
1303 verror (msgid, ap);
1304 va_end (ap);
1307 /* Set the function to call when a fatal error occurs. */
1309 void
1310 set_fatal_function (f)
1311 void (*f) PARAMS ((const char *, va_list));
1313 fatal_function = f;
1316 void
1317 fatal VPARAMS ((const char *msgid, ...))
1319 #ifndef ANSI_PROTOTYPES
1320 const char *msgid;
1321 #endif
1322 va_list ap;
1324 VA_START (ap, msgid);
1326 #ifndef ANSI_PROTOTYPES
1327 msgid = va_arg (ap, const char *);
1328 #endif
1330 vfatal (msgid, ap);
1331 va_end (ap);
1334 void
1335 _fatal_insn (msgid, insn, file, line, function)
1336 const char *msgid;
1337 rtx insn;
1338 const char *file;
1339 int line;
1340 const char *function;
1342 error ("%s", msgid);
1343 debug_rtx (insn);
1344 fancy_abort (file, line, function);
1347 void
1348 _fatal_insn_not_found (insn, file, line, function)
1349 rtx insn;
1350 const char *file;
1351 int line;
1352 const char *function;
1354 if (INSN_CODE (insn) < 0)
1355 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1356 else
1357 _fatal_insn ("Insn does not satisfy its constraints:",
1358 insn, file, line, function);
1361 void
1362 warning_with_file_and_line VPARAMS ((const char *file, int line,
1363 const char *msgid, ...))
1365 #ifndef ANSI_PROTOTYPES
1366 const char *file;
1367 int line;
1368 const char *msgid;
1369 #endif
1370 va_list ap;
1372 VA_START (ap, msgid);
1374 #ifndef ANSI_PROTOTYPES
1375 file = va_arg (ap, const char *);
1376 line = va_arg (ap, int);
1377 msgid = va_arg (ap, const char *);
1378 #endif
1380 v_warning_with_file_and_line (file, line, msgid, ap);
1381 va_end (ap);
1384 void
1385 warning_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1387 #ifndef ANSI_PROTOTYPES
1388 tree decl;
1389 const char *msgid;
1390 #endif
1391 va_list ap;
1393 VA_START (ap, msgid);
1395 #ifndef ANSI_PROTOTYPES
1396 decl = va_arg (ap, tree);
1397 msgid = va_arg (ap, const char *);
1398 #endif
1400 v_warning_with_decl (decl, msgid, ap);
1401 va_end (ap);
1404 void
1405 warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1407 #ifndef ANSI_PROTOTYPES
1408 rtx insn;
1409 const char *msgid;
1410 #endif
1411 va_list ap;
1413 VA_START (ap, msgid);
1415 #ifndef ANSI_PROTOTYPES
1416 insn = va_arg (ap, rtx);
1417 msgid = va_arg (ap, const char *);
1418 #endif
1420 v_warning_for_asm (insn, msgid, ap);
1421 va_end (ap);
1424 void
1425 warning VPARAMS ((const char *msgid, ...))
1427 #ifndef ANSI_PROTOTYPES
1428 const char *msgid;
1429 #endif
1430 va_list ap;
1432 VA_START (ap, msgid);
1434 #ifndef ANSI_PROTOTYPES
1435 msgid = va_arg (ap, const char *);
1436 #endif
1438 vwarning (msgid, ap);
1439 va_end (ap);