* haifa-sched.c (split_edges): Pass edgeset_size as second arg to
[official-gcc.git] / gcc / diagnostic.c
blob9d2eead4d120372c99e8e20efa02573c878e5990
1 /* Top level of GNU C compiler
2 Copyright (C) 1999 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 "obstack.h"
42 #define obstack_chunk_alloc xmalloc
43 #define obstack_chunk_free free
45 struct output_buffer
47 struct obstack obstack; /* where we build the text to output */
48 const char *prefix; /* prefix of every new line */
49 int line_length; /* current line length (in characters) */
50 int max_length; /* maximum characters per line */
53 /* Prototypes. */
54 static int doing_line_wrapping PROTO((void));
55 static void init_output_buffer PROTO((struct output_buffer*,
56 const char *, int));
57 static const char *get_output_prefix PROTO((const struct output_buffer *));
58 static int output_space_left PROTO((const struct output_buffer *));
59 static void emit_output_prefix PROTO((struct output_buffer *));
60 static void output_newline PROTO((struct output_buffer *));
61 static void output_append PROTO((struct output_buffer *, const char *,
62 const char *));
63 static void output_puts PROTO((struct output_buffer *, const char *));
64 static void dump_output PROTO((struct output_buffer *, FILE *));
65 static const char *vbuild_message_string PROTO((const char *, va_list));
66 static const char *build_message_string PVPROTO((const char *, ...));
67 static const char *build_location_prefix PROTO((const char *, int, int));
68 static void voutput_notice PROTO((struct output_buffer *, const char *,
69 va_list));
70 static void output_printf PVPROTO((struct output_buffer *, const char *, ...));
71 static void line_wrapper_printf PVPROTO((FILE *, const char *, ...));
72 static void vline_wrapper_message_with_location PROTO((const char *, int, int,
73 const char *, va_list));
74 static void notice PVPROTO((const char *s, ...)) ATTRIBUTE_PRINTF_1;
75 static void v_message_with_file_and_line PROTO((const char *, int, int,
76 const char *, va_list));
77 static void v_message_with_decl PROTO((tree, int, const char *, va_list));
78 static void file_and_line_for_asm PROTO((rtx, char **, int *));
79 static void v_error_with_file_and_line PROTO((const char *, int,
80 const char *, va_list));
81 static void v_error_with_decl PROTO((tree, const char *, va_list));
82 static void v_error_for_asm PROTO((rtx, const char *, va_list));
83 static void verror PROTO((const char *, va_list));
84 static void vfatal PROTO((const char *, va_list)) ATTRIBUTE_NORETURN;
85 static void v_warning_with_file_and_line PROTO ((const char *, int,
86 const char *, va_list));
87 static void v_warning_with_decl PROTO((tree, const char *, va_list));
88 static void v_warning_for_asm PROTO((rtx, const char *, va_list));
89 static void vwarning PROTO((const char *, va_list));
90 static void vpedwarn PROTO((const char *, va_list));
91 static void v_pedwarn_with_decl PROTO((tree, const char *, va_list));
92 static void v_pedwarn_with_file_and_line PROTO((const char *, int,
93 const char *, va_list));
94 static void vsorry PROTO((const char *, va_list));
95 static void report_file_and_line PROTO ((const char *, int, int));
96 static void vnotice PROTO ((FILE *, const char *, va_list));
99 extern int rtl_dump_and_exit;
100 extern int inhibit_warnings;
101 extern int warnings_are_errors;
102 extern int warningcount;
103 extern int errorcount;
105 static int need_error_newline;
107 /* Function of last error message;
108 more generally, function such that if next error message is in it
109 then we don't have to mention the function name. */
110 static tree last_error_function = NULL;
112 /* Used to detect when input_file_stack has changed since last described. */
113 static int last_error_tick;
115 /* Called by report_error_function to print out function name.
116 * Default may be overridden by language front-ends. */
118 void (*print_error_function) PROTO((const char *)) =
119 default_print_error_function;
121 /* Maximum characters per line in automatic line wrapping mode.
122 Non Zero means don't wrap lines. */
124 static int output_maximum_width = 0;
126 /* Predicate. Return 1 if we're in automatic line wrapping mode. */
128 static int
129 doing_line_wrapping ()
131 return output_maximum_width > 0;
134 /* Set Maximum characters per line in automatic line wrapping mode. */
136 void
137 set_message_length (n)
138 int n;
140 output_maximum_width = n;
143 /* Construct an output BUFFER with PREFIX and of MAX_LENGTH characters
144 per line. */
146 static void
147 init_output_buffer (buffer, prefix, max_length)
148 struct output_buffer *buffer;
149 const char *prefix;
150 int max_length;
152 obstack_init (&buffer->obstack);
153 buffer->prefix = prefix;
154 buffer->line_length = 0;
155 buffer->max_length = max_length;
158 /* Return BUFFER's prefix. */
160 static const char *
161 get_output_prefix (buffer)
162 const struct output_buffer *buffer;
164 return buffer->prefix;
167 /* Return the amount of characters BUFFER can accept to
168 make a full line. */
170 static int
171 output_space_left (buffer)
172 const struct output_buffer *buffer;
174 return buffer->max_length - buffer->line_length;
177 /* Dump BUFFER's prefix. */
179 static void
180 emit_output_prefix (buffer)
181 struct output_buffer *buffer;
183 if (buffer->prefix)
185 buffer->line_length = strlen (buffer->prefix);
186 obstack_grow (&buffer->obstack, buffer->prefix, buffer->line_length);
190 /* Have BUFFER start a new line. */
192 static void
193 output_newline (buffer)
194 struct output_buffer *buffer;
196 obstack_1grow (&buffer->obstack, '\n');
197 buffer->line_length = 0;
200 /* Append a string deliminated by START and END to BUFFER. No wrapping is
201 done. The caller must ensure that it is safe to do so. */
203 static void
204 output_append (buffer, start, end)
205 struct output_buffer *buffer;
206 const char *start;
207 const char *end;
209 int n;
211 /* Emit prefix and skip whitespace if we're starting a new line. */
212 if (buffer->line_length == 0)
214 emit_output_prefix (buffer);
215 while (start != end && *start == ' ')
216 ++start;
218 n = end - start;
219 obstack_grow (&buffer->obstack, start, n);
220 buffer->line_length += n;
223 /* Wrap a STRing into BUFFER. */
225 static void
226 output_puts (buffer, str)
227 struct output_buffer *buffer;
228 const char *str;
230 const char *p = str;
232 while (*str)
234 while (*p && *p != ' ' && *p != '\n')
235 ++p;
237 if (p - str < output_space_left (buffer))
238 output_append (buffer, str, p);
239 else
241 output_newline (buffer);
242 output_append (buffer, str, p);
245 while (*p && *p == '\n')
247 output_newline (buffer);
248 ++p;
251 str = p++;
255 /* Dump the content of BUFFER into FILE. */
257 static void
258 dump_output (buffer, file)
259 struct output_buffer *buffer;
260 FILE *file;
262 const char *text;
264 obstack_1grow (&buffer->obstack, '\0');
265 text = obstack_finish (&buffer->obstack);
266 fputs (text, file);
267 obstack_free (&buffer->obstack, (char *)text);
268 buffer->line_length = 0;
271 static const char *
272 vbuild_message_string (msgid, ap)
273 const char *msgid;
274 va_list ap;
276 char *str;
278 vasprintf (&str, msgid, ap);
279 return str;
282 /* Return a malloc'd string containing MSGID formatted a la
283 printf. The caller is reponsible for freeing the memory. */
285 static const char *
286 build_message_string VPROTO((const char *msgid, ...))
288 #ifndef ANSI_PROTOTYPES
289 const char *msgid;
290 #endif
291 va_list ap;
292 const char *str;
294 VA_START (ap, msgid);
296 #ifndef ANSI_PROTOTYPES
297 msgid = va_arg (ap, const char *);
298 #endif
300 str = vbuild_message_string (msgid, ap);
302 va_end (ap);
304 return str;
308 /* Return a malloc'd string describing a location. The caller is
309 responsible for freeing the memory. */
311 static const char *
312 build_location_prefix (file, line, warn)
313 const char *file;
314 int line;
315 int warn;
317 const char *fmt = file
318 ? (warn ? "%s:%d: warning: " : "%s:%d: ")
319 : (warn ? "%s: warning: " : "%s: ");
321 return file
322 ? build_message_string (fmt, file, line)
323 : build_message_string (fmt, progname);
326 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
328 static void
329 voutput_notice (buffer, msgid, ap)
330 struct output_buffer *buffer;
331 const char *msgid;
332 va_list ap;
334 const char *message = vbuild_message_string (msgid, ap);
336 output_puts (buffer, message);
337 free ((char *)message);
341 /* Format a message into BUFFER a la printf. */
343 static void
344 output_printf VPROTO((struct output_buffer *buffer, const char *msgid, ...))
346 #ifndef ANSI_PROTOTYPES
347 struct output_buffer *buffer;
348 const char *msgid;
349 #endif
350 va_list ap;
352 VA_START (ap, msgid);
354 #ifndef ANSI_PROTOTYPES
355 buffer = va_arg (ap, struct output_buffer *);
356 msgid = va_arg (ap, const char *);
357 #endif
359 voutput_notice (buffer, msgid, ap);
360 va_end (ap);
364 /* Format a MESSAGE into FILE. Do line wrapping, starting new lines
365 with PREFIX. */
367 static void
368 line_wrapper_printf VPROTO((FILE *file, const char *msgid, ...))
370 #ifndef ANSI_PROTOTYPES
371 FILE *file;
372 const char *msgid;
373 #endif
374 struct output_buffer buffer;
375 va_list ap;
377 VA_START (ap, msgid);
379 #ifndef ANSI_PROTOTYPES
380 file = va_arg (ap, FILE *);
381 msgid = va_arg (ap, const char *);
382 #endif
384 init_output_buffer (&buffer, (const char *)NULL, output_maximum_width);
385 voutput_notice (&buffer, msgid, ap);
386 dump_output (&buffer, file);
388 va_end (ap);
392 static void
393 vline_wrapper_message_with_location (file, line, warn, msgid, ap)
394 const char *file;
395 int line;
396 int warn;
397 const char *msgid;
398 va_list ap;
400 struct output_buffer buffer;
402 init_output_buffer
403 (&buffer, build_location_prefix (file, line, warn), output_maximum_width);
404 voutput_notice (&buffer, msgid, ap);
405 dump_output (&buffer, stderr);
406 free ((char*)get_output_prefix (&buffer));
407 fputc ('\n', stderr);
411 /* Print the message MSGID in FILE. */
413 static void
414 vnotice (file, msgid, ap)
415 FILE *file;
416 const char *msgid;
417 va_list ap;
419 vfprintf (file, _(msgid), ap);
422 /* Print MSGID on stderr. */
424 static void
425 notice VPROTO((const char *msgid, ...))
427 #ifndef ANSI_PROTOTYPES
428 char *msgid;
429 #endif
430 va_list ap;
432 VA_START (ap, msgid);
434 #ifndef ANSI_PROTOTYPES
435 msgid = va_arg (ap, char *);
436 #endif
438 vnotice (stderr, msgid, ap);
439 va_end (ap);
442 /* Report FILE and LINE (or program name), and optionally just WARN. */
444 static void
445 report_file_and_line (file, line, warn)
446 const char *file;
447 int line;
448 int warn;
450 if (file)
451 fprintf (stderr, "%s:%d: ", file, line);
452 else
453 fprintf (stderr, "%s: ", progname);
455 if (warn)
456 notice ("warning: ");
459 /* Print a message relevant to line LINE of file FILE. */
461 static void
462 v_message_with_file_and_line (file, line, warn, msgid, ap)
463 const char *file;
464 int line;
465 int warn;
466 const char *msgid;
467 va_list ap;
469 report_file_and_line (file, line, warn);
470 vnotice (stderr, msgid, ap);
471 fputc ('\n', stderr);
474 /* Print a message relevant to the given DECL. */
476 static void
477 v_message_with_decl (decl, warn, msgid, ap)
478 tree decl;
479 int warn;
480 const char *msgid;
481 va_list ap;
483 const char *p;
484 struct output_buffer buffer;
486 if (doing_line_wrapping ())
487 init_output_buffer
488 (&buffer,
489 build_location_prefix (DECL_SOURCE_FILE (decl),
490 DECL_SOURCE_LINE (decl), warn),
491 output_maximum_width);
492 else
493 report_file_and_line (DECL_SOURCE_FILE (decl),
494 DECL_SOURCE_LINE (decl), warn);
496 /* Do magic to get around lack of varargs support for insertion
497 of arguments into existing list. We know that the decl is first;
498 we ass_u_me that it will be printed with "%s". */
500 for (p = _(msgid); *p; ++p)
502 if (*p == '%')
504 if (*(p + 1) == '%')
505 ++p;
506 else if (*(p + 1) != 's')
507 abort ();
508 else
509 break;
513 if (p > _(msgid)) /* Print the left-hand substring. */
515 if (doing_line_wrapping ())
516 output_printf (&buffer, "%.*s", (int)(p - _(msgid)), _(msgid));
517 else
518 fprintf (stderr, "%.*s", (int)(p - _(msgid)), _(msgid));
521 if (*p == '%') /* Print the name. */
523 const char *n = (DECL_NAME (decl)
524 ? (*decl_printable_name) (decl, 2)
525 : "((anonymous))");
526 if (doing_line_wrapping ())
527 output_puts (&buffer, n);
528 else
529 fputs (n, stderr);
530 while (*p)
532 ++p;
533 if (ISALPHA (*(p - 1) & 0xFF))
534 break;
538 if (*p) /* Print the rest of the message. */
540 if (doing_line_wrapping ())
541 voutput_notice (&buffer, p, ap);
542 else
543 vfprintf (stderr, p, ap);
546 if (doing_line_wrapping())
548 dump_output (&buffer, stderr);
549 free ((char *)get_output_prefix (&buffer));
552 fputc ('\n', stderr);
555 /* Figure file and line of the given INSN. */
557 static void
558 file_and_line_for_asm (insn, pfile, pline)
559 rtx insn;
560 char **pfile;
561 int *pline;
563 rtx body = PATTERN (insn);
564 rtx asmop;
566 /* Find the (or one of the) ASM_OPERANDS in the insn. */
567 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
568 asmop = SET_SRC (body);
569 else if (GET_CODE (body) == ASM_OPERANDS)
570 asmop = body;
571 else if (GET_CODE (body) == PARALLEL
572 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
573 asmop = SET_SRC (XVECEXP (body, 0, 0));
574 else if (GET_CODE (body) == PARALLEL
575 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
576 asmop = XVECEXP (body, 0, 0);
577 else
578 asmop = NULL;
580 if (asmop)
582 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
583 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
585 else
587 *pfile = input_filename;
588 *pline = lineno;
592 /* Report an error at line LINE of file FILE. */
594 static void
595 v_error_with_file_and_line (file, line, msgid, ap)
596 const char *file;
597 int line;
598 const char *msgid;
599 va_list ap;
601 count_error (0);
602 report_error_function (file);
603 if (doing_line_wrapping ())
604 vline_wrapper_message_with_location (file, line, 0, msgid, ap);
605 else
606 v_message_with_file_and_line (file, line, 0, msgid, ap);
609 /* Report an error at the declaration DECL.
610 MSGID is a format string which uses %s to substitute the declaration
611 name; subsequent substitutions are a la printf. */
613 static void
614 v_error_with_decl (decl, msgid, ap)
615 tree decl;
616 const char *msgid;
617 va_list ap;
619 count_error (0);
620 report_error_function (DECL_SOURCE_FILE (decl));
621 v_message_with_decl (decl, 0, msgid, ap);
625 /* Report an error at the line number of the insn INSN.
626 This is used only when INSN is an `asm' with operands,
627 and each ASM_OPERANDS records its own source file and line. */
629 static void
630 v_error_for_asm (insn, msgid, ap)
631 rtx insn;
632 const char *msgid;
633 va_list ap;
635 char *file;
636 int line;
638 count_error (0);
639 file_and_line_for_asm (insn, &file, &line);
640 report_error_function (file);
641 v_message_with_file_and_line (file, line, 0, msgid, ap);
645 /* Report an error at the current line number. */
647 static void
648 verror (msgid, ap)
649 const char *msgid;
650 va_list ap;
652 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
656 /* Report a fatal error at the current line number. Allow a front end to
657 intercept the message. */
659 static void (*fatal_function) PROTO ((const char *, va_list));
661 static void
662 vfatal (msgid, ap)
663 const char *msgid;
664 va_list ap;
666 if (fatal_function != 0)
667 (*fatal_function) (_(msgid), ap);
669 verror (msgid, ap);
670 exit (FATAL_EXIT_CODE);
673 /* Report a warning at line LINE of file FILE. */
675 static void
676 v_warning_with_file_and_line (file, line, msgid, ap)
677 const char *file;
678 int line;
679 const char *msgid;
680 va_list ap;
682 if (count_error (1))
684 report_error_function (file);
685 if (doing_line_wrapping ())
686 vline_wrapper_message_with_location (file, line, 1, msgid, ap);
687 else
688 v_message_with_file_and_line (file, line, 1, msgid, ap);
693 /* Report a warning at the declaration DECL.
694 MSGID is a format string which uses %s to substitute the declaration
695 name; subsequent substitutions are a la printf. */
697 static void
698 v_warning_with_decl (decl, msgid, ap)
699 tree decl;
700 const char *msgid;
701 va_list ap;
703 if (count_error (1))
705 report_error_function (DECL_SOURCE_FILE (decl));
706 v_message_with_decl (decl, 1, msgid, ap);
711 /* Report a warning at the line number of the insn INSN.
712 This is used only when INSN is an `asm' with operands,
713 and each ASM_OPERANDS records its own source file and line. */
715 static void
716 v_warning_for_asm (insn, msgid, ap)
717 rtx insn;
718 const char *msgid;
719 va_list ap;
721 if (count_error (1))
723 char *file;
724 int line;
726 file_and_line_for_asm (insn, &file, &line);
727 report_error_function (file);
728 v_message_with_file_and_line (file, line, 1, msgid, ap);
733 /* Report a warning at the current line number. */
735 static void
736 vwarning (msgid, ap)
737 const char *msgid;
738 va_list ap;
740 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
743 /* These functions issue either warnings or errors depending on
744 -pedantic-errors. */
746 static void
747 vpedwarn (msgid, ap)
748 const char *msgid;
749 va_list ap;
751 if (flag_pedantic_errors)
752 verror (msgid, ap);
753 else
754 vwarning (msgid, ap);
758 static void
759 v_pedwarn_with_decl (decl, msgid, ap)
760 tree decl;
761 const char *msgid;
762 va_list ap;
764 /* We don't want -pedantic-errors to cause the compilation to fail from
765 "errors" in system header files. Sometimes fixincludes can't fix what's
766 broken (eg: unsigned char bitfields - fixing it may change the alignment
767 which will cause programs to mysteriously fail because the C library
768 or kernel uses the original layout). There's no point in issuing a
769 warning either, it's just unnecessary noise. */
771 if (! DECL_IN_SYSTEM_HEADER (decl))
773 if (flag_pedantic_errors)
774 v_error_with_decl (decl, msgid, ap);
775 else
776 v_warning_with_decl (decl, msgid, ap);
781 static void
782 v_pedwarn_with_file_and_line (file, line, msgid, ap)
783 const char *file;
784 int line;
785 const char *msgid;
786 va_list ap;
788 if (flag_pedantic_errors)
789 v_error_with_file_and_line (file, line, msgid, ap);
790 else
791 v_warning_with_file_and_line (file, line, msgid, ap);
795 /* Apologize for not implementing some feature. */
797 static void
798 vsorry (msgid, ap)
799 const char *msgid;
800 va_list ap;
802 sorrycount++;
803 if (input_filename)
804 fprintf (stderr, "%s:%d: ", input_filename, lineno);
805 else
806 fprintf (stderr, "%s: ", progname);
807 notice ("sorry, not implemented: ");
808 vnotice (stderr, msgid, ap);
809 fputc ('\n', stderr);
813 /* Count an error or warning. Return 1 if the message should be printed. */
816 count_error (warningp)
817 int warningp;
819 if (warningp && inhibit_warnings)
820 return 0;
822 if (warningp && !warnings_are_errors)
823 warningcount++;
824 else
826 static int warning_message = 0;
828 if (warningp && !warning_message)
830 notice ("%s: warnings being treated as errors\n", progname);
831 warning_message = 1;
833 errorcount++;
836 return 1;
839 /* Print a diagnistic MSGID on FILE. */
840 void
841 fnotice VPROTO((FILE *file, const char *msgid, ...))
843 #ifndef ANSI_PROTOTYPES
844 FILE *file;
845 const char *msgid;
846 #endif
847 va_list ap;
849 VA_START (ap, msgid);
851 #ifndef ANSI_PROTOTYPES
852 file = va_arg (ap, FILE *);
853 msgid = va_arg (ap, const char *);
854 #endif
856 vnotice (file, msgid, ap);
857 va_end (ap);
861 /* Print a fatal error message. NAME is the text.
862 Also include a system error message based on `errno'. */
864 void
865 pfatal_with_name (name)
866 const char *name;
868 fprintf (stderr, "%s: ", progname);
869 perror (name);
870 exit (FATAL_EXIT_CODE);
873 void
874 fatal_io_error (name)
875 const char *name;
877 notice ("%s: %s: I/O error\n", progname, name);
878 exit (FATAL_EXIT_CODE);
881 /* Issue a pedantic warning MSGID. */
882 void
883 pedwarn VPROTO((const char *msgid, ...))
885 #ifndef ANSI_PROTOTYPES
886 const char *msgid;
887 #endif
888 va_list ap;
890 VA_START (ap, msgid);
892 #ifndef ANSI_PROTOTYPES
893 msgid = va_arg (ap, const char *);
894 #endif
896 vpedwarn (msgid, ap);
897 va_end (ap);
900 /* Issue a pedantic waring about DECL. */
901 void
902 pedwarn_with_decl VPROTO((tree decl, const char *msgid, ...))
904 #ifndef ANSI_PROTOTYPES
905 tree decl;
906 const char *msgid;
907 #endif
908 va_list ap;
910 VA_START (ap, msgid);
912 #ifndef ANSI_PROTOTYPES
913 decl = va_arg (ap, tree);
914 msgid = va_arg (ap, const char *);
915 #endif
917 v_pedwarn_with_decl (decl, msgid, ap);
918 va_end (ap);
921 /* Same as above but within the context FILE and LINE. */
922 void
923 pedwarn_with_file_and_line VPROTO((const char *file, int line,
924 const char *msgid, ...))
926 #ifndef ANSI_PROTOTYPES
927 const char *file;
928 int line;
929 const char *msgid;
930 #endif
931 va_list ap;
933 VA_START (ap, msgid);
935 #ifndef ANSI_PROTOTYPES
936 file = va_arg (ap, const char *);
937 line = va_arg (ap, int);
938 msgid = va_arg (ap, const char *);
939 #endif
941 v_pedwarn_with_file_and_line (file, line, msgid, ap);
942 va_end (ap);
945 /* Just apologize with MSGID. */
946 void
947 sorry VPROTO((const char *msgid, ...))
949 #ifndef ANSI_PROTOTYPES
950 const char *msgid;
951 #endif
952 va_list ap;
954 VA_START (ap, msgid);
956 #ifndef ANSI_PROTOTYPES
957 msgid = va_arg (ap, const char *);
958 #endif
960 vsorry (msgid, ap);
961 va_end (ap);
964 /* Called when the start of a function definition is parsed,
965 this function prints on stderr the name of the function. */
967 void
968 announce_function (decl)
969 tree decl;
971 if (! quiet_flag)
973 if (rtl_dump_and_exit)
974 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
975 else
977 if (doing_line_wrapping ())
978 line_wrapper_printf
979 (stderr, " %s", (*decl_printable_name) (decl, 2));
980 else
981 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
983 fflush (stderr);
984 need_error_newline = 1;
985 last_error_function = current_function_decl;
989 /* The default function to print out name of current function that caused
990 an error. */
992 void
993 default_print_error_function (file)
994 const char *file;
996 if (last_error_function != current_function_decl)
998 const char *prefix = NULL;
999 struct output_buffer buffer;
1001 if (file)
1002 prefix = build_message_string ("%s: ", file);
1004 if (doing_line_wrapping ())
1005 init_output_buffer (&buffer, prefix, output_maximum_width);
1006 else
1008 if (file)
1009 fprintf (stderr, "%s: ", file);
1012 if (current_function_decl == NULL)
1014 if (doing_line_wrapping ())
1015 output_printf (&buffer, "At top level:\n");
1016 else
1017 notice ("At top level:\n");
1019 else
1021 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1023 if (doing_line_wrapping ())
1024 output_printf
1025 (&buffer, "In method `%s':\n",
1026 (*decl_printable_name) (current_function_decl, 2));
1027 else
1028 notice ("In method `%s':\n",
1029 (*decl_printable_name) (current_function_decl, 2));
1031 else
1033 if (doing_line_wrapping ())
1034 output_printf
1035 (&buffer, "In function `%s':\n",
1036 (*decl_printable_name) (current_function_decl, 2));
1037 else
1038 notice ("In function `%s':\n",
1039 (*decl_printable_name) (current_function_decl, 2));
1043 last_error_function = current_function_decl;
1045 if (doing_line_wrapping ())
1046 dump_output (&buffer, stderr);
1048 free ((char *)prefix);
1052 /* Prints out, if necessary, the name of the current function
1053 that caused an error. Called from all error and warning functions.
1054 We ignore the FILE parameter, as it cannot be relied upon. */
1056 void
1057 report_error_function (file)
1058 const char *file ATTRIBUTE_UNUSED;
1060 struct file_stack *p;
1062 if (need_error_newline)
1064 fprintf (stderr, "\n");
1065 need_error_newline = 0;
1068 if (input_file_stack && input_file_stack->next != 0
1069 && input_file_stack_tick != last_error_tick)
1071 for (p = input_file_stack->next; p; p = p->next)
1072 if (p == input_file_stack->next)
1073 notice ("In file included from %s:%d", p->name, p->line);
1074 else
1075 notice (",\n from %s:%d", p->name, p->line);
1076 fprintf (stderr, ":\n");
1077 last_error_tick = input_file_stack_tick;
1080 (*print_error_function) (input_filename);
1083 void
1084 error_with_file_and_line VPROTO((const char *file, int line,
1085 const char *msgid, ...))
1087 #ifndef ANSI_PROTOTYPES
1088 const char *file;
1089 int line;
1090 const char *msgid;
1091 #endif
1092 va_list ap;
1094 VA_START (ap, msgid);
1096 #ifndef ANSI_PROTOTYPES
1097 file = va_arg (ap, const char *);
1098 line = va_arg (ap, int);
1099 msgid = va_arg (ap, const char *);
1100 #endif
1102 v_error_with_file_and_line (file, line, msgid, ap);
1103 va_end (ap);
1106 void
1107 error_with_decl VPROTO((tree decl, const char *msgid, ...))
1109 #ifndef ANSI_PROTOTYPES
1110 tree decl;
1111 const char *msgid;
1112 #endif
1113 va_list ap;
1115 VA_START (ap, msgid);
1117 #ifndef ANSI_PROTOTYPES
1118 decl = va_arg (ap, tree);
1119 msgid = va_arg (ap, const char *);
1120 #endif
1122 v_error_with_decl (decl, msgid, ap);
1123 va_end (ap);
1126 void
1127 error_for_asm VPROTO((rtx insn, const char *msgid, ...))
1129 #ifndef ANSI_PROTOTYPES
1130 rtx insn;
1131 const char *msgid;
1132 #endif
1133 va_list ap;
1135 VA_START (ap, msgid);
1137 #ifndef ANSI_PROTOTYPES
1138 insn = va_arg (ap, rtx);
1139 msgid = va_arg (ap, const char *);
1140 #endif
1142 v_error_for_asm (insn, msgid, ap);
1143 va_end (ap);
1146 void
1147 error VPROTO((const char *msgid, ...))
1149 #ifndef ANSI_PROTOTYPES
1150 const char *msgid;
1151 #endif
1152 va_list ap;
1154 VA_START (ap, msgid);
1156 #ifndef ANSI_PROTOTYPES
1157 msgid = va_arg (ap, const char *);
1158 #endif
1160 verror (msgid, ap);
1161 va_end (ap);
1164 /* Set the function to call when a fatal error occurs. */
1166 void
1167 set_fatal_function (f)
1168 void (*f) PROTO ((const char *, va_list));
1170 fatal_function = f;
1173 void
1174 fatal VPROTO((const char *msgid, ...))
1176 #ifndef ANSI_PROTOTYPES
1177 const char *msgid;
1178 #endif
1179 va_list ap;
1181 VA_START (ap, msgid);
1183 #ifndef ANSI_PROTOTYPES
1184 msgid = va_arg (ap, const char *);
1185 #endif
1187 vfatal (msgid, ap);
1188 va_end (ap);
1191 void
1192 _fatal_insn (msgid, insn, file, line, function)
1193 const char *msgid;
1194 rtx insn;
1195 const char *file;
1196 int line;
1197 const char *function;
1199 error ("%s", msgid);
1200 debug_rtx (insn);
1201 fancy_abort (file, line, function);
1204 void
1205 _fatal_insn_not_found (insn, file, line, function)
1206 rtx insn;
1207 const char *file;
1208 int line;
1209 const char *function;
1211 if (INSN_CODE (insn) < 0)
1212 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1213 else
1214 _fatal_insn ("Insn does not satisfy its constraints:",
1215 insn, file, line, function);
1218 void
1219 warning_with_file_and_line VPROTO((const char *file, int line,
1220 const char *msgid, ...))
1222 #ifndef ANSI_PROTOTYPES
1223 const char *file;
1224 int line;
1225 const char *msgid;
1226 #endif
1227 va_list ap;
1229 VA_START (ap, msgid);
1231 #ifndef ANSI_PROTOTYPES
1232 file = va_arg (ap, const char *);
1233 line = va_arg (ap, int);
1234 msgid = va_arg (ap, const char *);
1235 #endif
1237 v_warning_with_file_and_line (file, line, msgid, ap);
1238 va_end (ap);
1241 void
1242 warning_with_decl VPROTO((tree decl, const char *msgid, ...))
1244 #ifndef ANSI_PROTOTYPES
1245 tree decl;
1246 const char *msgid;
1247 #endif
1248 va_list ap;
1250 VA_START (ap, msgid);
1252 #ifndef ANSI_PROTOTYPES
1253 decl = va_arg (ap, tree);
1254 msgid = va_arg (ap, const char *);
1255 #endif
1257 v_warning_with_decl (decl, msgid, ap);
1258 va_end (ap);
1261 void
1262 warning_for_asm VPROTO((rtx insn, const char *msgid, ...))
1264 #ifndef ANSI_PROTOTYPES
1265 rtx insn;
1266 const char *msgid;
1267 #endif
1268 va_list ap;
1270 VA_START (ap, msgid);
1272 #ifndef ANSI_PROTOTYPES
1273 insn = va_arg (ap, rtx);
1274 msgid = va_arg (ap, const char *);
1275 #endif
1277 v_warning_for_asm (insn, msgid, ap);
1278 va_end (ap);
1281 void
1282 warning VPROTO((const char *msgid, ...))
1284 #ifndef ANSI_PROTOTYPES
1285 const char *msgid;
1286 #endif
1287 va_list ap;
1289 VA_START (ap, msgid);
1291 #ifndef ANSI_PROTOTYPES
1292 msgid = va_arg (ap, const char *);
1293 #endif
1295 vwarning (msgid, ap);
1296 va_end (ap);