1 /* Language-independent diagnostic subroutines for the GNU C compiler
2 Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
3 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
5 This file is part of GNU CC.
7 GNU CC is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 2, or (at your option)
12 GNU CC is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with GNU CC; see the file COPYING. If not, write to
19 the Free Software Foundation, 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
23 /* This file implements the language independent aspect of diagnostic
27 #undef FLOAT /* This is for hpux. They should change hpux. */
28 #undef FFS /* Some systems define this in param.h. */
36 #include "insn-attr.h"
37 #include "insn-config.h"
40 #include "diagnostic.h"
42 #define obstack_chunk_alloc xmalloc
43 #define obstack_chunk_free free
45 #define output_formatted_integer(BUFFER, FORMAT, INTEGER) \
47 sprintf (digit_buffer, FORMAT, INTEGER); \
48 output_add_string (BUFFER, digit_buffer); \
51 #define output_text_length(BUFFER) (BUFFER)->line_length
52 #define is_starting_newline(BUFFER) (output_text_length (BUFFER) == 0)
53 #define output_prefix(BUFFER) (BUFFER)->state.prefix
54 #define line_wrap_cutoff(BUFFER) (BUFFER)->state.maximum_length
55 #define ideal_line_wrap_cutoff(BUFFER) (BUFFER)->state.ideal_maximum_length
56 #define prefix_was_emitted_for(BUFFER) (BUFFER)->state.emitted_prefix_p
57 #define prefixing_policy(BUFFER) (BUFFER)->state.prefixing_rule
58 #define output_buffer_ptr_to_format_args(BUFFER) (BUFFER)->state.format_args
60 #define diagnostic_args output_buffer_ptr_to_format_args (diagnostic_buffer)
61 #define diagnostic_msg output_buffer_text_cursor (diagnostic_buffer)
64 static void finish_diagnostic
PARAMS ((void));
65 static void output_do_verbatim
PARAMS ((output_buffer
*,
66 const char *, va_list *));
67 static void output_buffer_to_stream
PARAMS ((output_buffer
*));
68 static void output_format
PARAMS ((output_buffer
*));
69 static void output_indent
PARAMS ((output_buffer
*));
71 static char *vbuild_message_string
PARAMS ((const char *, va_list))
72 ATTRIBUTE_PRINTF (1, 0);
73 static char *build_message_string
PARAMS ((const char *, ...))
75 static void output_do_printf
PARAMS ((output_buffer
*, const char *))
76 ATTRIBUTE_PRINTF (2, 0);
77 static void format_with_decl
PARAMS ((output_buffer
*, tree
));
78 static void file_and_line_for_asm
PARAMS ((rtx
, const char **, int *));
79 static void diagnostic_for_asm
PARAMS ((rtx
, const char *, va_list *, int));
80 static void diagnostic_for_decl
PARAMS ((tree
, const char *, va_list *, int));
81 static void vnotice
PARAMS ((FILE *, const char *, va_list))
82 ATTRIBUTE_PRINTF (2, 0);
83 static void set_real_maximum_length
PARAMS ((output_buffer
*));
85 static void output_unsigned_decimal
PARAMS ((output_buffer
*, unsigned int));
86 static void output_long_decimal
PARAMS ((output_buffer
*, long int));
87 static void output_long_unsigned_decimal
PARAMS ((output_buffer
*,
89 static void output_octal
PARAMS ((output_buffer
*, unsigned int));
90 static void output_long_octal
PARAMS ((output_buffer
*, unsigned long int));
91 static void output_hexadecimal
PARAMS ((output_buffer
*, unsigned int));
92 static void output_long_hexadecimal
PARAMS ((output_buffer
*,
94 static void output_append_r
PARAMS ((output_buffer
*, const char *, int));
95 static void wrap_text
PARAMS ((output_buffer
*, const char *, const char *));
96 static void maybe_wrap_text
PARAMS ((output_buffer
*, const char *,
98 static void clear_diagnostic_info
PARAMS ((output_buffer
*));
100 static void default_diagnostic_starter
PARAMS ((output_buffer
*,
101 diagnostic_context
*));
102 static void default_diagnostic_finalizer
PARAMS ((output_buffer
*,
103 diagnostic_context
*));
105 static void error_recursion
PARAMS ((void)) ATTRIBUTE_NORETURN
;
107 extern int rtl_dump_and_exit
;
108 extern int inhibit_warnings
;
109 extern int warnings_are_errors
;
110 extern int warningcount
;
111 extern int errorcount
;
113 /* Front-end specific tree formatter, if non-NULL. */
114 printer_fn lang_printer
= NULL
;
116 /* This must be large enough to hold any printed integer or
117 floating-point value. */
118 static char digit_buffer
[128];
120 /* An output_buffer surrogate for stderr. */
121 static output_buffer global_output_buffer
;
122 output_buffer
*diagnostic_buffer
= &global_output_buffer
;
124 /* Function of last error message;
125 more generally, function such that if next error message is in it
126 then we don't have to mention the function name. */
127 static tree last_error_function
= NULL
;
129 /* Used to detect when input_file_stack has changed since last described. */
130 static int last_error_tick
;
132 /* Called by report_error_function to print out function name.
133 Default may be overridden by language front-ends. */
135 void (*print_error_function
) PARAMS ((const char *)) =
136 default_print_error_function
;
138 /* Hooks for language specific diagnostic messages pager and finalizer. */
139 diagnostic_starter_fn lang_diagnostic_starter
;
140 diagnostic_finalizer_fn lang_diagnostic_finalizer
;
142 /* Maximum characters per line in automatic line wrapping mode.
143 Zero means don't wrap lines. */
145 int diagnostic_message_length_per_line
;
147 /* Used to control every diagnostic message formatting. Front-ends should
148 call set_message_prefixing_rule to set up their policies. */
149 static int current_prefixing_rule
;
151 /* Prevent recursion into the error handler. */
152 static int diagnostic_lock
;
155 /* Return truthvalue if current input file is different from the most recent
156 file involved in a diagnostic message. */
159 error_module_changed ()
161 return last_error_tick
!= input_file_stack_tick
;
164 /* Remember current file as being the most recent file involved in a
165 diagnostic message. */
168 record_last_error_module ()
170 last_error_tick
= input_file_stack_tick
;
173 /* Same as error_module_changed, but for function. */
176 error_function_changed ()
178 return last_error_function
!= current_function_decl
;
181 /* Same as record_last_error_module, but for function. */
184 record_last_error_function ()
186 last_error_function
= current_function_decl
;
189 /* Initialize the diagnostic message outputting machinery. */
192 initialize_diagnostics ()
194 /* By default, we don't line-wrap messages. */
195 diagnostic_message_length_per_line
= 0;
196 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE
);
198 /* Proceed to actual initialization. */
199 default_initialize_buffer (diagnostic_buffer
);
201 lang_diagnostic_starter
= default_diagnostic_starter
;
202 lang_diagnostic_finalizer
= default_diagnostic_finalizer
;
206 set_message_prefixing_rule (rule
)
209 current_prefixing_rule
= rule
;
212 /* Returns true if BUFFER is in line-wrappind mode. */
215 output_is_line_wrapping (buffer
)
216 output_buffer
*buffer
;
218 return ideal_line_wrap_cutoff (buffer
) > 0;
221 /* Return BUFFER's prefix. */
224 output_get_prefix (buffer
)
225 const output_buffer
*buffer
;
227 return output_prefix (buffer
);
230 /* Subroutine of output_set_maximum_length. Set up BUFFER's
231 internal maximum characters per line. */
234 set_real_maximum_length (buffer
)
235 output_buffer
*buffer
;
237 /* If we're told not to wrap lines then do the obvious thing. In case
238 we'll emit prefix only once per diagnostic message, it is appropriate
239 not to increase unncessarily the line-length cut-off. */
240 if (! output_is_line_wrapping (buffer
)
241 || prefixing_policy (buffer
) == DIAGNOSTICS_SHOW_PREFIX_ONCE
242 || prefixing_policy (buffer
) == DIAGNOSTICS_SHOW_PREFIX_NEVER
)
243 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
);
247 output_prefix (buffer
) ? strlen (output_prefix (buffer
)) : 0;
248 /* If the prefix is ridiculously too long, output at least
250 if (ideal_line_wrap_cutoff (buffer
) - prefix_length
< 32)
251 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
) + 32;
253 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
);
257 /* Sets the number of maximum characters per line BUFFER can output
258 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
261 output_set_maximum_length (buffer
, length
)
262 output_buffer
*buffer
;
265 ideal_line_wrap_cutoff (buffer
) = length
;
266 set_real_maximum_length (buffer
);
269 /* Sets BUFFER's PREFIX. */
272 output_set_prefix (buffer
, prefix
)
273 output_buffer
*buffer
;
276 output_prefix (buffer
) = prefix
;
277 set_real_maximum_length (buffer
);
278 prefix_was_emitted_for (buffer
) = 0;
279 output_indentation (buffer
) = 0;
282 /* Return a pointer to the last character emitted in the output
283 BUFFER area. A NULL pointer means no character available. */
285 output_last_position (buffer
)
286 const output_buffer
*buffer
;
288 const char *p
= NULL
;
290 if (obstack_base (&buffer
->obstack
) != obstack_next_free (&buffer
->obstack
))
291 p
= ((const char *) obstack_next_free (&buffer
->obstack
)) - 1;
295 /* Free BUFFER's prefix, a previously malloc'd string. */
298 output_destroy_prefix (buffer
)
299 output_buffer
*buffer
;
301 if (output_prefix (buffer
) != NULL
)
303 free ((char *) output_prefix (buffer
));
304 output_prefix (buffer
) = NULL
;
308 /* Zero out any text output so far in BUFFER. */
311 output_clear_message_text (buffer
)
312 output_buffer
*buffer
;
314 obstack_free (&buffer
->obstack
, obstack_base (&buffer
->obstack
));
315 output_text_length (buffer
) = 0;
318 /* Zero out any diagnostic data used so far by BUFFER. */
321 clear_diagnostic_info (buffer
)
322 output_buffer
*buffer
;
324 output_buffer_text_cursor (buffer
) = NULL
;
325 output_buffer_ptr_to_format_args (buffer
) = NULL
;
326 prefix_was_emitted_for (buffer
) = 0;
327 output_indentation (buffer
) = 0;
330 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
331 characters per line. */
334 init_output_buffer (buffer
, prefix
, maximum_length
)
335 output_buffer
*buffer
;
339 memset (buffer
, 0, sizeof (output_buffer
));
340 obstack_init (&buffer
->obstack
);
341 output_buffer_attached_stream (buffer
) = stderr
;
342 ideal_line_wrap_cutoff (buffer
) = maximum_length
;
343 prefixing_policy (buffer
) = current_prefixing_rule
;
344 output_set_prefix (buffer
, prefix
);
345 output_text_length (buffer
) = 0;
346 clear_diagnostic_info (buffer
);
349 /* Initialize BUFFER with a NULL prefix and current diagnostic message
353 default_initialize_buffer (buffer
)
354 output_buffer
*buffer
;
356 init_output_buffer (buffer
, NULL
, diagnostic_message_length_per_line
);
359 /* Recompute diagnostic_buffer's attributes to reflect any change
360 in diagnostic formatting global options. */
363 reshape_diagnostic_buffer ()
365 ideal_line_wrap_cutoff (diagnostic_buffer
) =
366 diagnostic_message_length_per_line
;
367 prefixing_policy (diagnostic_buffer
) = current_prefixing_rule
;
368 set_real_maximum_length (diagnostic_buffer
);
371 /* Reinitialize BUFFER. */
374 output_clear (buffer
)
375 output_buffer
*buffer
;
377 output_clear_message_text (buffer
);
378 clear_diagnostic_info (buffer
);
381 /* Finishes constructing a NULL-terminated character string representing
382 the BUFFERed message. */
385 output_finalize_message (buffer
)
386 output_buffer
*buffer
;
388 obstack_1grow (&buffer
->obstack
, '\0');
389 return output_message_text (buffer
);
393 flush_diagnostic_buffer ()
395 output_buffer_to_stream (diagnostic_buffer
);
396 fflush (output_buffer_attached_stream (diagnostic_buffer
));
399 /* Return the amount of characters BUFFER can accept to
403 output_space_left (buffer
)
404 const output_buffer
*buffer
;
406 return line_wrap_cutoff (buffer
) - output_text_length (buffer
);
409 /* Write out BUFFER's prefix. */
412 output_emit_prefix (buffer
)
413 output_buffer
*buffer
;
415 if (output_prefix (buffer
) != NULL
)
417 switch (prefixing_policy (buffer
))
420 case DIAGNOSTICS_SHOW_PREFIX_NEVER
:
423 case DIAGNOSTICS_SHOW_PREFIX_ONCE
:
424 if (prefix_was_emitted_for (buffer
))
426 output_indent (buffer
);
429 output_indentation (buffer
) += 3;
432 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE
:
434 int prefix_length
= strlen (output_prefix (buffer
));
435 output_append_r (buffer
, output_prefix (buffer
), prefix_length
);
436 prefix_was_emitted_for (buffer
) = 1;
443 /* Have BUFFER start a new line. */
446 output_add_newline (buffer
)
447 output_buffer
*buffer
;
449 obstack_1grow (&buffer
->obstack
, '\n');
450 output_text_length (buffer
) = 0;
453 /* Appends a character to BUFFER. */
456 output_add_character (buffer
, c
)
457 output_buffer
*buffer
;
460 if (output_is_line_wrapping (buffer
) && output_space_left (buffer
) <= 0)
461 output_add_newline (buffer
);
462 obstack_1grow (&buffer
->obstack
, c
);
463 ++output_text_length (buffer
);
466 /* Adds a space to BUFFER. */
469 output_add_space (buffer
)
470 output_buffer
*buffer
;
472 if (output_is_line_wrapping (buffer
) && output_space_left (buffer
) <= 0)
474 output_add_newline (buffer
);
477 obstack_1grow (&buffer
->obstack
, ' ');
478 ++output_text_length (buffer
);
481 /* These functions format an INTEGER into BUFFER as suggested by their
485 output_decimal (buffer
, i
)
486 output_buffer
*buffer
;
489 output_formatted_integer (buffer
, "%d", i
);
493 output_long_decimal (buffer
, i
)
494 output_buffer
*buffer
;
497 output_formatted_integer (buffer
, "%ld", i
);
501 output_unsigned_decimal (buffer
, i
)
502 output_buffer
*buffer
;
505 output_formatted_integer (buffer
, "%u", i
);
509 output_long_unsigned_decimal (buffer
, i
)
510 output_buffer
*buffer
;
513 output_formatted_integer (buffer
, "%lu", i
);
517 output_octal (buffer
, i
)
518 output_buffer
*buffer
;
521 output_formatted_integer (buffer
, "%o", i
);
525 output_long_octal (buffer
, i
)
526 output_buffer
*buffer
;
529 output_formatted_integer (buffer
, "%lo", i
);
533 output_hexadecimal (buffer
, i
)
534 output_buffer
*buffer
;
537 output_formatted_integer (buffer
, "%x", i
);
541 output_long_hexadecimal (buffer
, i
)
542 output_buffer
*buffer
;
545 output_formatted_integer (buffer
, "%lx", i
);
548 /* Append to BUFFER a string specified by its STARTING character
552 output_append_r (buffer
, start
, length
)
553 output_buffer
*buffer
;
557 obstack_grow (&buffer
->obstack
, start
, length
);
558 output_text_length (buffer
) += length
;
561 /* Append a string deliminated by START and END to BUFFER. No wrapping is
562 done. However, if beginning a new line then emit output_prefix (BUFFER)
563 and skip any leading whitespace if appropriate. The caller must ensure
564 that it is safe to do so. */
567 output_append (buffer
, start
, end
)
568 output_buffer
*buffer
;
572 /* Emit prefix and skip whitespace if we're starting a new line. */
573 if (is_starting_newline (buffer
))
575 output_emit_prefix (buffer
);
576 if (output_is_line_wrapping (buffer
))
577 while (start
!= end
&& *start
== ' ')
580 output_append_r (buffer
, start
, end
- start
);
584 output_indent (buffer
)
585 output_buffer
*buffer
;
587 int n
= output_indentation (buffer
);
590 for (i
= 0; i
< n
; ++i
)
591 output_add_character (buffer
, ' ');
594 /* Wrap a text delimited by START and END into BUFFER. */
597 wrap_text (buffer
, start
, end
)
598 output_buffer
*buffer
;
602 int is_wrapping
= output_is_line_wrapping (buffer
);
606 /* Dump anything bodered by whitespaces. */
608 const char *p
= start
;
609 while (p
!= end
&& *p
!= ' ' && *p
!= '\n')
611 if (is_wrapping
&& p
- start
>= output_space_left (buffer
))
612 output_add_newline (buffer
);
613 output_append (buffer
, start
, p
);
617 if (start
!= end
&& *start
== ' ')
619 output_add_space (buffer
);
622 if (start
!= end
&& *start
== '\n')
624 output_add_newline (buffer
);
630 /* Same as wrap_text but wrap text only when in line-wrapping mode. */
633 maybe_wrap_text (buffer
, start
, end
)
634 output_buffer
*buffer
;
638 if (output_is_line_wrapping (buffer
))
639 wrap_text (buffer
, start
, end
);
641 output_append (buffer
, start
, end
);
645 /* Append a STRING to BUFFER; the STRING might be line-wrapped if in
649 output_add_string (buffer
, str
)
650 output_buffer
*buffer
;
653 maybe_wrap_text (buffer
, str
, str
+ (str
? strlen (str
) : 0));
656 /* Flush the content of BUFFER onto the attached stream,
660 output_buffer_to_stream (buffer
)
661 output_buffer
*buffer
;
663 const char *text
= output_finalize_message (buffer
);
664 fputs (text
, output_buffer_attached_stream (buffer
));
665 output_clear_message_text (buffer
);
668 /* Format a message pointed to by output_buffer_text_cursor (BUFFER) using
669 output_buffer_format_args (BUFFER) as appropriate. The following format
670 specifiers are recognized as being language independent:
671 %d, %i: (signed) integer in base ten.
672 %u: unsigned integer in base ten.
673 %o: unsigned integer in base eight.
674 %x: unsigned integer in base sixteen.
675 %ld, %li, %lo, %lu, %lx: long versions of the above.
679 %*.s: a substring the length of which is specified by an integer. */
682 output_format (buffer
)
683 output_buffer
*buffer
;
685 for (; *output_buffer_text_cursor (buffer
);
686 ++output_buffer_text_cursor (buffer
))
688 int long_integer
= 0;
692 const char *p
= output_buffer_text_cursor (buffer
);
693 while (*p
&& *p
!= '%')
695 wrap_text (buffer
, output_buffer_text_cursor (buffer
), p
);
696 output_buffer_text_cursor (buffer
) = p
;
699 if (!*output_buffer_text_cursor (buffer
))
702 /* We got a '%'. Let's see what happens. Record whether we're
703 parsing a long integer format specifier. */
704 if (*++output_buffer_text_cursor (buffer
) == 'l')
707 ++output_buffer_text_cursor (buffer
);
710 /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %o, %s, %u,
711 %x, %.*s; %%. And nothing else. Front-ends should install
712 printers to grok language specific format specifiers. */
713 switch (*output_buffer_text_cursor (buffer
))
717 (buffer
, va_arg (output_buffer_format_args (buffer
), int));
724 (buffer
, va_arg (output_buffer_format_args (buffer
), long int));
727 (buffer
, va_arg (output_buffer_format_args (buffer
), int));
732 output_long_octal (buffer
,
733 va_arg (output_buffer_format_args (buffer
),
736 output_octal (buffer
,
737 va_arg (output_buffer_format_args (buffer
),
742 output_add_string (buffer
,
743 va_arg (output_buffer_format_args (buffer
),
749 output_long_unsigned_decimal
750 (buffer
, va_arg (output_buffer_format_args (buffer
),
753 output_unsigned_decimal
754 (buffer
, va_arg (output_buffer_format_args (buffer
),
760 output_long_hexadecimal
761 (buffer
, va_arg (output_buffer_format_args (buffer
),
765 (buffer
, va_arg (output_buffer_format_args (buffer
),
770 output_add_character (buffer
, '%');
777 /* We handle no precision specifier but `%.*s'. */
778 if (*++output_buffer_text_cursor (buffer
) != '*')
780 else if (*++output_buffer_text_cursor (buffer
) != 's')
782 n
= va_arg (output_buffer_format_args (buffer
), int);
783 s
= va_arg (output_buffer_format_args (buffer
), const char *);
784 output_append (buffer
, s
, s
+ n
);
789 if (! lang_printer
|| !(*lang_printer
) (buffer
))
791 /* Hmmm. The front-end failed to install a format translator
792 but called us with an unrecognized format. Sorry. */
800 vbuild_message_string (msgid
, ap
)
806 vasprintf (&str
, msgid
, ap
);
810 /* Return a malloc'd string containing MSGID formatted a la
811 printf. The caller is reponsible for freeing the memory. */
814 build_message_string
VPARAMS ((const char *msgid
, ...))
816 #ifndef ANSI_PROTOTYPES
822 VA_START (ap
, msgid
);
824 #ifndef ANSI_PROTOTYPES
825 msgid
= va_arg (ap
, const char *);
828 str
= vbuild_message_string (msgid
, ap
);
835 /* Return a malloc'd string describing a location. The caller is
836 responsible for freeing the memory. */
839 context_as_prefix (file
, line
, warn
)
847 return build_message_string ("%s:%d: warning: ", file
, line
);
849 return build_message_string ("%s:%d: ", file
, line
);
854 return build_message_string ("%s: warning: ", progname
);
856 return build_message_string ("%s: ", progname
);
860 /* Same as context_as_prefix, but only the source FILE is given. */
863 file_name_as_prefix (f
)
866 return build_message_string ("%s: ", f
);
869 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
872 output_do_printf (buffer
, msgid
)
873 output_buffer
*buffer
;
876 char *message
= vbuild_message_string (msgid
,
877 output_buffer_format_args (buffer
));
879 wrap_text (buffer
, message
, message
+ strlen (message
));
884 /* Format a message into BUFFER a la printf. */
887 output_printf
VPARAMS ((struct output_buffer
*buffer
, const char *msgid
, ...))
889 #ifndef ANSI_PROTOTYPES
890 struct output_buffer
*buffer
;
896 VA_START (ap
, msgid
);
897 #ifndef ANSI_PROTOTYPES
898 buffer
= va_arg (ap
, output_buffer
*);
899 msgid
= va_arg (ap
, const char *);
901 old_args
= output_buffer_ptr_to_format_args (buffer
);
902 output_buffer_ptr_to_format_args (buffer
) = &ap
;
903 output_do_printf (buffer
, msgid
);
904 output_buffer_ptr_to_format_args (buffer
) = old_args
;
908 /* Print the message MSGID in FILE. */
911 vnotice (file
, msgid
, ap
)
916 vfprintf (file
, _(msgid
), ap
);
919 /* Print a message relevant to the given DECL. */
922 format_with_decl (buffer
, decl
)
923 output_buffer
*buffer
;
928 /* Do magic to get around lack of varargs support for insertion
929 of arguments into existing list. We know that the decl is first;
930 we ass_u_me that it will be printed with "%s". */
931 for (p
= output_buffer_text_cursor (buffer
); *p
; ++p
)
937 else if (*(p
+ 1) != 's')
944 /* Print the left-hand substring. */
945 maybe_wrap_text (buffer
, output_buffer_text_cursor (buffer
), p
);
947 if (*p
== '%') /* Print the name. */
949 const char *n
= (DECL_NAME (decl
)
950 ? (*decl_printable_name
) (decl
, 2)
951 : _("((anonymous))"));
952 output_add_string (buffer
, n
);
956 if (ISALPHA (*(p
- 1) & 0xFF))
961 if (*p
) /* Print the rest of the message. */
963 output_buffer_text_cursor (buffer
) = p
;
964 output_format (buffer
);
968 /* Figure file and line of the given INSN. */
971 file_and_line_for_asm (insn
, pfile
, pline
)
976 rtx body
= PATTERN (insn
);
979 /* Find the (or one of the) ASM_OPERANDS in the insn. */
980 if (GET_CODE (body
) == SET
&& GET_CODE (SET_SRC (body
)) == ASM_OPERANDS
)
981 asmop
= SET_SRC (body
);
982 else if (GET_CODE (body
) == ASM_OPERANDS
)
984 else if (GET_CODE (body
) == PARALLEL
985 && GET_CODE (XVECEXP (body
, 0, 0)) == SET
)
986 asmop
= SET_SRC (XVECEXP (body
, 0, 0));
987 else if (GET_CODE (body
) == PARALLEL
988 && GET_CODE (XVECEXP (body
, 0, 0)) == ASM_OPERANDS
)
989 asmop
= XVECEXP (body
, 0, 0);
995 *pfile
= ASM_OPERANDS_SOURCE_FILE (asmop
);
996 *pline
= ASM_OPERANDS_SOURCE_LINE (asmop
);
1000 *pfile
= input_filename
;
1005 /* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
1006 of the insn INSN. This is used only when INSN is an `asm' with operands,
1007 and each ASM_OPERANDS records its own source file and line. */
1010 diagnostic_for_asm (insn
, msg
, args_ptr
, warn
)
1016 diagnostic_context dc
;
1018 set_diagnostic_context (&dc
, msg
, args_ptr
, NULL
, 0, warn
);
1019 file_and_line_for_asm (insn
, &diagnostic_file_location (&dc
),
1020 &diagnostic_line_location (&dc
));
1021 report_diagnostic (&dc
);
1024 /* Report a diagnostic MESSAGE at the declaration DECL.
1025 MSG is a format string which uses %s to substitute the declaration
1026 name; subsequent substitutions are a la output_format. */
1029 diagnostic_for_decl (decl
, msg
, args_ptr
, warn
)
1037 if (diagnostic_lock
++)
1040 if (count_error (warn
))
1042 os
= output_buffer_state (diagnostic_buffer
);
1043 report_error_function (DECL_SOURCE_FILE (decl
));
1045 (diagnostic_buffer
, context_as_prefix
1046 (DECL_SOURCE_FILE (decl
), DECL_SOURCE_LINE (decl
), warn
));
1047 output_buffer_ptr_to_format_args (diagnostic_buffer
) = args_ptr
;
1048 output_buffer_text_cursor (diagnostic_buffer
) = msg
;
1049 format_with_decl (diagnostic_buffer
, decl
);
1050 finish_diagnostic ();
1051 output_destroy_prefix (diagnostic_buffer
);
1053 output_buffer_state (diagnostic_buffer
) = os
;
1059 /* Count an error or warning. Return 1 if the message should be printed. */
1062 count_error (warningp
)
1066 && (inhibit_warnings
1067 || (in_system_header
&& !warn_system_headers
)))
1070 if (warningp
&& !warnings_are_errors
)
1074 static int warning_message
= 0;
1076 if (warningp
&& !warning_message
)
1078 verbatim ("%s: warnings being treated as errors\n", progname
);
1079 warning_message
= 1;
1087 /* Print a diagnistic MSGID on FILE. */
1090 fnotice
VPARAMS ((FILE *file
, const char *msgid
, ...))
1092 #ifndef ANSI_PROTOTYPES
1098 VA_START (ap
, msgid
);
1100 #ifndef ANSI_PROTOTYPES
1101 file
= va_arg (ap
, FILE *);
1102 msgid
= va_arg (ap
, const char *);
1105 vnotice (file
, msgid
, ap
);
1110 /* Print a fatal I/O error message. Argument are like printf.
1111 Also include a system error message based on `errno'. */
1114 fatal_io_error
VPARAMS ((const char *msgid
, ...))
1116 #ifndef ANSI_PROTOTYPES
1122 os
= output_buffer_state (diagnostic_buffer
);
1123 VA_START (ap
, msgid
);
1125 #ifndef ANSI_PROTOTYPES
1126 msgid
= va_arg (ap
, const char *);
1129 output_printf (diagnostic_buffer
, "%s: %s: ", progname
, xstrerror (errno
));
1130 output_buffer_ptr_to_format_args (diagnostic_buffer
) = &ap
;
1131 output_buffer_text_cursor (diagnostic_buffer
) = msgid
;
1132 output_format (diagnostic_buffer
);
1133 finish_diagnostic ();
1134 output_buffer_state (diagnostic_buffer
) = os
;
1136 exit (FATAL_EXIT_CODE
);
1139 /* Issue a pedantic warning MSGID. */
1142 pedwarn
VPARAMS ((const char *msgid
, ...))
1144 #ifndef ANSI_PROTOTYPES
1148 diagnostic_context dc
;
1150 VA_START (ap
, msgid
);
1152 #ifndef ANSI_PROTOTYPES
1153 msgid
= va_arg (ap
, const char *);
1156 set_diagnostic_context
1157 (&dc
, msgid
, &ap
, input_filename
, lineno
, !flag_pedantic_errors
);
1158 report_diagnostic (&dc
);
1162 /* Issue a pedantic waring about DECL. */
1165 pedwarn_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1167 #ifndef ANSI_PROTOTYPES
1173 VA_START (ap
, msgid
);
1175 #ifndef ANSI_PROTOTYPES
1176 decl
= va_arg (ap
, tree
);
1177 msgid
= va_arg (ap
, const char *);
1179 /* We don't want -pedantic-errors to cause the compilation to fail from
1180 "errors" in system header files. Sometimes fixincludes can't fix what's
1181 broken (eg: unsigned char bitfields - fixing it may change the alignment
1182 which will cause programs to mysteriously fail because the C library
1183 or kernel uses the original layout). There's no point in issuing a
1184 warning either, it's just unnecessary noise. */
1185 if (!DECL_IN_SYSTEM_HEADER (decl
))
1186 diagnostic_for_decl (decl
, msgid
, &ap
, !flag_pedantic_errors
);
1190 /* Same as above but within the context FILE and LINE. */
1193 pedwarn_with_file_and_line
VPARAMS ((const char *file
, int line
,
1194 const char *msgid
, ...))
1196 #ifndef ANSI_PROTOTYPES
1202 diagnostic_context dc
;
1204 VA_START (ap
, msgid
);
1206 #ifndef ANSI_PROTOTYPES
1207 file
= va_arg (ap
, const char *);
1208 line
= va_arg (ap
, int);
1209 msgid
= va_arg (ap
, const char *);
1212 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, !flag_pedantic_errors
);
1213 report_diagnostic (&dc
);
1217 /* Just apologize with MSGID. */
1220 sorry
VPARAMS ((const char *msgid
, ...))
1222 #ifndef ANSI_PROTOTYPES
1228 os
= output_buffer_state (diagnostic_buffer
);
1229 VA_START (ap
, msgid
);
1231 #ifndef ANSI_PROTOTYPES
1232 msgid
= va_arg (ap
, const char *);
1236 (diagnostic_buffer
, context_as_prefix (input_filename
, lineno
, 0));
1237 output_printf (diagnostic_buffer
, "sorry, not implemented: ");
1238 output_buffer_ptr_to_format_args (diagnostic_buffer
) = &ap
;
1239 output_buffer_text_cursor (diagnostic_buffer
) = msgid
;
1240 output_format (diagnostic_buffer
);
1241 finish_diagnostic ();
1242 output_buffer_state (diagnostic_buffer
) = os
;
1246 /* Called when the start of a function definition is parsed,
1247 this function prints on stderr the name of the function. */
1250 announce_function (decl
)
1255 if (rtl_dump_and_exit
)
1256 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl
)));
1258 verbatim (" %s", (*decl_printable_name
) (decl
, 2));
1260 output_needs_newline (diagnostic_buffer
) = 1;
1261 record_last_error_function ();
1265 /* The default function to print out name of current function that caused
1269 default_print_error_function (file
)
1272 if (error_function_changed ())
1274 char *prefix
= file
? build_message_string ("%s: ", file
) : NULL
;
1277 os
= output_buffer_state (diagnostic_buffer
);
1278 output_set_prefix (diagnostic_buffer
, prefix
);
1280 if (current_function_decl
== NULL
)
1281 output_add_string (diagnostic_buffer
, "At top level:");
1284 if (TREE_CODE (TREE_TYPE (current_function_decl
)) == METHOD_TYPE
)
1286 (diagnostic_buffer
, "In method `%s':",
1287 (*decl_printable_name
) (current_function_decl
, 2));
1290 (diagnostic_buffer
, "In function `%s':",
1291 (*decl_printable_name
) (current_function_decl
, 2));
1293 output_add_newline (diagnostic_buffer
);
1295 record_last_error_function ();
1296 output_buffer_to_stream (diagnostic_buffer
);
1297 output_buffer_state (diagnostic_buffer
) = os
;
1298 free ((char*) prefix
);
1302 /* Prints out, if necessary, the name of the current function
1303 that caused an error. Called from all error and warning functions.
1304 We ignore the FILE parameter, as it cannot be relied upon. */
1307 report_error_function (file
)
1308 const char *file ATTRIBUTE_UNUSED
;
1310 report_problematic_module (diagnostic_buffer
);
1311 (*print_error_function
) (input_filename
);
1315 error_with_file_and_line
VPARAMS ((const char *file
, int line
,
1316 const char *msgid
, ...))
1318 #ifndef ANSI_PROTOTYPES
1324 diagnostic_context dc
;
1326 VA_START (ap
, msgid
);
1328 #ifndef ANSI_PROTOTYPES
1329 file
= va_arg (ap
, const char *);
1330 line
= va_arg (ap
, int);
1331 msgid
= va_arg (ap
, const char *);
1334 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, /* warn = */ 0);
1335 report_diagnostic (&dc
);
1340 error_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1342 #ifndef ANSI_PROTOTYPES
1348 VA_START (ap
, msgid
);
1350 #ifndef ANSI_PROTOTYPES
1351 decl
= va_arg (ap
, tree
);
1352 msgid
= va_arg (ap
, const char *);
1355 diagnostic_for_decl (decl
, msgid
, &ap
, /* warn = */ 0);
1360 error_for_asm
VPARAMS ((rtx insn
, const char *msgid
, ...))
1362 #ifndef ANSI_PROTOTYPES
1368 VA_START (ap
, msgid
);
1370 #ifndef ANSI_PROTOTYPES
1371 insn
= va_arg (ap
, rtx
);
1372 msgid
= va_arg (ap
, const char *);
1375 diagnostic_for_asm (insn
, msgid
, &ap
, /* warn = */ 0);
1379 /* Report an error message. The arguments are like that of printf. */
1382 error
VPARAMS ((const char *msgid
, ...))
1384 #ifndef ANSI_PROTOTYPES
1388 diagnostic_context dc
;
1390 VA_START (ap
, msgid
);
1392 #ifndef ANSI_PROTOTYPES
1393 msgid
= va_arg (ap
, const char *);
1396 set_diagnostic_context
1397 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 0);
1398 report_diagnostic (&dc
);
1402 /* Likewise, except that the compilation is terminated after printing the
1406 fatal_error
VPARAMS ((const char *msgid
, ...))
1408 #ifndef ANSI_PROTOTYPES
1412 diagnostic_context dc
;
1414 VA_START (ap
, msgid
);
1416 #ifndef ANSI_PROTOTYPES
1417 msgid
= va_arg (ap
, const char *);
1420 set_diagnostic_context
1421 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 0);
1422 report_diagnostic (&dc
);
1425 fprintf (stderr
, "compilation terminated.\n");
1426 exit (FATAL_EXIT_CODE
);
1429 /* Report a compiler error at the current line number. Allow a front end to
1430 intercept the message. */
1432 static void (*internal_error_function
) PARAMS ((const char *, va_list *));
1434 /* Set the function to call when a compiler error occurs. */
1437 set_internal_error_function (f
)
1438 void (*f
) PARAMS ((const char *, va_list *));
1440 internal_error_function
= f
;
1444 internal_error
VPARAMS ((const char *msgid
, ...))
1446 #ifndef ANSI_PROTOTYPES
1450 diagnostic_context dc
;
1452 VA_START (ap
, msgid
);
1454 #ifndef ANSI_PROTOTYPES
1455 msgid
= va_arg (ap
, const char *);
1458 if (errorcount
> 0 || sorrycount
> 0)
1460 fprintf (stderr
, "%s:%d: confused by earlier errors, bailing out\n",
1461 input_filename
, lineno
);
1462 exit (FATAL_EXIT_CODE
);
1465 if (internal_error_function
!= 0)
1466 (*internal_error_function
) (_(msgid
), &ap
);
1468 set_diagnostic_context
1469 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */0);
1470 report_diagnostic (&dc
);
1473 fprintf (stderr
, "Please submit a full bug report, ");
1474 fprintf (stderr
, "with preprocessed source if appropriate.\n");
1475 fprintf (stderr
, "See %s for instructions.\n", GCCBUGURL
);
1476 exit (FATAL_EXIT_CODE
);
1480 _fatal_insn (msgid
, insn
, file
, line
, function
)
1485 const char *function
;
1487 error ("%s", msgid
);
1489 /* The above incremented error_count, but isn't an error that we want to
1490 count, so reset it here. */
1494 fancy_abort (file
, line
, function
);
1498 _fatal_insn_not_found (insn
, file
, line
, function
)
1502 const char *function
;
1504 if (INSN_CODE (insn
) < 0)
1505 _fatal_insn ("Unrecognizable insn:", insn
, file
, line
, function
);
1507 _fatal_insn ("Insn does not satisfy its constraints:",
1508 insn
, file
, line
, function
);
1512 warning_with_file_and_line
VPARAMS ((const char *file
, int line
,
1513 const char *msgid
, ...))
1515 #ifndef ANSI_PROTOTYPES
1521 diagnostic_context dc
;
1523 VA_START (ap
, msgid
);
1525 #ifndef ANSI_PROTOTYPES
1526 file
= va_arg (ap
, const char *);
1527 line
= va_arg (ap
, int);
1528 msgid
= va_arg (ap
, const char *);
1531 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, /* warn = */ 1);
1532 report_diagnostic (&dc
);
1537 warning_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1539 #ifndef ANSI_PROTOTYPES
1545 VA_START (ap
, msgid
);
1547 #ifndef ANSI_PROTOTYPES
1548 decl
= va_arg (ap
, tree
);
1549 msgid
= va_arg (ap
, const char *);
1552 diagnostic_for_decl (decl
, msgid
, &ap
, /* warn = */ 1);
1557 warning_for_asm
VPARAMS ((rtx insn
, const char *msgid
, ...))
1559 #ifndef ANSI_PROTOTYPES
1565 VA_START (ap
, msgid
);
1567 #ifndef ANSI_PROTOTYPES
1568 insn
= va_arg (ap
, rtx
);
1569 msgid
= va_arg (ap
, const char *);
1572 diagnostic_for_asm (insn
, msgid
, &ap
, /* warn = */ 1);
1577 warning
VPARAMS ((const char *msgid
, ...))
1579 #ifndef ANSI_PROTOTYPES
1583 diagnostic_context dc
;
1585 VA_START (ap
, msgid
);
1587 #ifndef ANSI_PROTOTYPES
1588 msgid
= va_arg (ap
, const char *);
1591 set_diagnostic_context
1592 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 1);
1593 report_diagnostic (&dc
);
1597 /* Flush diagnostic_buffer content on stderr. */
1600 finish_diagnostic ()
1602 output_buffer_to_stream (diagnostic_buffer
);
1603 clear_diagnostic_info (diagnostic_buffer
);
1604 fputc ('\n', output_buffer_attached_stream (diagnostic_buffer
));
1605 fflush (output_buffer_attached_stream (diagnostic_buffer
));
1608 /* Helper subroutine of output_verbatim and verbatim. Do the approriate
1609 settings needed by BUFFER for a verbatim formatting. */
1612 output_do_verbatim (buffer
, msg
, args_ptr
)
1613 output_buffer
*buffer
;
1619 os
= output_buffer_state (buffer
);
1620 output_prefix (buffer
) = NULL
;
1621 prefixing_policy (buffer
) = DIAGNOSTICS_SHOW_PREFIX_NEVER
;
1622 output_buffer_text_cursor (buffer
) = msg
;
1623 output_buffer_ptr_to_format_args (buffer
) = args_ptr
;
1624 output_set_maximum_length (buffer
, 0);
1625 output_format (buffer
);
1626 output_buffer_state (buffer
) = os
;
1629 /* Output MESSAGE verbatim into BUFFER. */
1632 output_verbatim
VPARAMS ((output_buffer
*buffer
, const char *msg
, ...))
1634 #ifndef ANSI_PROTOTYPES
1635 output_buffer
*buffer
;
1641 #ifndef ANSI_PROTOTYPES
1642 buffer
= va_arg (ap
, output_buffer
*);
1643 msg
= va_arg (ap
, const char *);
1645 output_do_verbatim (buffer
, msg
, &ap
);
1649 /* Same as above but use diagnostic_buffer. */
1652 verbatim
VPARAMS ((const char *msg
, ...))
1654 #ifndef ANSI_PROTOTYPES
1660 #ifndef ANSI_PROTOTYPES
1661 msg
= va_arg (ap
, const char *);
1663 output_do_verbatim (diagnostic_buffer
, msg
, &ap
);
1664 output_buffer_to_stream (diagnostic_buffer
);
1668 /* Report a diagnostic message (an error or a warning) as specified by
1669 DC. This function is *the* subroutine in terms of which front-ends
1670 should implement their specific diagnostic handling modules. The
1671 front-end independent format specifiers are exactly those described
1672 in the documentation of output_format. */
1675 report_diagnostic (dc
)
1676 diagnostic_context
*dc
;
1680 if (diagnostic_lock
++)
1683 if (count_error (diagnostic_is_warning (dc
)))
1685 os
= output_buffer_state (diagnostic_buffer
);
1686 diagnostic_msg
= diagnostic_message (dc
);
1687 diagnostic_args
= diagnostic_argument_list (dc
);
1688 (*diagnostic_starter (dc
)) (diagnostic_buffer
, dc
);
1689 output_format (diagnostic_buffer
);
1690 (*diagnostic_finalizer (dc
)) (diagnostic_buffer
, dc
);
1691 finish_diagnostic ();
1692 output_buffer_state (diagnostic_buffer
) = os
;
1698 /* Inform the user that an error occurred while trying to report some
1699 other error. This indicates catastrophic internal inconsistencies,
1700 so give up now. But do try to flush out the previous error. */
1705 if (diagnostic_lock
< 3)
1706 finish_diagnostic ();
1709 ("Internal compiler error: Error reporting routines re-entered.");
1712 /* Given a partial pathname as input, return another pathname that
1713 shares no directory elements with the pathname of __FILE__. This
1714 is used by fancy_abort() to print `Internal compiler error in expr.c'
1715 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
1718 trim_filename (name
)
1721 static const char this_file
[] = __FILE__
;
1722 const char *p
= name
, *q
= this_file
;
1724 /* First skip any "../" in each filename. This allows us to give a proper
1725 reference to a file in a subdirectory. */
1726 while (p
[0] == '.' && p
[1] == '.'
1727 && (p
[2] == DIR_SEPARATOR
1728 #ifdef DIR_SEPARATOR_2
1729 || p
[2] == DIR_SEPARATOR_2
1734 while (q
[0] == '.' && q
[1] == '.'
1735 && (q
[2] == DIR_SEPARATOR
1736 #ifdef DIR_SEPARATOR_2
1737 || p
[2] == DIR_SEPARATOR_2
1742 /* Now skip any parts the two filenames have in common. */
1743 while (*p
== *q
&& *p
!= 0 && *q
!= 0)
1746 /* Now go backwards until the previous directory separator. */
1747 while (p
> name
&& p
[-1] != DIR_SEPARATOR
1748 #ifdef DIR_SEPARATOR_2
1749 && p
[-1] != DIR_SEPARATOR_2
1757 /* Report an internal compiler error in a friendly manner and without
1761 fancy_abort (file
, line
, function
)
1764 const char *function
;
1766 internal_error ("Internal compiler error in %s, at %s:%d",
1767 function
, trim_filename (file
), line
);
1770 /* Setup DC for reporting a diagnostic MESSAGE (an error or a WARNING),
1771 using arguments pointed to by ARGS_PTR, issued at a location specified
1772 by FILE and LINE. */
1775 set_diagnostic_context (dc
, message
, args_ptr
, file
, line
, warn
)
1776 diagnostic_context
*dc
;
1777 const char *message
;
1783 memset (dc
, 0, sizeof (diagnostic_context
));
1784 diagnostic_message (dc
) = message
;
1785 diagnostic_argument_list (dc
) = args_ptr
;
1786 diagnostic_file_location (dc
) = file
;
1787 diagnostic_line_location (dc
) = line
;
1788 diagnostic_is_warning (dc
) = warn
;
1789 diagnostic_starter (dc
) = lang_diagnostic_starter
;
1790 diagnostic_finalizer (dc
) = lang_diagnostic_finalizer
;
1794 report_problematic_module (buffer
)
1795 output_buffer
*buffer
;
1797 struct file_stack
*p
;
1799 if (output_needs_newline (buffer
))
1801 output_add_newline (buffer
);
1802 output_needs_newline (buffer
) = 0;
1805 if (input_file_stack
&& input_file_stack
->next
!= 0
1806 && error_module_changed ())
1808 for (p
= input_file_stack
->next
; p
; p
= p
->next
)
1809 if (p
== input_file_stack
->next
)
1811 (buffer
, "In file included from %s:%d", p
->name
, p
->line
);
1814 (buffer
, ",\n from %s:%d", p
->name
, p
->line
);
1815 output_verbatim (buffer
, ":\n");
1816 record_last_error_module ();
1821 default_diagnostic_starter (buffer
, dc
)
1822 output_buffer
*buffer
;
1823 diagnostic_context
*dc
;
1825 report_error_function (diagnostic_file_location (dc
));
1826 output_set_prefix (buffer
,
1827 context_as_prefix (diagnostic_file_location (dc
),
1828 diagnostic_line_location (dc
),
1829 diagnostic_is_warning (dc
)));
1833 default_diagnostic_finalizer (buffer
, dc
)
1834 output_buffer
*buffer
;
1835 diagnostic_context
*dc
__attribute__((__unused__
));
1837 output_destroy_prefix (buffer
);