Fix cut and paste error in last change
[official-gcc.git] / gcc / diagnostic.c
blob564c4883cf63ef71931c4f665f2d32cced0f09d1
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 vfatal PARAMS ((const char *, va_list)) ATTRIBUTE_NORETURN;
68 static void v_warning_with_file_and_line PARAMS ((const char *, int,
69 const char *, va_list));
70 static void v_warning_with_decl PARAMS ((tree, const char *, va_list));
71 static void v_warning_for_asm PARAMS ((rtx, const char *, va_list));
72 static void v_pedwarn_with_decl PARAMS ((tree, const char *, va_list));
73 static void v_pedwarn_with_file_and_line PARAMS ((const char *, int,
74 const char *, va_list));
75 static void vsorry PARAMS ((const char *, va_list));
76 static void report_file_and_line PARAMS ((const char *, int, int));
77 static void vnotice PARAMS ((FILE *, const char *, va_list));
78 static void set_real_maximum_length PARAMS ((output_buffer *));
80 extern int rtl_dump_and_exit;
81 extern int inhibit_warnings;
82 extern int warnings_are_errors;
83 extern int warningcount;
84 extern int errorcount;
86 /* Front-end specific tree formatter, if non-NULL. */
87 printer_fn lang_printer = NULL;
89 /* An output_buffer surrogate for stderr. */
90 static output_buffer global_output_buffer;
91 output_buffer *diagnostic_buffer = &global_output_buffer;
93 static int need_error_newline;
95 /* Function of last error message;
96 more generally, function such that if next error message is in it
97 then we don't have to mention the function name. */
98 static tree last_error_function = NULL;
100 /* Used to detect when input_file_stack has changed since last described. */
101 static int last_error_tick;
103 /* Called by report_error_function to print out function name.
104 * Default may be overridden by language front-ends. */
106 void (*print_error_function) PARAMS ((const char *)) =
107 default_print_error_function;
109 /* Maximum characters per line in automatic line wrapping mode.
110 Zero means don't wrap lines. */
112 int diagnostic_message_length_per_line;
114 /* Used to control every diagnostic message formatting. Front-ends should
115 call set_message_prefixing_rule to set up their politics. */
116 static int current_prefixing_rule;
118 /* Initialize the diagnostic message outputting machinery. */
120 void
121 initialize_diagnostics ()
123 /* By default, we don't line-wrap messages. */
124 diagnostic_message_length_per_line = 0;
125 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE);
126 /* Proceed to actual initialization. */
127 default_initialize_buffer (diagnostic_buffer);
130 /* Predicate. Return 1 if we're in automatic line wrapping mode. */
132 static int
133 doing_line_wrapping ()
135 return diagnostic_message_length_per_line > 0;
138 void
139 set_message_prefixing_rule (rule)
140 int rule;
142 current_prefixing_rule = rule;
145 /* Returns true if BUFFER is in line-wrappind mode. */
147 output_is_line_wrapping (buffer)
148 output_buffer *buffer;
150 return buffer->ideal_maximum_length > 0;
153 /* Return BUFFER's prefix. */
154 const char *
155 output_get_prefix (buffer)
156 const output_buffer *buffer;
158 return buffer->prefix;
161 /* Subroutine of output_set_maximum_length. Set up BUFFER's
162 internal maximum characters per line. */
163 static void
164 set_real_maximum_length (buffer)
165 output_buffer *buffer;
167 /* If we're told not to wrap lines then do the obvious thing. */
168 if (! output_is_line_wrapping (buffer))
169 buffer->maximum_length = buffer->ideal_maximum_length;
170 else
172 int prefix_length = buffer->prefix ? strlen (buffer->prefix) : 0;
173 /* If the prefix is ridiculously too long, output at least
174 32 characters. */
175 if (buffer->ideal_maximum_length - prefix_length < 32)
176 buffer->maximum_length = buffer->ideal_maximum_length + 32;
177 else
178 buffer->maximum_length = buffer->ideal_maximum_length;
182 /* Sets the number of maximum characters per line BUFFER can output
183 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
184 void
185 output_set_maximum_length (buffer, length)
186 output_buffer *buffer;
187 int length;
189 buffer->ideal_maximum_length = length;
190 set_real_maximum_length (buffer);
193 /* Sets BUFFER's PREFIX. */
194 void
195 output_set_prefix (buffer, prefix)
196 output_buffer *buffer;
197 const char *prefix;
199 buffer->prefix = prefix;
200 set_real_maximum_length (buffer);
201 buffer->emitted_prefix_p = 0;
204 /* Free BUFFER's prefix, a previously malloc()'d string. */
206 void
207 output_destroy_prefix (buffer)
208 output_buffer *buffer;
210 if (buffer->prefix)
212 free ((char *) buffer->prefix);
213 buffer->prefix = NULL;
217 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
218 characters per line. */
219 void
220 init_output_buffer (buffer, prefix, maximum_length)
221 output_buffer *buffer;
222 const char *prefix;
223 int maximum_length;
225 obstack_init (&buffer->obstack);
226 buffer->ideal_maximum_length = maximum_length;
227 buffer->line_length = 0;
228 output_set_prefix (buffer, prefix);
229 buffer->emitted_prefix_p = 0;
230 buffer->prefixing_rule = current_prefixing_rule;
232 buffer->cursor = NULL;
235 /* Initialize BUFFER with a NULL prefix and current diagnostic message
236 length cutoff. */
237 void
238 default_initialize_buffer (buffer)
239 output_buffer *buffer;
241 init_output_buffer (buffer, NULL, diagnostic_message_length_per_line);
244 /* Recompute diagnostic_buffer's attributes to reflect any change
245 in diagnostic formatting global options. */
246 void
247 reshape_diagnostic_buffer ()
249 diagnostic_buffer->ideal_maximum_length = diagnostic_message_length_per_line;
250 diagnostic_buffer->prefixing_rule = current_prefixing_rule;
251 set_real_maximum_length (diagnostic_buffer);
254 /* Reinitialize BUFFER. */
255 void
256 output_clear (buffer)
257 output_buffer *buffer;
259 obstack_free (&buffer->obstack, obstack_base (&buffer->obstack));
260 buffer->line_length = 0;
261 buffer->cursor = NULL;
262 buffer->emitted_prefix_p = 0;
265 /* Finishes to construct a NULL-terminated character string representing
266 the BUFFERed message. */
267 const char *
268 output_finish (buffer)
269 output_buffer *buffer;
271 obstack_1grow (&buffer->obstack, '\0');
272 return (const char *) obstack_finish (&buffer->obstack);
275 /* Return the amount of characters BUFFER can accept to
276 make a full line. */
278 output_space_left (buffer)
279 const output_buffer *buffer;
281 return buffer->maximum_length - buffer->line_length;
284 /* Write out BUFFER's prefix. */
285 void
286 output_emit_prefix (buffer)
287 output_buffer *buffer;
289 if (buffer->prefix)
291 switch (buffer->prefixing_rule)
293 default:
294 case DIAGNOSTICS_SHOW_PREFIX_NEVER:
295 break;
297 case DIAGNOSTICS_SHOW_PREFIX_ONCE:
298 if (buffer->emitted_prefix_p)
299 break;
300 else
301 buffer->emitted_prefix_p = 1;
302 /* Fall through. */
304 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE:
305 buffer->line_length += strlen (buffer->prefix);
306 obstack_grow
307 (&buffer->obstack, buffer->prefix, buffer->line_length);
308 break;
313 /* Have BUFFER start a new line. */
314 void
315 output_add_newline (buffer)
316 output_buffer *buffer;
318 obstack_1grow (&buffer->obstack, '\n');
319 buffer->line_length = 0;
322 /* Appends a character to BUFFER. */
323 void
324 output_add_character (buffer, c)
325 output_buffer *buffer;
326 int c;
328 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
329 output_add_newline (buffer);
330 obstack_1grow (&buffer->obstack, c);
331 ++buffer->line_length;
334 /* Adds a space to BUFFER. */
335 void
336 output_add_space (buffer)
337 output_buffer *buffer;
339 if (output_is_line_wrapping (buffer) && output_space_left (buffer) <= 0)
341 output_add_newline (buffer);
342 return;
344 obstack_1grow (&buffer->obstack, ' ');
345 ++buffer->line_length;
348 /* Add the stringified version of an integer to BUFFER. */
349 void
350 output_add_integer (buffer, i)
351 output_buffer *buffer;
352 HOST_WIDE_INT i;
354 /* This must be large enough to hold any printed integer or
355 floating-point value. */
356 static char digit_buffer[128];
358 sprintf (digit_buffer, HOST_WIDE_INT_PRINT_DEC, i);
359 output_add_string (buffer, digit_buffer);
362 /* Append a string deliminated by START and END to BUFFER. No wrapping is
363 done. The caller must ensure that it is safe to do so. */
365 void
366 output_append (buffer, start, end)
367 output_buffer *buffer;
368 const char *start;
369 const char *end;
371 int n;
373 /* Emit prefix and skip whitespace if we're starting a new line. */
374 if (buffer->line_length == 0)
376 output_emit_prefix (buffer);
377 while (start != end && *start == ' ')
378 ++start;
380 n = end - start;
381 obstack_grow (&buffer->obstack, start, n);
382 buffer->line_length += n;
385 /* Wrap a STRing into BUFFER. */
387 void
388 output_add_string (buffer, str)
389 output_buffer *buffer;
390 const char *str;
392 const char *p = str;
394 if (!output_is_line_wrapping (buffer))
395 output_append (buffer, str, str + strlen (str));
396 else while (*str)
398 while (*p && *p != ' ' && *p != '\n')
399 ++p;
401 if (p - str < output_space_left (buffer))
402 output_append (buffer, str, p);
403 else
405 output_add_newline (buffer);
406 output_append (buffer, str, p);
409 while (*p && *p == '\n')
411 output_add_newline (buffer);
412 ++p;
415 str = p++;
419 /* Flush the content of BUFFER onto FILE and reinitialize BUFFER. */
421 void
422 output_flush_on (buffer, file)
423 output_buffer *buffer;
424 FILE *file;
426 const char *text = output_finish (buffer);
427 fputs (text, file);
428 output_clear (buffer);
431 /* Format MESSAGE into BUFFER. */
432 void
433 output_format (buffer, msg)
434 output_buffer *buffer;
435 const char *msg;
437 for (buffer->cursor = msg; *buffer->cursor; ++buffer->cursor)
439 /* Ignore text. */
440 if (*buffer->cursor != '%')
442 output_add_character (buffer, *buffer->cursor);
443 continue;
446 /* We got a '%'. Let's see what happens. */
447 ++buffer->cursor;
449 /* Let's handle the traditional cases. */
450 if (*buffer->cursor == 's')
451 output_add_string (buffer, va_arg (buffer->format_args, const char *));
452 else if (*buffer->cursor == 'd')
453 output_add_integer (buffer, va_arg (buffer->format_args, int));
454 else if (*buffer->cursor == '%')
455 /* It was a '%%'. Just output a '%'. */
456 output_add_character (buffer, '%');
457 else if (lang_printer)
458 (*lang_printer) (buffer);
459 else
461 /* Hmmm. The front-end failed to install a format translator
462 but called us with an unrecognized format. Sorry. */
463 abort();
466 output_finish (buffer);
469 static char *
470 vbuild_message_string (msgid, ap)
471 const char *msgid;
472 va_list ap;
474 char *str;
476 vasprintf (&str, msgid, ap);
477 return str;
480 /* Return a malloc'd string containing MSGID formatted a la
481 printf. The caller is reponsible for freeing the memory. */
483 static char *
484 build_message_string VPARAMS ((const char *msgid, ...))
486 #ifndef ANSI_PROTOTYPES
487 const char *msgid;
488 #endif
489 va_list ap;
490 char *str;
492 VA_START (ap, msgid);
494 #ifndef ANSI_PROTOTYPES
495 msgid = va_arg (ap, const char *);
496 #endif
498 str = vbuild_message_string (msgid, ap);
500 va_end (ap);
502 return str;
506 /* Return a malloc'd string describing a location. The caller is
507 responsible for freeing the memory. */
509 static char *
510 build_location_prefix (file, line, warn)
511 const char *file;
512 int line;
513 int warn;
515 if (file)
517 if (warn)
518 return build_message_string ("%s:%d: warning: ", file, line);
519 else
520 return build_message_string ("%s:%d: ", file, line);
522 else
524 if (warn)
525 return build_message_string ("%s: warning: ", progname);
526 else
527 return build_message_string ("%s: ", progname);
531 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
533 static void
534 output_notice (buffer, msgid)
535 output_buffer *buffer;
536 const char *msgid;
538 char *message = vbuild_message_string (msgid, buffer->format_args);
540 output_add_string (buffer, message);
541 free (message);
545 /* Format a message into BUFFER a la printf. */
547 void
548 output_printf VPARAMS ((struct output_buffer *buffer, const char *msgid, ...))
550 #ifndef ANSI_PROTOTYPES
551 struct output_buffer *buffer;
552 const char *msgid;
553 #endif
554 va_list ap;
556 VA_START (ap, msgid);
558 #ifndef ANSI_PROTOTYPES
559 buffer = va_arg (ap, struct output_buffer *);
560 msgid = va_arg (ap, const char *);
561 #endif
563 va_copy (buffer->format_args, ap);
564 output_notice (buffer, msgid);
565 va_end (buffer->format_args);
569 /* Format a MESSAGE into FILE. Do line wrapping, starting new lines
570 with PREFIX. */
572 static void
573 line_wrapper_printf VPARAMS ((FILE *file, const char *msgid, ...))
575 #ifndef ANSI_PROTOTYPES
576 FILE *file;
577 const char *msgid;
578 #endif
579 output_buffer buffer;
581 init_output_buffer (&buffer, NULL, diagnostic_message_length_per_line);
582 VA_START (buffer.format_args, msgid);
584 #ifndef ANSI_PROTOTYPES
585 file = va_arg (buffer.format_args, FILE *);
586 msgid = va_arg (buffer.format_args, const char *);
587 #endif
589 output_notice (&buffer, msgid);
590 output_flush_on (&buffer, file);
592 va_end (buffer.format_args);
596 static void
597 vline_wrapper_message_with_location (file, line, warn, msgid, ap)
598 const char *file;
599 int line;
600 int warn;
601 const char *msgid;
602 va_list ap;
604 output_buffer buffer;
606 init_output_buffer (&buffer, build_location_prefix (file, line, warn),
607 diagnostic_message_length_per_line);
608 va_copy (buffer.format_args, ap);
609 output_notice (&buffer, msgid);
610 output_flush_on (&buffer, stderr);
612 output_destroy_prefix (&buffer);
613 fputc ('\n', stderr);
617 /* Print the message MSGID in FILE. */
619 static void
620 vnotice (file, msgid, ap)
621 FILE *file;
622 const char *msgid;
623 va_list ap;
625 vfprintf (file, _(msgid), ap);
628 /* Print MSGID on stderr. */
630 static void
631 notice VPARAMS ((const char *msgid, ...))
633 #ifndef ANSI_PROTOTYPES
634 char *msgid;
635 #endif
636 va_list ap;
638 VA_START (ap, msgid);
640 #ifndef ANSI_PROTOTYPES
641 msgid = va_arg (ap, char *);
642 #endif
644 vnotice (stderr, msgid, ap);
645 va_end (ap);
648 /* Report FILE and LINE (or program name), and optionally just WARN. */
650 static void
651 report_file_and_line (file, line, warn)
652 const char *file;
653 int line;
654 int warn;
656 if (file)
657 fprintf (stderr, "%s:%d: ", file, line);
658 else
659 fprintf (stderr, "%s: ", progname);
661 if (warn)
662 notice ("warning: ");
665 /* Print a message relevant to line LINE of file FILE. */
667 static void
668 v_message_with_file_and_line (file, line, warn, msgid, ap)
669 const char *file;
670 int line;
671 int warn;
672 const char *msgid;
673 va_list ap;
675 report_file_and_line (file, line, warn);
676 vnotice (stderr, msgid, ap);
677 fputc ('\n', stderr);
680 /* Print a message relevant to the given DECL. */
682 static void
683 v_message_with_decl (decl, warn, msgid, ap)
684 tree decl;
685 int warn;
686 const char *msgid;
687 va_list ap;
689 const char *p;
690 output_buffer buffer;
692 if (doing_line_wrapping ())
694 init_output_buffer
695 (&buffer, build_location_prefix
696 (DECL_SOURCE_FILE (decl), DECL_SOURCE_LINE (decl), warn),
697 diagnostic_message_length_per_line);
699 else
700 report_file_and_line (DECL_SOURCE_FILE (decl),
701 DECL_SOURCE_LINE (decl), warn);
703 /* Do magic to get around lack of varargs support for insertion
704 of arguments into existing list. We know that the decl is first;
705 we ass_u_me that it will be printed with "%s". */
707 for (p = _(msgid); *p; ++p)
709 if (*p == '%')
711 if (*(p + 1) == '%')
712 ++p;
713 else if (*(p + 1) != 's')
714 abort ();
715 else
716 break;
720 if (p > _(msgid)) /* Print the left-hand substring. */
722 if (doing_line_wrapping ())
723 output_printf (&buffer, "%.*s", (int)(p - _(msgid)), _(msgid));
724 else
725 fprintf (stderr, "%.*s", (int)(p - _(msgid)), _(msgid));
728 if (*p == '%') /* Print the name. */
730 const char *n = (DECL_NAME (decl)
731 ? (*decl_printable_name) (decl, 2)
732 : "((anonymous))");
733 if (doing_line_wrapping ())
734 output_add_string (&buffer, n);
735 else
736 fputs (n, stderr);
737 while (*p)
739 ++p;
740 if (ISALPHA (*(p - 1) & 0xFF))
741 break;
745 if (*p) /* Print the rest of the message. */
747 if (doing_line_wrapping ())
749 va_copy (buffer.format_args, ap);
750 output_notice (&buffer, p);
751 va_copy (ap, buffer.format_args);
753 else
754 vfprintf (stderr, p, ap);
757 if (doing_line_wrapping())
759 output_flush_on (&buffer, stderr);
760 output_destroy_prefix (&buffer);
763 fputc ('\n', stderr);
766 /* Figure file and line of the given INSN. */
768 static void
769 file_and_line_for_asm (insn, pfile, pline)
770 rtx insn;
771 const char **pfile;
772 int *pline;
774 rtx body = PATTERN (insn);
775 rtx asmop;
777 /* Find the (or one of the) ASM_OPERANDS in the insn. */
778 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
779 asmop = SET_SRC (body);
780 else if (GET_CODE (body) == ASM_OPERANDS)
781 asmop = body;
782 else if (GET_CODE (body) == PARALLEL
783 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
784 asmop = SET_SRC (XVECEXP (body, 0, 0));
785 else if (GET_CODE (body) == PARALLEL
786 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
787 asmop = XVECEXP (body, 0, 0);
788 else
789 asmop = NULL;
791 if (asmop)
793 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
794 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
796 else
798 *pfile = input_filename;
799 *pline = lineno;
803 /* Report an error at line LINE of file FILE. */
805 static void
806 v_error_with_file_and_line (file, line, msgid, ap)
807 const char *file;
808 int line;
809 const char *msgid;
810 va_list ap;
812 count_error (0);
813 report_error_function (file);
814 if (doing_line_wrapping ())
815 vline_wrapper_message_with_location (file, line, 0, msgid, ap);
816 else
817 v_message_with_file_and_line (file, line, 0, msgid, ap);
820 /* Report an error at the declaration DECL.
821 MSGID is a format string which uses %s to substitute the declaration
822 name; subsequent substitutions are a la printf. */
824 static void
825 v_error_with_decl (decl, msgid, ap)
826 tree decl;
827 const char *msgid;
828 va_list ap;
830 count_error (0);
831 report_error_function (DECL_SOURCE_FILE (decl));
832 v_message_with_decl (decl, 0, msgid, ap);
836 /* Report an error at the line number of the insn INSN.
837 This is used only when INSN is an `asm' with operands,
838 and each ASM_OPERANDS records its own source file and line. */
840 static void
841 v_error_for_asm (insn, msgid, ap)
842 rtx insn;
843 const char *msgid;
844 va_list ap;
846 const char *file;
847 int line;
849 count_error (0);
850 file_and_line_for_asm (insn, &file, &line);
851 report_error_function (file);
852 v_message_with_file_and_line (file, line, 0, msgid, ap);
856 /* Report an error at the current line number. */
858 void
859 verror (msgid, ap)
860 const char *msgid;
861 va_list ap;
863 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
867 /* Report a fatal error at the current line number. Allow a front end to
868 intercept the message. */
870 static void (*fatal_function) PARAMS ((const char *, va_list));
872 static void
873 vfatal (msgid, ap)
874 const char *msgid;
875 va_list ap;
877 if (fatal_function != 0)
878 (*fatal_function) (_(msgid), ap);
880 verror (msgid, ap);
881 exit (FATAL_EXIT_CODE);
884 /* Report a warning at line LINE of file FILE. */
886 static void
887 v_warning_with_file_and_line (file, line, msgid, ap)
888 const char *file;
889 int line;
890 const char *msgid;
891 va_list ap;
893 if (count_error (1))
895 report_error_function (file);
896 if (doing_line_wrapping ())
897 vline_wrapper_message_with_location (file, line, 1, msgid, ap);
898 else
899 v_message_with_file_and_line (file, line, 1, msgid, ap);
904 /* Report a warning at the declaration DECL.
905 MSGID is a format string which uses %s to substitute the declaration
906 name; subsequent substitutions are a la printf. */
908 static void
909 v_warning_with_decl (decl, msgid, ap)
910 tree decl;
911 const char *msgid;
912 va_list ap;
914 if (count_error (1))
916 report_error_function (DECL_SOURCE_FILE (decl));
917 v_message_with_decl (decl, 1, msgid, ap);
922 /* Report a warning at the line number of the insn INSN.
923 This is used only when INSN is an `asm' with operands,
924 and each ASM_OPERANDS records its own source file and line. */
926 static void
927 v_warning_for_asm (insn, msgid, ap)
928 rtx insn;
929 const char *msgid;
930 va_list ap;
932 if (count_error (1))
934 const char *file;
935 int line;
937 file_and_line_for_asm (insn, &file, &line);
938 report_error_function (file);
939 v_message_with_file_and_line (file, line, 1, msgid, ap);
944 /* Report a warning at the current line number. */
946 void
947 vwarning (msgid, ap)
948 const char *msgid;
949 va_list ap;
951 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
954 /* These functions issue either warnings or errors depending on
955 -pedantic-errors. */
957 void
958 vpedwarn (msgid, ap)
959 const char *msgid;
960 va_list ap;
962 if (flag_pedantic_errors)
963 verror (msgid, ap);
964 else
965 vwarning (msgid, ap);
969 static void
970 v_pedwarn_with_decl (decl, msgid, ap)
971 tree decl;
972 const char *msgid;
973 va_list ap;
975 /* We don't want -pedantic-errors to cause the compilation to fail from
976 "errors" in system header files. Sometimes fixincludes can't fix what's
977 broken (eg: unsigned char bitfields - fixing it may change the alignment
978 which will cause programs to mysteriously fail because the C library
979 or kernel uses the original layout). There's no point in issuing a
980 warning either, it's just unnecessary noise. */
982 if (! DECL_IN_SYSTEM_HEADER (decl))
984 if (flag_pedantic_errors)
985 v_error_with_decl (decl, msgid, ap);
986 else
987 v_warning_with_decl (decl, msgid, ap);
992 static void
993 v_pedwarn_with_file_and_line (file, line, msgid, ap)
994 const char *file;
995 int line;
996 const char *msgid;
997 va_list ap;
999 if (flag_pedantic_errors)
1000 v_error_with_file_and_line (file, line, msgid, ap);
1001 else
1002 v_warning_with_file_and_line (file, line, msgid, ap);
1006 /* Apologize for not implementing some feature. */
1008 static void
1009 vsorry (msgid, ap)
1010 const char *msgid;
1011 va_list ap;
1013 sorrycount++;
1014 if (input_filename)
1015 fprintf (stderr, "%s:%d: ", input_filename, lineno);
1016 else
1017 fprintf (stderr, "%s: ", progname);
1018 notice ("sorry, not implemented: ");
1019 vnotice (stderr, msgid, ap);
1020 fputc ('\n', stderr);
1024 /* Count an error or warning. Return 1 if the message should be printed. */
1027 count_error (warningp)
1028 int warningp;
1030 if (warningp && inhibit_warnings)
1031 return 0;
1033 if (warningp && !warnings_are_errors)
1034 warningcount++;
1035 else
1037 static int warning_message = 0;
1039 if (warningp && !warning_message)
1041 notice ("%s: warnings being treated as errors\n", progname);
1042 warning_message = 1;
1044 errorcount++;
1047 return 1;
1050 /* Print a diagnistic MSGID on FILE. */
1051 void
1052 fnotice VPARAMS ((FILE *file, const char *msgid, ...))
1054 #ifndef ANSI_PROTOTYPES
1055 FILE *file;
1056 const char *msgid;
1057 #endif
1058 va_list ap;
1060 VA_START (ap, msgid);
1062 #ifndef ANSI_PROTOTYPES
1063 file = va_arg (ap, FILE *);
1064 msgid = va_arg (ap, const char *);
1065 #endif
1067 vnotice (file, msgid, ap);
1068 va_end (ap);
1072 /* Print a fatal error message. NAME is the text.
1073 Also include a system error message based on `errno'. */
1075 void
1076 pfatal_with_name (name)
1077 const char *name;
1079 fprintf (stderr, "%s: ", progname);
1080 perror (name);
1081 exit (FATAL_EXIT_CODE);
1084 void
1085 fatal_io_error (name)
1086 const char *name;
1088 notice ("%s: %s: I/O error\n", progname, name);
1089 exit (FATAL_EXIT_CODE);
1092 /* Issue a pedantic warning MSGID. */
1093 void
1094 pedwarn VPARAMS ((const char *msgid, ...))
1096 #ifndef ANSI_PROTOTYPES
1097 const char *msgid;
1098 #endif
1099 va_list ap;
1101 VA_START (ap, msgid);
1103 #ifndef ANSI_PROTOTYPES
1104 msgid = va_arg (ap, const char *);
1105 #endif
1107 vpedwarn (msgid, ap);
1108 va_end (ap);
1111 /* Issue a pedantic waring about DECL. */
1112 void
1113 pedwarn_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1115 #ifndef ANSI_PROTOTYPES
1116 tree decl;
1117 const char *msgid;
1118 #endif
1119 va_list ap;
1121 VA_START (ap, msgid);
1123 #ifndef ANSI_PROTOTYPES
1124 decl = va_arg (ap, tree);
1125 msgid = va_arg (ap, const char *);
1126 #endif
1128 v_pedwarn_with_decl (decl, msgid, ap);
1129 va_end (ap);
1132 /* Same as above but within the context FILE and LINE. */
1133 void
1134 pedwarn_with_file_and_line VPARAMS ((const char *file, int line,
1135 const char *msgid, ...))
1137 #ifndef ANSI_PROTOTYPES
1138 const char *file;
1139 int line;
1140 const char *msgid;
1141 #endif
1142 va_list ap;
1144 VA_START (ap, msgid);
1146 #ifndef ANSI_PROTOTYPES
1147 file = va_arg (ap, const char *);
1148 line = va_arg (ap, int);
1149 msgid = va_arg (ap, const char *);
1150 #endif
1152 v_pedwarn_with_file_and_line (file, line, msgid, ap);
1153 va_end (ap);
1156 /* Just apologize with MSGID. */
1157 void
1158 sorry VPARAMS ((const char *msgid, ...))
1160 #ifndef ANSI_PROTOTYPES
1161 const char *msgid;
1162 #endif
1163 va_list ap;
1165 VA_START (ap, msgid);
1167 #ifndef ANSI_PROTOTYPES
1168 msgid = va_arg (ap, const char *);
1169 #endif
1171 vsorry (msgid, ap);
1172 va_end (ap);
1175 /* Called when the start of a function definition is parsed,
1176 this function prints on stderr the name of the function. */
1178 void
1179 announce_function (decl)
1180 tree decl;
1182 if (! quiet_flag)
1184 if (rtl_dump_and_exit)
1185 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
1186 else
1188 if (doing_line_wrapping ())
1189 line_wrapper_printf
1190 (stderr, " %s", (*decl_printable_name) (decl, 2));
1191 else
1192 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
1194 fflush (stderr);
1195 need_error_newline = 1;
1196 last_error_function = current_function_decl;
1200 /* The default function to print out name of current function that caused
1201 an error. */
1203 void
1204 default_print_error_function (file)
1205 const char *file;
1207 if (last_error_function != current_function_decl)
1209 char *prefix = NULL;
1210 output_buffer buffer;
1212 if (file)
1213 prefix = build_message_string ("%s: ", file);
1215 if (doing_line_wrapping ())
1216 init_output_buffer
1217 (&buffer, prefix, diagnostic_message_length_per_line);
1218 else
1220 if (file)
1221 fprintf (stderr, "%s: ", file);
1224 if (current_function_decl == NULL)
1226 if (doing_line_wrapping ())
1227 output_printf (&buffer, "At top level:\n");
1228 else
1229 notice ("At top level:\n");
1231 else
1233 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
1235 if (doing_line_wrapping ())
1236 output_printf
1237 (&buffer, "In method `%s':\n",
1238 (*decl_printable_name) (current_function_decl, 2));
1239 else
1240 notice ("In method `%s':\n",
1241 (*decl_printable_name) (current_function_decl, 2));
1243 else
1245 if (doing_line_wrapping ())
1246 output_printf
1247 (&buffer, "In function `%s':\n",
1248 (*decl_printable_name) (current_function_decl, 2));
1249 else
1250 notice ("In function `%s':\n",
1251 (*decl_printable_name) (current_function_decl, 2));
1255 last_error_function = current_function_decl;
1257 if (doing_line_wrapping ())
1258 output_flush_on (&buffer, stderr);
1260 free ((char*) prefix);
1264 /* Prints out, if necessary, the name of the current function
1265 that caused an error. Called from all error and warning functions.
1266 We ignore the FILE parameter, as it cannot be relied upon. */
1268 void
1269 report_error_function (file)
1270 const char *file ATTRIBUTE_UNUSED;
1272 struct file_stack *p;
1274 if (need_error_newline)
1276 fprintf (stderr, "\n");
1277 need_error_newline = 0;
1280 if (input_file_stack && input_file_stack->next != 0
1281 && input_file_stack_tick != last_error_tick)
1283 for (p = input_file_stack->next; p; p = p->next)
1284 if (p == input_file_stack->next)
1285 notice ("In file included from %s:%d", p->name, p->line);
1286 else
1287 notice (",\n from %s:%d", p->name, p->line);
1288 fprintf (stderr, ":\n");
1289 last_error_tick = input_file_stack_tick;
1292 (*print_error_function) (input_filename);
1295 void
1296 error_with_file_and_line VPARAMS ((const char *file, int line,
1297 const char *msgid, ...))
1299 #ifndef ANSI_PROTOTYPES
1300 const char *file;
1301 int line;
1302 const char *msgid;
1303 #endif
1304 va_list ap;
1306 VA_START (ap, msgid);
1308 #ifndef ANSI_PROTOTYPES
1309 file = va_arg (ap, const char *);
1310 line = va_arg (ap, int);
1311 msgid = va_arg (ap, const char *);
1312 #endif
1314 v_error_with_file_and_line (file, line, msgid, ap);
1315 va_end (ap);
1318 void
1319 error_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1321 #ifndef ANSI_PROTOTYPES
1322 tree decl;
1323 const char *msgid;
1324 #endif
1325 va_list ap;
1327 VA_START (ap, msgid);
1329 #ifndef ANSI_PROTOTYPES
1330 decl = va_arg (ap, tree);
1331 msgid = va_arg (ap, const char *);
1332 #endif
1334 v_error_with_decl (decl, msgid, ap);
1335 va_end (ap);
1338 void
1339 error_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1341 #ifndef ANSI_PROTOTYPES
1342 rtx insn;
1343 const char *msgid;
1344 #endif
1345 va_list ap;
1347 VA_START (ap, msgid);
1349 #ifndef ANSI_PROTOTYPES
1350 insn = va_arg (ap, rtx);
1351 msgid = va_arg (ap, const char *);
1352 #endif
1354 v_error_for_asm (insn, msgid, ap);
1355 va_end (ap);
1358 void
1359 error VPARAMS ((const char *msgid, ...))
1361 #ifndef ANSI_PROTOTYPES
1362 const char *msgid;
1363 #endif
1364 va_list ap;
1366 VA_START (ap, msgid);
1368 #ifndef ANSI_PROTOTYPES
1369 msgid = va_arg (ap, const char *);
1370 #endif
1372 verror (msgid, ap);
1373 va_end (ap);
1376 /* Set the function to call when a fatal error occurs. */
1378 void
1379 set_fatal_function (f)
1380 void (*f) PARAMS ((const char *, va_list));
1382 fatal_function = f;
1385 void
1386 fatal VPARAMS ((const char *msgid, ...))
1388 #ifndef ANSI_PROTOTYPES
1389 const char *msgid;
1390 #endif
1391 va_list ap;
1393 VA_START (ap, msgid);
1395 #ifndef ANSI_PROTOTYPES
1396 msgid = va_arg (ap, const char *);
1397 #endif
1399 vfatal (msgid, ap);
1400 va_end (ap);
1403 void
1404 _fatal_insn (msgid, insn, file, line, function)
1405 const char *msgid;
1406 rtx insn;
1407 const char *file;
1408 int line;
1409 const char *function;
1411 error ("%s", msgid);
1412 debug_rtx (insn);
1413 fancy_abort (file, line, function);
1416 void
1417 _fatal_insn_not_found (insn, file, line, function)
1418 rtx insn;
1419 const char *file;
1420 int line;
1421 const char *function;
1423 if (INSN_CODE (insn) < 0)
1424 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
1425 else
1426 _fatal_insn ("Insn does not satisfy its constraints:",
1427 insn, file, line, function);
1430 void
1431 warning_with_file_and_line VPARAMS ((const char *file, int line,
1432 const char *msgid, ...))
1434 #ifndef ANSI_PROTOTYPES
1435 const char *file;
1436 int line;
1437 const char *msgid;
1438 #endif
1439 va_list ap;
1441 VA_START (ap, msgid);
1443 #ifndef ANSI_PROTOTYPES
1444 file = va_arg (ap, const char *);
1445 line = va_arg (ap, int);
1446 msgid = va_arg (ap, const char *);
1447 #endif
1449 v_warning_with_file_and_line (file, line, msgid, ap);
1450 va_end (ap);
1453 void
1454 warning_with_decl VPARAMS ((tree decl, const char *msgid, ...))
1456 #ifndef ANSI_PROTOTYPES
1457 tree decl;
1458 const char *msgid;
1459 #endif
1460 va_list ap;
1462 VA_START (ap, msgid);
1464 #ifndef ANSI_PROTOTYPES
1465 decl = va_arg (ap, tree);
1466 msgid = va_arg (ap, const char *);
1467 #endif
1469 v_warning_with_decl (decl, msgid, ap);
1470 va_end (ap);
1473 void
1474 warning_for_asm VPARAMS ((rtx insn, const char *msgid, ...))
1476 #ifndef ANSI_PROTOTYPES
1477 rtx insn;
1478 const char *msgid;
1479 #endif
1480 va_list ap;
1482 VA_START (ap, msgid);
1484 #ifndef ANSI_PROTOTYPES
1485 insn = va_arg (ap, rtx);
1486 msgid = va_arg (ap, const char *);
1487 #endif
1489 v_warning_for_asm (insn, msgid, ap);
1490 va_end (ap);
1493 void
1494 warning VPARAMS ((const char *msgid, ...))
1496 #ifndef ANSI_PROTOTYPES
1497 const char *msgid;
1498 #endif
1499 va_list ap;
1501 VA_START (ap, msgid);
1503 #ifndef ANSI_PROTOTYPES
1504 msgid = va_arg (ap, const char *);
1505 #endif
1507 vwarning (msgid, ap);
1508 va_end (ap);