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)
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
26 #undef FLOAT /* This is for hpux. They should change hpux. */
27 #undef FFS /* Some systems define this in param.h. */
35 #include "insn-attr.h"
36 #include "insn-codes.h"
37 #include "insn-config.h"
43 static void notice PVPROTO((const char *s, ...)) ATTRIBUTE_PRINTF_1;
44 static void vmessage PROTO((const char *, const char *, va_list));
45 static void v_message_with_file_and_line PROTO((const char *, int, int,
46 const char *, va_list));
47 static void v_message_with_decl PROTO((tree, int, const char *, va_list));
48 static void file_and_line_for_asm PROTO((rtx, char **, int *));
49 static void v_error_with_file_and_line PROTO((const char *, int,
50 const char *, va_list));
51 static void v_error_with_decl PROTO((tree, const char *, va_list));
52 static void v_error_for_asm PROTO((rtx, const char *, va_list));
53 static void verror PROTO((const char *, va_list));
54 static void vfatal PROTO((const char *, va_list)) ATTRIBUTE_NORETURN;
55 static void v_warning_with_file_and_line PROTO ((const char *, int,
56 const char *, va_list));
57 static void v_warning_with_decl PROTO((tree, const char *, va_list));
58 static void v_warning_for_asm PROTO((rtx, const char *, va_list));
59 static void vwarning PROTO((const char *, va_list));
60 static void vpedwarn PROTO((const char *, va_list));
61 static void v_pedwarn_with_decl PROTO((tree, const char *, va_list));
62 static void v_pedwarn_with_file_and_line PROTO((const char *, int,
63 const char *, va_list));
64 static void vsorry PROTO((const char *, va_list));
65 static void report_file_and_line PROTO ((const char *, int, int));
66 static void vnotice PROTO ((FILE *, const char *, va_list));
69 extern int rtl_dump_and_exit;
70 extern int inhibit_warnings;
71 extern int warnings_are_errors;
72 extern int warningcount;
73 extern int errorcount;
75 static int need_error_newline;
77 /* Function of last error message;
78 more generally, function such that if next error message is in it
79 then we don't have to mention the function name. */
80 static tree last_error_function = NULL;
82 /* Used to detect when input_file_stack has changed since last described. */
83 static int last_error_tick;
85 /* Called by report_error_function to print out function name.
86 * Default may be overridden by language front-ends. */
88 void (*print_error_function) PROTO((const char *)) =
89 default_print_error_function;
92 /* Print the message MSGID in FILE. */
95 vnotice (file, msgid, ap)
100 vfprintf (file, _(msgid), ap);
103 /* Print MSGID on stderr. */
106 notice VPROTO((const char *msgid, ...))
108 #ifndef ANSI_PROTOTYPES
113 VA_START (ap, msgid);
115 #ifndef ANSI_PROTOTYPES
116 msgid = va_arg (ap, char *);
119 vnotice (stderr, msgid, ap);
123 /* Report FILE and LINE (or program name), and optionally just WARN. */
126 report_file_and_line (file, line, warn)
132 fprintf (stderr, "%s:%d: ", file, line);
134 fprintf (stderr, "%s: ", progname);
137 notice ("warning: ");
140 /* Print a PREFIXed MSGID. */
143 vmessage (prefix, msgid, ap)
149 fprintf (stderr, "%s: ", prefix);
151 vfprintf (stderr, msgid, ap);
154 /* Print a message relevant to line LINE of file FILE. */
157 v_message_with_file_and_line (file, line, warn, msgid, ap)
164 report_file_and_line (file, line, warn);
165 vnotice (stderr, msgid, ap);
166 fputc ('\n', stderr);
169 /* Print a message relevant to the given DECL. */
172 v_message_with_decl (decl, warn, msgid, ap)
180 report_file_and_line (DECL_SOURCE_FILE (decl),
181 DECL_SOURCE_LINE (decl), warn);
183 /* Do magic to get around lack of varargs support for insertion
184 of arguments into existing list. We know that the decl is first;
185 we ass_u_me that it will be printed with "%s". */
187 for (p = _(msgid); *p; ++p)
193 else if (*(p + 1) != 's')
200 if (p > _(msgid)) /* Print the left-hand substring. */
201 fprintf (stderr, "%.*s", (int)(p - _(msgid)), _(msgid));
203 if (*p == '%') /* Print the name. */
205 const char *n = (DECL_NAME (decl)
206 ? (*decl_printable_name) (decl, 2)
212 if (ISALPHA (*(p - 1) & 0xFF))
217 if (*p) /* Print the rest of the message. */
218 vmessage ((char *)NULL, p, ap);
220 fputc ('\n', stderr);
223 /* Figure file and line of the given INSN. */
226 file_and_line_for_asm (insn, pfile, pline)
231 rtx body = PATTERN (insn);
234 /* Find the (or one of the) ASM_OPERANDS in the insn. */
235 if (GET_CODE (body) == SET && GET_CODE (SET_SRC (body)) == ASM_OPERANDS)
236 asmop = SET_SRC (body);
237 else if (GET_CODE (body) == ASM_OPERANDS)
239 else if (GET_CODE (body) == PARALLEL
240 && GET_CODE (XVECEXP (body, 0, 0)) == SET)
241 asmop = SET_SRC (XVECEXP (body, 0, 0));
242 else if (GET_CODE (body) == PARALLEL
243 && GET_CODE (XVECEXP (body, 0, 0)) == ASM_OPERANDS)
244 asmop = XVECEXP (body, 0, 0);
250 *pfile = ASM_OPERANDS_SOURCE_FILE (asmop);
251 *pline = ASM_OPERANDS_SOURCE_LINE (asmop);
255 *pfile = input_filename;
260 /* Report an error at line LINE of file FILE. */
263 v_error_with_file_and_line (file, line, msgid, ap)
270 report_error_function (file);
271 v_message_with_file_and_line (file, line, 0, msgid, ap);
274 /* Report an error at the declaration DECL.
275 MSGID is a format string which uses %s to substitute the declaration
276 name; subsequent substitutions are a la printf. */
279 v_error_with_decl (decl, msgid, ap)
285 report_error_function (DECL_SOURCE_FILE (decl));
286 v_message_with_decl (decl, 0, msgid, ap);
290 /* Report an error at the line number of the insn INSN.
291 This is used only when INSN is an `asm' with operands,
292 and each ASM_OPERANDS records its own source file and line. */
295 v_error_for_asm (insn, msgid, ap)
304 file_and_line_for_asm (insn, &file, &line);
305 report_error_function (file);
306 v_message_with_file_and_line (file, line, 0, msgid, ap);
310 /* Report an error at the current line number. */
317 v_error_with_file_and_line (input_filename, lineno, msgid, ap);
321 /* Report a fatal error at the current line number. Allow a front end to
322 intercept the message. */
324 static void (*fatal_function) PROTO ((const char *, va_list));
331 if (fatal_function != 0)
332 (*fatal_function) (_(msgid), ap);
335 exit (FATAL_EXIT_CODE);
338 /* Report a warning at line LINE of file FILE. */
341 v_warning_with_file_and_line (file, line, msgid, ap)
349 report_error_function (file);
350 v_message_with_file_and_line (file, line, 1, msgid, ap);
355 /* Report a warning at the declaration DECL.
356 MSGID is a format string which uses %s to substitute the declaration
357 name; subsequent substitutions are a la printf. */
360 v_warning_with_decl (decl, msgid, ap)
367 report_error_function (DECL_SOURCE_FILE (decl));
368 v_message_with_decl (decl, 1, msgid, ap);
373 /* Report a warning at the line number of the insn INSN.
374 This is used only when INSN is an `asm' with operands,
375 and each ASM_OPERANDS records its own source file and line. */
378 v_warning_for_asm (insn, msgid, ap)
388 file_and_line_for_asm (insn, &file, &line);
389 report_error_function (file);
390 v_message_with_file_and_line (file, line, 1, msgid, ap);
395 /* Report a warning at the current line number. */
402 v_warning_with_file_and_line (input_filename, lineno, msgid, ap);
405 /* These functions issue either warnings or errors depending on
413 if (flag_pedantic_errors)
416 vwarning (msgid, ap);
421 v_pedwarn_with_decl (decl, msgid, ap)
426 /* We don't want -pedantic-errors to cause the compilation to fail from
427 "errors" in system header files. Sometimes fixincludes can't fix what's
428 broken (eg: unsigned char bitfields - fixing it may change the alignment
429 which will cause programs to mysteriously fail because the C library
430 or kernel uses the original layout). There's no point in issuing a
431 warning either, it's just unnecessary noise. */
433 if (! DECL_IN_SYSTEM_HEADER (decl))
435 if (flag_pedantic_errors)
436 v_error_with_decl (decl, msgid, ap);
438 v_warning_with_decl (decl, msgid, ap);
444 v_pedwarn_with_file_and_line (file, line, msgid, ap)
450 if (flag_pedantic_errors)
451 v_error_with_file_and_line (file, line, msgid, ap);
453 v_warning_with_file_and_line (file, line, msgid, ap);
457 /* Apologize for not implementing some feature. */
466 fprintf (stderr, "%s:%d: ", input_filename, lineno);
468 fprintf (stderr, "%s: ", progname);
469 notice ("sorry, not implemented: ");
470 vnotice (stderr, msgid, ap);
471 fputc ('\n', stderr);
475 /* Count an error or warning. Return 1 if the message should be printed. */
478 count_error (warningp)
481 if (warningp && inhibit_warnings)
484 if (warningp && !warnings_are_errors)
488 static int warning_message = 0;
490 if (warningp && !warning_message)
492 notice ("%s: warnings being treated as errors\n", progname);
501 /* Print a diagnistic MSGID on FILE. */
503 fnotice VPROTO((FILE *file, const char *msgid, ...))
505 #ifndef ANSI_PROTOTYPES
511 VA_START (ap, msgid);
513 #ifndef ANSI_PROTOTYPES
514 file = va_arg (ap, FILE *);
515 msgid = va_arg (ap, const char *);
518 vnotice (file, msgid, ap);
523 /* Print a fatal error message. NAME is the text.
524 Also include a system error message based on `errno'. */
527 pfatal_with_name (name)
530 fprintf (stderr, "%s: ", progname);
532 exit (FATAL_EXIT_CODE);
536 fatal_io_error (name)
539 notice ("%s: %s: I/O error\n", progname, name);
540 exit (FATAL_EXIT_CODE);
543 /* Issue a pedantic warning MSGID. */
545 pedwarn VPROTO((const char *msgid, ...))
547 #ifndef ANSI_PROTOTYPES
552 VA_START (ap, msgid);
554 #ifndef ANSI_PROTOTYPES
555 msgid = va_arg (ap, const char *);
558 vpedwarn (msgid, ap);
562 /* Issue a pedantic waring about DECL. */
564 pedwarn_with_decl VPROTO((tree decl, const char *msgid, ...))
566 #ifndef ANSI_PROTOTYPES
572 VA_START (ap, msgid);
574 #ifndef ANSI_PROTOTYPES
575 decl = va_arg (ap, tree);
576 msgid = va_arg (ap, const char *);
579 v_pedwarn_with_decl (decl, msgid, ap);
583 /* Same as above but within the context FILE and LINE. */
585 pedwarn_with_file_and_line VPROTO((const char *file, int line,
586 const char *msgid, ...))
588 #ifndef ANSI_PROTOTYPES
595 VA_START (ap, msgid);
597 #ifndef ANSI_PROTOTYPES
598 file = va_arg (ap, const char *);
599 line = va_arg (ap, int);
600 msgid = va_arg (ap, const char *);
603 v_pedwarn_with_file_and_line (file, line, msgid, ap);
607 /* Just apologize with MSGID. */
609 sorry VPROTO((const char *msgid, ...))
611 #ifndef ANSI_PROTOTYPES
616 VA_START (ap, msgid);
618 #ifndef ANSI_PROTOTYPES
619 msgid = va_arg (ap, const char *);
626 /* Called when the start of a function definition is parsed,
627 this function prints on stderr the name of the function. */
630 announce_function (decl)
635 if (rtl_dump_and_exit)
636 fprintf (stderr, "%s ", IDENTIFIER_POINTER (DECL_NAME (decl)));
638 fprintf (stderr, " %s", (*decl_printable_name) (decl, 2));
640 need_error_newline = 1;
641 last_error_function = current_function_decl;
645 /* The default function to print out name of current function that caused
649 default_print_error_function (file)
652 if (last_error_function != current_function_decl)
655 fprintf (stderr, "%s: ", file);
657 if (current_function_decl == NULL)
658 notice ("At top level:\n");
661 if (TREE_CODE (TREE_TYPE (current_function_decl)) == METHOD_TYPE)
662 notice ("In method `%s':\n",
663 (*decl_printable_name) (current_function_decl, 2));
665 notice ("In function `%s':\n",
666 (*decl_printable_name) (current_function_decl, 2));
669 last_error_function = current_function_decl;
673 /* Prints out, if necessary, the name of the current function
674 that caused an error. Called from all error and warning functions.
675 We ignore the FILE parameter, as it cannot be relied upon. */
678 report_error_function (file)
679 const char *file ATTRIBUTE_UNUSED;
681 struct file_stack *p;
683 if (need_error_newline)
685 fprintf (stderr, "\n");
686 need_error_newline = 0;
689 if (input_file_stack && input_file_stack->next != 0
690 && input_file_stack_tick != last_error_tick)
692 for (p = input_file_stack->next; p; p = p->next)
693 if (p == input_file_stack->next)
694 notice ("In file included from %s:%d", p->name, p->line);
696 notice (",\n from %s:%d", p->name, p->line);
697 fprintf (stderr, ":\n");
698 last_error_tick = input_file_stack_tick;
701 (*print_error_function) (input_filename);
705 error_with_file_and_line VPROTO((const char *file, int line,
706 const char *msgid, ...))
708 #ifndef ANSI_PROTOTYPES
715 VA_START (ap, msgid);
717 #ifndef ANSI_PROTOTYPES
718 file = va_arg (ap, const char *);
719 line = va_arg (ap, int);
720 msgid = va_arg (ap, const char *);
723 v_error_with_file_and_line (file, line, msgid, ap);
728 error_with_decl VPROTO((tree decl, const char *msgid, ...))
730 #ifndef ANSI_PROTOTYPES
736 VA_START (ap, msgid);
738 #ifndef ANSI_PROTOTYPES
739 decl = va_arg (ap, tree);
740 msgid = va_arg (ap, const char *);
743 v_error_with_decl (decl, msgid, ap);
748 error_for_asm VPROTO((rtx insn, const char *msgid, ...))
750 #ifndef ANSI_PROTOTYPES
756 VA_START (ap, msgid);
758 #ifndef ANSI_PROTOTYPES
759 insn = va_arg (ap, rtx);
760 msgid = va_arg (ap, const char *);
763 v_error_for_asm (insn, msgid, ap);
768 error VPROTO((const char *msgid, ...))
770 #ifndef ANSI_PROTOTYPES
775 VA_START (ap, msgid);
777 #ifndef ANSI_PROTOTYPES
778 msgid = va_arg (ap, const char *);
785 /* Set the function to call when a fatal error occurs. */
788 set_fatal_function (f)
789 void (*f) PROTO ((const char *, va_list));
795 fatal VPROTO((const char *msgid, ...))
797 #ifndef ANSI_PROTOTYPES
802 VA_START (ap, msgid);
804 #ifndef ANSI_PROTOTYPES
805 msgid = va_arg (ap, const char *);
813 _fatal_insn (msgid, insn, file, line, function)
818 const char *function;
822 fancy_abort (file, line, function);
826 _fatal_insn_not_found (insn, file, line, function)
830 const char *function;
832 if (INSN_CODE (insn) < 0)
833 _fatal_insn ("Unrecognizable insn:", insn, file, line, function);
835 _fatal_insn ("Insn does not satisfy its constraints:",
836 insn, file, line, function);
840 warning_with_file_and_line VPROTO((const char *file, int line,
841 const char *msgid, ...))
843 #ifndef ANSI_PROTOTYPES
850 VA_START (ap, msgid);
852 #ifndef ANSI_PROTOTYPES
853 file = va_arg (ap, const char *);
854 line = va_arg (ap, int);
855 msgid = va_arg (ap, const char *);
858 v_warning_with_file_and_line (file, line, msgid, ap);
863 warning_with_decl VPROTO((tree decl, const char *msgid, ...))
865 #ifndef ANSI_PROTOTYPES
871 VA_START (ap, msgid);
873 #ifndef ANSI_PROTOTYPES
874 decl = va_arg (ap, tree);
875 msgid = va_arg (ap, const char *);
878 v_warning_with_decl (decl, msgid, ap);
883 warning_for_asm VPROTO((rtx insn, const char *msgid, ...))
885 #ifndef ANSI_PROTOTYPES
891 VA_START (ap, msgid);
893 #ifndef ANSI_PROTOTYPES
894 insn = va_arg (ap, rtx);
895 msgid = va_arg (ap, const char *);
898 v_warning_for_asm (insn, msgid, ap);
903 warning VPROTO((const char *msgid, ...))
905 #ifndef ANSI_PROTOTYPES
910 VA_START (ap, msgid);
912 #ifndef ANSI_PROTOTYPES
913 msgid = va_arg (ap, const char *);
916 vwarning (msgid, ap);