* cppexp.c (parse_charconst): Null does not end character
[official-gcc.git] / gcc / diagnostic.c
blob1b404625f7b1d9c32687f8262bca378484283260
1 /* Top level of 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 "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 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 PARAMS ((void));
55 static void init_output_buffer PARAMS ((struct output_buffer*, char *, int));
56 static char *get_output_prefix PARAMS ((const struct output_buffer *));
57 static int output_space_left PARAMS ((const struct output_buffer *));
58 static void emit_output_prefix PARAMS ((struct output_buffer *));
59 static void output_newline PARAMS ((struct output_buffer *));
60 static void output_append PARAMS ((struct output_buffer *, const char *,
61 const char *));
62 static void output_puts PARAMS ((struct output_buffer *, const char *));
63 static void dump_output PARAMS ((struct output_buffer *, FILE *));
64 static char *vbuild_message_string PARAMS ((const char *, va_list));
65 static char *build_message_string PARAMS ((const char *, ...))
66 ATTRIBUTE_PRINTF_1;
67 static char *build_location_prefix PARAMS ((const char *, int, int));
68 static void voutput_notice PARAMS ((struct output_buffer *, const char *,
69 va_list));
70 static void output_printf PARAMS ((struct output_buffer *, const char *, ...))
71 ATTRIBUTE_PRINTF_2;
72 static void line_wrapper_printf PARAMS ((FILE *, const char *, ...))
73 ATTRIBUTE_PRINTF_2;
74 static void vline_wrapper_message_with_location PARAMS ((const char *, int,
75 int, const char *,
76 va_list));
77 static void notice PARAMS ((const char *s, ...)) ATTRIBUTE_PRINTF_1;
78 static void v_message_with_file_and_line PARAMS ((const char *, int, int,
79 const char *, va_list));
80 static void v_message_with_decl PARAMS ((tree, int, const char *, va_list));
81 static void file_and_line_for_asm PARAMS ((rtx, const char **, int *));
82 static void v_error_with_file_and_line PARAMS ((const char *, int,
83 const char *, va_list));
84 static void v_error_with_decl PARAMS ((tree, const char *, va_list));
85 static void v_error_for_asm PARAMS ((rtx, const char *, va_list));
86 static void verror PARAMS ((const char *, va_list));
87 static void vfatal PARAMS ((const char *, va_list)) ATTRIBUTE_NORETURN;
88 static void v_warning_with_file_and_line PARAMS ((const char *, int,
89 const char *, va_list));
90 static void v_warning_with_decl PARAMS ((tree, const char *, va_list));
91 static void v_warning_for_asm PARAMS ((rtx, const char *, va_list));
92 static void vwarning PARAMS ((const char *, va_list));
93 static void vpedwarn PARAMS ((const char *, va_list));
94 static void v_pedwarn_with_decl PARAMS ((tree, const char *, va_list));
95 static void v_pedwarn_with_file_and_line PARAMS ((const char *, int,
96 const char *, va_list));
97 static void vsorry PARAMS ((const char *, va_list));
98 static void report_file_and_line PARAMS ((const char *, int, int));
99 static void vnotice PARAMS ((FILE *, const char *, va_list));
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 static int need_error_newline;
110 /* Function of last error message;
111 more generally, function such that if next error message is in it
112 then we don't have to mention the function name. */
113 static tree last_error_function = NULL;
115 /* Used to detect when input_file_stack has changed since last described. */
116 static int last_error_tick;
118 /* Called by report_error_function to print out function name.
119 * Default may be overridden by language front-ends. */
121 void (*print_error_function) PARAMS ((const char *)) =
122 default_print_error_function;
124 /* Maximum characters per line in automatic line wrapping mode.
125 Zero means don't wrap lines. */
127 static int output_maximum_width = 0;
129 /* Predicate. Return 1 if we're in automatic line wrapping mode. */
131 static int
132 doing_line_wrapping ()
134 return output_maximum_width > 0;
137 /* Set Maximum characters per line in automatic line wrapping mode. */
139 void
140 set_message_length (n)
141 int n;
143 output_maximum_width = n;
146 /* Construct an output BUFFER with PREFIX and of MAX_LENGTH characters
147 per line. */
149 static void
150 init_output_buffer (buffer, prefix, max_length)
151 struct output_buffer *buffer;
152 char *prefix;
153 int max_length;
155 int prefix_length = prefix == 0 ? 0 : strlen (prefix);
157 obstack_init (&buffer->obstack);
158 buffer->prefix = prefix;
159 buffer->line_length = 0;
160 /* If the prefix is ridiculously too long, output at least
161 32 characters. */
162 if (max_length - prefix_length < 32)
163 buffer->max_length = max_length + 32;
164 else
165 buffer->max_length = max_length;
168 /* Return BUFFER's prefix. */
170 static char *
171 get_output_prefix (buffer)
172 const struct output_buffer *buffer;
174 return buffer->prefix;
177 /* Return the amount of characters BUFFER can accept to
178 make a full line. */
180 static int
181 output_space_left (buffer)
182 const struct output_buffer *buffer;
184 return buffer->max_length - buffer->line_length;
187 /* Dump BUFFER's prefix. */
189 static void
190 emit_output_prefix (buffer)
191 struct output_buffer *buffer;
193 if (buffer->prefix)
195 buffer->line_length = strlen (buffer->prefix);
196 obstack_grow (&buffer->obstack, buffer->prefix, buffer->line_length);
200 /* Have BUFFER start a new line. */
202 static void
203 output_newline (buffer)
204 struct output_buffer *buffer;
206 obstack_1grow (&buffer->obstack, '\n');
207 buffer->line_length = 0;
210 /* Append a string deliminated by START and END to BUFFER. No wrapping is
211 done. The caller must ensure that it is safe to do so. */
213 static void
214 output_append (buffer, start, end)
215 struct output_buffer *buffer;
216 const char *start;
217 const char *end;
219 int n;
221 /* Emit prefix and skip whitespace if we're starting a new line. */
222 if (buffer->line_length == 0)
224 emit_output_prefix (buffer);
225 while (start != end && *start == ' ')
226 ++start;
228 n = end - start;
229 obstack_grow (&buffer->obstack, start, n);
230 buffer->line_length += n;
233 /* Wrap a STRing into BUFFER. */
235 static void
236 output_puts (buffer, str)
237 struct output_buffer *buffer;
238 const char *str;
240 const char *p = str;
242 while (*str)
244 while (*p && *p != ' ' && *p != '\n')
245 ++p;
247 if (p - str < output_space_left (buffer))
248 output_append (buffer, str, p);
249 else
251 output_newline (buffer);
252 output_append (buffer, str, p);
255 while (*p && *p == '\n')
257 output_newline (buffer);
258 ++p;
261 str = p++;
265 /* Dump the content of BUFFER into FILE. */
267 static void
268 dump_output (buffer, file)
269 struct output_buffer *buffer;
270 FILE *file;
272 char *text;
274 obstack_1grow (&buffer->obstack, '\0');
275 text = obstack_finish (&buffer->obstack);
276 fputs (text, file);
277 obstack_free (&buffer->obstack, text);
278 buffer->line_length = 0;
281 static char *
282 vbuild_message_string (msgid, ap)
283 const char *msgid;
284 va_list ap;
286 char *str;
288 vasprintf (&str, msgid, ap);
289 return str;
292 /* Return a malloc'd string containing MSGID formatted a la
293 printf. The caller is reponsible for freeing the memory. */
295 static char *
296 build_message_string VPARAMS ((const char *msgid, ...))
298 #ifndef ANSI_PROTOTYPES
299 const char *msgid;
300 #endif
301 va_list ap;
302 char *str;
304 VA_START (ap, msgid);
306 #ifndef ANSI_PROTOTYPES
307 msgid = va_arg (ap, const char *);
308 #endif
310 str = vbuild_message_string (msgid, ap);
312 va_end (ap);
314 return str;
318 /* Return a malloc'd string describing a location. The caller is
319 responsible for freeing the memory. */
321 static char *
322 build_location_prefix (file, line, warn)
323 const char *file;
324 int line;
325 int warn;
327 if (file)
329 if (warn)
330 return build_message_string ("%s:%d: warning: ", file, line);
331 else
332 return build_message_string ("%s:%d: ", file, line);
334 else
336 if (warn)
337 return build_message_string ("%s: warning: ", progname);
338 else
339 return build_message_string ("%s: ", progname);
343 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
345 static void
346 voutput_notice (buffer, msgid, ap)
347 struct output_buffer *buffer;
348 const char *msgid;
349 va_list ap;
351 char *message = vbuild_message_string (msgid, ap);
353 output_puts (buffer, message);
354 free (message);
358 /* Format a message into BUFFER a la printf. */
360 static void
361 output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
363 #ifndef ANSI_PROTOTYPES
364 struct output_buffer *buffer;
365 const char *msgid;
366 #endif
367 va_list ap;
369 VA_START (ap, msgid);
371 #ifndef ANSI_PROTOTYPES
372 buffer = va_arg (ap, struct output_buffer *);
373 msgid = va_arg (ap, const char *);
374 #endif
376 voutput_notice (buffer, msgid, ap);
377 va_end (ap);
381 /* Format a MESSAGE into FILE. Do line wrapping, starting new lines
382 with PREFIX. */
384 static void
385 line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...))
387 #ifndef ANSI_PROTOTYPES
388 FILE *file;
389 const char *msgid;
390 #endif
391 struct output_buffer buffer;
392 va_list ap;
394 VA_START (ap, msgid);
396 #ifndef ANSI_PROTOTYPES
397 file = va_arg (ap, FILE *);
398 msgid = va_arg (ap, const char *);
399 #endif
401 init_output_buffer (&buffer, NULL, output_maximum_width);
402 voutput_notice (&buffer, msgid, ap);
403 dump_output (&buffer, file);
405 va_end (ap);
409 static void
410 vline_wrapper_message_with_location (file, line, warn, msgid, ap)
411 const char *file;
412 int line;
413 int warn;
414 const char *msgid;
415 va_list ap;
417 struct output_buffer buffer;
419 init_output_buffer
420 (&buffer, build_location_prefix (file, line, warn), output_maximum_width);
421 voutput_notice (&buffer, msgid, ap);
422 dump_output (&buffer, stderr);
423 free ((char*)get_output_prefix (&buffer));
424 fputc ('\n', stderr);
428 /* Print the message MSGID in FILE. */
430 static void
431 vnotice (file, msgid, ap)
432 FILE *file;
433 const char *msgid;
434 va_list ap;
436 vfprintf (file, _(msgid), ap);
439 /* Print MSGID on stderr. */
441 static void
442 notice VPARAMS ((const char *msgid, ...))
444 #ifndef ANSI_PROTOTYPES
445 char *msgid;
446 #endif
447 va_list ap;
449 VA_START (ap, msgid);
451 #ifndef ANSI_PROTOTYPES
452 msgid = va_arg (ap, char *);
453 #endif
455 vnotice (stderr, msgid, ap);
456 va_end (ap);
459 /* Report FILE and LINE (or program name), and optionally just WARN. */
461 static void
462 report_file_and_line (file, line, warn)
463 const char *file;
464 int line;
465 int warn;
467 if (file)
468 fprintf (stderr, "%s:%d: ", file, line);
469 else
470 fprintf (stderr, "%s: ", progname);
472 if (warn)
473 notice ("warning: ");
476 /* Print a message relevant to line LINE of file FILE. */
478 static void
479 v_message_with_file_and_line (file, line, warn, msgid, ap)
480 const char *file;
481 int line;
482 int warn;
483 const char *msgid;
484 va_list ap;
486 report_file_and_line (file, line, warn);
487 vnotice (stderr, msgid, ap);
488 fputc ('\n', stderr);
491 /* Print a message relevant to the given DECL. */
493 static void
494 v_message_with_decl (decl, warn, msgid, ap)
495 tree decl;
496 int warn;
497 const char *msgid;
498 va_list ap;
500 const char *p;
501 struct output_buffer buffer;
503 if (doing_line_wrapping ())
504 init_output_buffer
505 (&buffer,
506 build_location_prefix (DECL_SOURCE_FILE (decl),
507 DECL_SOURCE_LINE (decl), warn),
508 output_maximum_width);
509 else
510 report_file_and_line (DECL_SOURCE_FILE (decl),
511 DECL_SOURCE_LINE (decl), warn);
513 /* Do magic to get around lack of varargs support for insertion
514 of arguments into existing list. We know that the decl is first;
515 we ass_u_me that it will be printed with "%s". */
517 for (p = _(msgid); *p; ++p)
519 if (*p == '%')
521 if (*(p + 1) == '%')
522 ++p;
523 else if (*(p + 1) != 's')
524 abort ();
525 else
526 break;
530 if (p > _(msgid)) /* Print the left-hand substring. */
532 if (doing_line_wrapping ())
533 output_printf (&buffer, "%.*s", (int)(p - _(msgid)), _(msgid));
534 else
535 fprintf (stderr, "%.*s", (int)(p - _(msgid)), _(msgid));
538 if (*p == '%') /* Print the name. */
540 const char *n = (DECL_NAME (decl)
541 ? (*decl_printable_name) (decl, 2)
542 : "((anonymous))");
543 if (doing_line_wrapping ())
544 output_puts (&buffer, n);
545 else
546 fputs (n, stderr);
547 while (*p)
549 ++p;
550 if (ISALPHA (*(p - 1) & 0xFF))
551 break;
555 if (*p) /* Print the rest of the message. */
557 if (doing_line_wrapping ())
558 voutput_notice (&buffer, p, ap);
559 else
560 vfprintf (stderr, p, ap);
563 if (doing_line_wrapping())
565 dump_output (&buffer, stderr);
566 free ((char *)get_output_prefix (&buffer));
569 fputc ('\n', stderr);
572 /* Figure file and line of the given INSN. */
574 static void
575 file_and_line_for_asm (insn, pfile, pline)
576 rtx insn;
577 const char **pfile;
578 int *pline;
580 rtx body = PATTERN (insn);
581 rtx asmop;
583 /* Find the (or one of the) ASM_OPERANDS in the insn. */
584 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
585 asmop = SET_SRC (body);
586 else if (GET_CODE (body) == ASM_OPERANDS)
587 asmop = body;
588 else if (GET_CODE (body) == PARALLEL
589 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
590 asmop = SET_SRC (XVECEXP (body, 0, 0));
591 else if (GET_CODE (body) == PARALLEL
592 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
593 asmop = XVECEXP (body, 0, 0);
594 else
595 asmop = NULL;
597 if (asmop)
599 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
600 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
602 else
604 *pfile = input_filename;
605 *pline = lineno;
609 /* Report an error at line LINE of file FILE. */
611 static void
612 v_error_with_file_and_line (file, line, msgid, ap)
613 const char *file;
614 int line;
615 const char *msgid;
616 va_list ap;
618 count_error (0);
619 report_error_function (file);
620 if (doing_line_wrapping ())
621 vline_wrapper_message_with_location (file, line, 0, msgid, ap);
622 else
623 v_message_with_file_and_line (file, line, 0, msgid, ap);
626 /* Report an error at the declaration DECL.
627 MSGID is a format string which uses %s to substitute the declaration
628 name; subsequent substitutions are a la printf. */
630 static void
631 v_error_with_decl (decl, msgid, ap)
632 tree decl;
633 const char *msgid;
634 va_list ap;
636 count_error (0);
637 report_error_function (DECL_SOURCE_FILE (decl));
638 v_message_with_decl (decl, 0, msgid, ap);
642 /* Report an error at the line number of the insn INSN.
643 This is used only when INSN is an `asm' with operands,
644 and each ASM_OPERANDS records its own source file and line. */
646 static void
647 v_error_for_asm (insn, msgid, ap)
648 rtx insn;
649 const char *msgid;
650 va_list ap;
652 const char *file;
653 int line;
655 count_error (0);
656 file_and_line_for_asm (insn, &file, &line);
657 report_error_function (file);
658 v_message_with_file_and_line (file, line, 0, msgid, ap);
662 /* Report an error at the current line number. */
664 static void
665 verror (msgid, ap)
666 const char *msgid;
667 va_list ap;
669 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
673 /* Report a fatal error at the current line number. Allow a front end to
674 intercept the message. */
676 static void (*fatal_function) PARAMS ((const char *, va_list));
678 static void
679 vfatal (msgid, ap)
680 const char *msgid;
681 va_list ap;
683 if (fatal_function != 0)
684 (*fatal_function) (_(msgid), ap);
686 verror (msgid, ap);
687 exit (FATAL_EXIT_CODE);
690 /* Report a warning at line LINE of file FILE. */
692 static void
693 v_warning_with_file_and_line (file, line, msgid, ap)
694 const char *file;
695 int line;
696 const char *msgid;
697 va_list ap;
699 if (count_error (1))
701 report_error_function (file);
702 if (doing_line_wrapping ())
703 vline_wrapper_message_with_location (file, line, 1, msgid, ap);
704 else
705 v_message_with_file_and_line (file, line, 1, msgid, ap);
710 /* Report a warning at the declaration DECL.
711 MSGID is a format string which uses %s to substitute the declaration
712 name; subsequent substitutions are a la printf. */
714 static void
715 v_warning_with_decl (decl, msgid, ap)
716 tree decl;
717 const char *msgid;
718 va_list ap;
720 if (count_error (1))
722 report_error_function (DECL_SOURCE_FILE (decl));
723 v_message_with_decl (decl, 1, msgid, ap);
728 /* Report a warning at the line number of the insn INSN.
729 This is used only when INSN is an `asm' with operands,
730 and each ASM_OPERANDS records its own source file and line. */
732 static void
733 v_warning_for_asm (insn, msgid, ap)
734 rtx insn;
735 const char *msgid;
736 va_list ap;
738 if (count_error (1))
740 const char *file;
741 int line;
743 file_and_line_for_asm (insn, &file, &line);
744 report_error_function (file);
745 v_message_with_file_and_line (file, line, 1, msgid, ap);
750 /* Report a warning at the current line number. */
752 static void
753 vwarning (msgid, ap)
754 const char *msgid;
755 va_list ap;
757 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
760 /* These functions issue either warnings or errors depending on
761 -pedantic-errors. */
763 static void
764 vpedwarn (msgid, ap)
765 const char *msgid;
766 va_list ap;
768 if (flag_pedantic_errors)
769 verror (msgid, ap);
770 else
771 vwarning (msgid, ap);
775 static void
776 v_pedwarn_with_decl (decl, msgid, ap)
777 tree decl;
778 const char *msgid;
779 va_list ap;
781 /* We don't want -pedantic-errors to cause the compilation to fail from
782 "errors" in system header files. Sometimes fixincludes can't fix what's
783 broken (eg: unsigned char bitfields - fixing it may change the alignment
784 which will cause programs to mysteriously fail because the C library
785 or kernel uses the original layout). There's no point in issuing a
786 warning either, it's just unnecessary noise. */
788 if (! DECL_IN_SYSTEM_HEADER (decl))
790 if (flag_pedantic_errors)
791 v_error_with_decl (decl, msgid, ap);
792 else
793 v_warning_with_decl (decl, msgid, ap);
798 static void
799 v_pedwarn_with_file_and_line (file, line, msgid, ap)
800 const char *file;
801 int line;
802 const char *msgid;
803 va_list ap;
805 if (flag_pedantic_errors)
806 v_error_with_file_and_line (file, line, msgid, ap);
807 else
808 v_warning_with_file_and_line (file, line, msgid, ap);
812 /* Apologize for not implementing some feature. */
814 static void
815 vsorry (msgid, ap)
816 const char *msgid;
817 va_list ap;
819 sorrycount++;
820 if (input_filename)
821 fprintf (stderr, "%s:%d: ", input_filename, lineno);
822 else
823 fprintf (stderr, "%s: ", progname);
824 notice ("sorry, not implemented: ");
825 vnotice (stderr, msgid, ap);
826 fputc ('\n', stderr);
830 /* Count an error or warning. Return 1 if the message should be printed. */
833 count_error (warningp)
834 int warningp;
836 if (warningp && inhibit_warnings)
837 return 0;
839 if (warningp && !warnings_are_errors)
840 warningcount++;
841 else
843 static int warning_message = 0;
845 if (warningp && !warning_message)
847 notice ("%s: warnings being treated as errors\n", progname);
848 warning_message = 1;
850 errorcount++;
853 return 1;
856 /* Print a diagnistic MSGID on FILE. */
857 void
858 fnotice VPARAMS ((FILE *file, const char *msgid, ...))
860 #ifndef ANSI_PROTOTYPES
861 FILE *file;
862 const char *msgid;
863 #endif
864 va_list ap;
866 VA_START (ap, msgid);
868 #ifndef ANSI_PROTOTYPES
869 file = va_arg (ap, FILE *);
870 msgid = va_arg (ap, const char *);
871 #endif
873 vnotice (file, msgid, ap);
874 va_end (ap);
878 /* Print a fatal error message. NAME is the text.
879 Also include a system error message based on `errno'. */
881 void
882 pfatal_with_name (name)
883 const char *name;
885 fprintf (stderr, "%s: ", progname);
886 perror (name);
887 exit (FATAL_EXIT_CODE);
890 void
891 fatal_io_error (name)
892 const char *name;
894 notice ("%s: %s: I/O error\n", progname, name);
895 exit (FATAL_EXIT_CODE);
898 /* Issue a pedantic warning MSGID. */
899 void
900 pedwarn VPARAMS ((const char *msgid, ...))
902 #ifndef ANSI_PROTOTYPES
903 const char *msgid;
904 #endif
905 va_list ap;
907 VA_START (ap, msgid);
909 #ifndef ANSI_PROTOTYPES
910 msgid = va_arg (ap, const char *);
911 #endif
913 vpedwarn (msgid, ap);
914 va_end (ap);
917 /* Issue a pedantic waring about DECL. */
918 void
919 pedwarn_with_decl VPARAMS ((tree decl, const char *msgid, ...))
921 #ifndef ANSI_PROTOTYPES
922 tree decl;
923 const char *msgid;
924 #endif
925 va_list ap;
927 VA_START (ap, msgid);
929 #ifndef ANSI_PROTOTYPES
930 decl = va_arg (ap, tree);
931 msgid = va_arg (ap, const char *);
932 #endif
934 v_pedwarn_with_decl (decl, msgid, ap);
935 va_end (ap);
938 /* Same as above but within the context FILE and LINE. */
939 void
940 pedwarn_with_file_and_line VPARAMS ((const char *file, int line,
941 const char *msgid, ...))
943 #ifndef ANSI_PROTOTYPES
944 const char *file;
945 int line;
946 const char *msgid;
947 #endif
948 va_list ap;
950 VA_START (ap, msgid);
952 #ifndef ANSI_PROTOTYPES
953 file = va_arg (ap, const char *);
954 line = va_arg (ap, int);
955 msgid = va_arg (ap, const char *);
956 #endif
958 v_pedwarn_with_file_and_line (file, line, msgid, ap);
959 va_end (ap);
962 /* Just apologize with MSGID. */
963 void
964 sorry VPARAMS ((const char *msgid, ...))
966 #ifndef ANSI_PROTOTYPES
967 const char *msgid;
968 #endif
969 va_list ap;
971 VA_START (ap, msgid);
973 #ifndef ANSI_PROTOTYPES
974 msgid = va_arg (ap, const char *);
975 #endif
977 vsorry (msgid, ap);
978 va_end (ap);
981 /* Called when the start of a function definition is parsed,
982 this function prints on stderr the name of the function. */
984 void
985 announce_function (decl)
986 tree decl;
988 if (! quiet_flag)
990 if (rtl_dump_and_exit)
991 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
992 else
994 if (doing_line_wrapping ())
995 line_wrapper_printf
996 (stderr, " %s", (*decl_printable_name) (decl, 2));
997 else
998 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1000 fflush (stderr);
1001 need_error_newline = 1;
1002 last_error_function = current_function_decl;
1006 /* The default function to print out name of current function that caused
1007 an error. */
1009 void
1010 default_print_error_function (file)
1011 const char *file;
1013 if (last_error_function != current_function_decl)
1015 char *prefix = NULL;
1016 struct output_buffer buffer;
1018 if (file)
1019 prefix = build_message_string ("%s: ", file);
1021 if (doing_line_wrapping ())
1022 init_output_buffer (&buffer, prefix, output_maximum_width);
1023 else
1025 if (file)
1026 fprintf (stderr, "%s: ", file);
1029 if (current_function_decl == NULL)
1031 if (doing_line_wrapping ())
1032 output_printf (&buffer, "At top level:\n");
1033 else
1034 notice ("At top level:\n");
1036 else
1038 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1040 if (doing_line_wrapping ())
1041 output_printf
1042 (&buffer, "In method `%s':\n",
1043 (*decl_printable_name) (current_function_decl, 2));
1044 else
1045 notice ("In method `%s':\n",
1046 (*decl_printable_name) (current_function_decl, 2));
1048 else
1050 if (doing_line_wrapping ())
1051 output_printf
1052 (&buffer, "In function `%s':\n",
1053 (*decl_printable_name) (current_function_decl, 2));
1054 else
1055 notice ("In function `%s':\n",
1056 (*decl_printable_name) (current_function_decl, 2));
1060 last_error_function = current_function_decl;
1062 if (doing_line_wrapping ())
1063 dump_output (&buffer, stderr);
1065 free (prefix);
1069 /* Prints out, if necessary, the name of the current function
1070 that caused an error. Called from all error and warning functions.
1071 We ignore the FILE parameter, as it cannot be relied upon. */
1073 void
1074 report_error_function (file)
1075 const char *file ATTRIBUTE_UNUSED;
1077 struct file_stack *p;
1079 if (need_error_newline)
1081 fprintf (stderr, "\n");
1082 need_error_newline = 0;
1085 if (input_file_stack && input_file_stack->next != 0
1086 && input_file_stack_tick != last_error_tick)
1088 for (p = input_file_stack->next; p; p = p->next)
1089 if (p == input_file_stack->next)
1090 notice ("In file included from %s:%d", p->name, p->line);
1091 else
1092 notice (",\n from %s:%d", p->name, p->line);
1093 fprintf (stderr, ":\n");
1094 last_error_tick = input_file_stack_tick;
1097 (*print_error_function) (input_filename);
1100 void
1101 error_with_file_and_line VPARAMS ((const char *file, int line,
1102 const char *msgid, ...))
1104 #ifndef ANSI_PROTOTYPES
1105 const char *file;
1106 int line;
1107 const char *msgid;
1108 #endif
1109 va_list ap;
1111 VA_START (ap, msgid);
1113 #ifndef ANSI_PROTOTYPES
1114 file = va_arg (ap, const char *);
1115 line = va_arg (ap, int);
1116 msgid = va_arg (ap, const char *);
1117 #endif
1119 v_error_with_file_and_line (file, line, msgid, ap);
1120 va_end (ap);
1123 void
1124 error_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1126 #ifndef ANSI_PROTOTYPES
1127 tree decl;
1128 const char *msgid;
1129 #endif
1130 va_list ap;
1132 VA_START (ap, msgid);
1134 #ifndef ANSI_PROTOTYPES
1135 decl = va_arg (ap, tree);
1136 msgid = va_arg (ap, const char *);
1137 #endif
1139 v_error_with_decl (decl, msgid, ap);
1140 va_end (ap);
1143 void
1144 error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1146 #ifndef ANSI_PROTOTYPES
1147 rtx insn;
1148 const char *msgid;
1149 #endif
1150 va_list ap;
1152 VA_START (ap, msgid);
1154 #ifndef ANSI_PROTOTYPES
1155 insn = va_arg (ap, rtx);
1156 msgid = va_arg (ap, const char *);
1157 #endif
1159 v_error_for_asm (insn, msgid, ap);
1160 va_end (ap);
1163 void
1164 error VPARAMS ((const char *msgid, ...))
1166 #ifndef ANSI_PROTOTYPES
1167 const char *msgid;
1168 #endif
1169 va_list ap;
1171 VA_START (ap, msgid);
1173 #ifndef ANSI_PROTOTYPES
1174 msgid = va_arg (ap, const char *);
1175 #endif
1177 verror (msgid, ap);
1178 va_end (ap);
1181 /* Set the function to call when a fatal error occurs. */
1183 void
1184 set_fatal_function (f)
1185 void (*f) PARAMS ((const char *, va_list));
1187 fatal_function = f;
1190 void
1191 fatal VPARAMS ((const char *msgid, ...))
1193 #ifndef ANSI_PROTOTYPES
1194 const char *msgid;
1195 #endif
1196 va_list ap;
1198 VA_START (ap, msgid);
1200 #ifndef ANSI_PROTOTYPES
1201 msgid = va_arg (ap, const char *);
1202 #endif
1204 vfatal (msgid, ap);
1205 va_end (ap);
1208 void
1209 _fatal_insn (msgid, insn, file, line, function)
1210 const char *msgid;
1211 rtx insn;
1212 const char *file;
1213 int line;
1214 const char *function;
1216 error ("%s", msgid);
1217 debug_rtx (insn);
1218 fancy_abort (file, line, function);
1221 void
1222 _fatal_insn_not_found (insn, file, line, function)
1223 rtx insn;
1224 const char *file;
1225 int line;
1226 const char *function;
1228 if (INSN_CODE (insn) < 0)
1229 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1230 else
1231 _fatal_insn ("Insn does not satisfy its constraints:",
1232 insn, file, line, function);
1235 void
1236 warning_with_file_and_line VPARAMS ((const char *file, int line,
1237 const char *msgid, ...))
1239 #ifndef ANSI_PROTOTYPES
1240 const char *file;
1241 int line;
1242 const char *msgid;
1243 #endif
1244 va_list ap;
1246 VA_START (ap, msgid);
1248 #ifndef ANSI_PROTOTYPES
1249 file = va_arg (ap, const char *);
1250 line = va_arg (ap, int);
1251 msgid = va_arg (ap, const char *);
1252 #endif
1254 v_warning_with_file_and_line (file, line, msgid, ap);
1255 va_end (ap);
1258 void
1259 warning_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1261 #ifndef ANSI_PROTOTYPES
1262 tree decl;
1263 const char *msgid;
1264 #endif
1265 va_list ap;
1267 VA_START (ap, msgid);
1269 #ifndef ANSI_PROTOTYPES
1270 decl = va_arg (ap, tree);
1271 msgid = va_arg (ap, const char *);
1272 #endif
1274 v_warning_with_decl (decl, msgid, ap);
1275 va_end (ap);
1278 void
1279 warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1281 #ifndef ANSI_PROTOTYPES
1282 rtx insn;
1283 const char *msgid;
1284 #endif
1285 va_list ap;
1287 VA_START (ap, msgid);
1289 #ifndef ANSI_PROTOTYPES
1290 insn = va_arg (ap, rtx);
1291 msgid = va_arg (ap, const char *);
1292 #endif
1294 v_warning_for_asm (insn, msgid, ap);
1295 va_end (ap);
1298 void
1299 warning VPARAMS ((const char *msgid, ...))
1301 #ifndef ANSI_PROTOTYPES
1302 const char *msgid;
1303 #endif
1304 va_list ap;
1306 VA_START (ap, msgid);
1308 #ifndef ANSI_PROTOTYPES
1309 msgid = va_arg (ap, const char *);
1310 #endif
1312 vwarning (msgid, ap);
1313 va_end (ap);