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 set_real_maximum_length
PARAMS ((output_buffer
*));
83 static void output_unsigned_decimal
PARAMS ((output_buffer
*, unsigned int));
84 static void output_long_decimal
PARAMS ((output_buffer
*, long int));
85 static void output_long_unsigned_decimal
PARAMS ((output_buffer
*,
87 static void output_octal
PARAMS ((output_buffer
*, unsigned int));
88 static void output_long_octal
PARAMS ((output_buffer
*, unsigned long int));
89 static void output_hexadecimal
PARAMS ((output_buffer
*, unsigned int));
90 static void output_long_hexadecimal
PARAMS ((output_buffer
*,
92 static void output_append_r
PARAMS ((output_buffer
*, const char *, int));
93 static void wrap_text
PARAMS ((output_buffer
*, const char *, const char *));
94 static void maybe_wrap_text
PARAMS ((output_buffer
*, const char *,
96 static void clear_diagnostic_info
PARAMS ((output_buffer
*));
98 static void default_diagnostic_starter
PARAMS ((output_buffer
*,
99 diagnostic_context
*));
100 static void default_diagnostic_finalizer
PARAMS ((output_buffer
*,
101 diagnostic_context
*));
103 static void error_recursion
PARAMS ((void)) ATTRIBUTE_NORETURN
;
105 extern int rtl_dump_and_exit
;
106 extern int warnings_are_errors
;
108 /* Front-end specific tree formatter, if non-NULL. */
109 printer_fn lang_printer
= NULL
;
111 /* This must be large enough to hold any printed integer or
112 floating-point value. */
113 static char digit_buffer
[128];
115 /* An output_buffer surrogate for stderr. */
116 static output_buffer global_output_buffer
;
117 output_buffer
*diagnostic_buffer
= &global_output_buffer
;
119 /* Function of last error message;
120 more generally, function such that if next error message is in it
121 then we don't have to mention the function name. */
122 static tree last_error_function
= NULL
;
124 /* Used to detect when input_file_stack has changed since last described. */
125 static int last_error_tick
;
127 /* Called by report_error_function to print out function name.
128 Default may be overridden by language front-ends. */
130 void (*print_error_function
) PARAMS ((const char *)) =
131 default_print_error_function
;
133 /* Hooks for language specific diagnostic messages pager and finalizer. */
134 diagnostic_starter_fn lang_diagnostic_starter
;
135 diagnostic_finalizer_fn lang_diagnostic_finalizer
;
137 /* Maximum characters per line in automatic line wrapping mode.
138 Zero means don't wrap lines. */
140 int diagnostic_message_length_per_line
;
142 /* Used to control every diagnostic message formatting. Front-ends should
143 call set_message_prefixing_rule to set up their policies. */
144 static int current_prefixing_rule
;
146 /* Prevent recursion into the error handler. */
147 static int diagnostic_lock
;
150 /* Return truthvalue if current input file is different from the most recent
151 file involved in a diagnostic message. */
154 error_module_changed ()
156 return last_error_tick
!= input_file_stack_tick
;
159 /* Remember current file as being the most recent file involved in a
160 diagnostic message. */
163 record_last_error_module ()
165 last_error_tick
= input_file_stack_tick
;
168 /* Same as error_module_changed, but for function. */
171 error_function_changed ()
173 return last_error_function
!= current_function_decl
;
176 /* Same as record_last_error_module, but for function. */
179 record_last_error_function ()
181 last_error_function
= current_function_decl
;
184 /* Initialize the diagnostic message outputting machinery. */
187 initialize_diagnostics ()
189 /* By default, we don't line-wrap messages. */
190 diagnostic_message_length_per_line
= 0;
191 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE
);
193 /* Proceed to actual initialization. */
194 default_initialize_buffer (diagnostic_buffer
);
196 lang_diagnostic_starter
= default_diagnostic_starter
;
197 lang_diagnostic_finalizer
= default_diagnostic_finalizer
;
201 set_message_prefixing_rule (rule
)
204 current_prefixing_rule
= rule
;
207 /* Returns true if BUFFER is in line-wrappind mode. */
210 output_is_line_wrapping (buffer
)
211 output_buffer
*buffer
;
213 return ideal_line_wrap_cutoff (buffer
) > 0;
216 /* Return BUFFER's prefix. */
219 output_get_prefix (buffer
)
220 const output_buffer
*buffer
;
222 return output_prefix (buffer
);
225 /* Subroutine of output_set_maximum_length. Set up BUFFER's
226 internal maximum characters per line. */
229 set_real_maximum_length (buffer
)
230 output_buffer
*buffer
;
232 /* If we're told not to wrap lines then do the obvious thing. In case
233 we'll emit prefix only once per diagnostic message, it is appropriate
234 not to increase unncessarily the line-length cut-off. */
235 if (! output_is_line_wrapping (buffer
)
236 || prefixing_policy (buffer
) == DIAGNOSTICS_SHOW_PREFIX_ONCE
237 || prefixing_policy (buffer
) == DIAGNOSTICS_SHOW_PREFIX_NEVER
)
238 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
);
242 output_prefix (buffer
) ? strlen (output_prefix (buffer
)) : 0;
243 /* If the prefix is ridiculously too long, output at least
245 if (ideal_line_wrap_cutoff (buffer
) - prefix_length
< 32)
246 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
) + 32;
248 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
);
252 /* Sets the number of maximum characters per line BUFFER can output
253 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
256 output_set_maximum_length (buffer
, length
)
257 output_buffer
*buffer
;
260 ideal_line_wrap_cutoff (buffer
) = length
;
261 set_real_maximum_length (buffer
);
264 /* Sets BUFFER's PREFIX. */
267 output_set_prefix (buffer
, prefix
)
268 output_buffer
*buffer
;
271 output_prefix (buffer
) = prefix
;
272 set_real_maximum_length (buffer
);
273 prefix_was_emitted_for (buffer
) = 0;
274 output_indentation (buffer
) = 0;
277 /* Return a pointer to the last character emitted in the output
278 BUFFER area. A NULL pointer means no character available. */
280 output_last_position (buffer
)
281 const output_buffer
*buffer
;
283 const char *p
= NULL
;
285 if (obstack_base (&buffer
->obstack
) != obstack_next_free (&buffer
->obstack
))
286 p
= ((const char *) obstack_next_free (&buffer
->obstack
)) - 1;
290 /* Free BUFFER's prefix, a previously malloc'd string. */
293 output_destroy_prefix (buffer
)
294 output_buffer
*buffer
;
296 if (output_prefix (buffer
) != NULL
)
298 free ((char *) output_prefix (buffer
));
299 output_prefix (buffer
) = NULL
;
303 /* Zero out any text output so far in BUFFER. */
306 output_clear_message_text (buffer
)
307 output_buffer
*buffer
;
309 obstack_free (&buffer
->obstack
, obstack_base (&buffer
->obstack
));
310 output_text_length (buffer
) = 0;
313 /* Zero out any diagnostic data used so far by BUFFER. */
316 clear_diagnostic_info (buffer
)
317 output_buffer
*buffer
;
319 output_buffer_text_cursor (buffer
) = NULL
;
320 output_buffer_ptr_to_format_args (buffer
) = NULL
;
321 prefix_was_emitted_for (buffer
) = 0;
322 output_indentation (buffer
) = 0;
325 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
326 characters per line. */
329 init_output_buffer (buffer
, prefix
, maximum_length
)
330 output_buffer
*buffer
;
334 memset (buffer
, 0, sizeof (output_buffer
));
335 obstack_init (&buffer
->obstack
);
336 output_buffer_attached_stream (buffer
) = stderr
;
337 ideal_line_wrap_cutoff (buffer
) = maximum_length
;
338 prefixing_policy (buffer
) = current_prefixing_rule
;
339 output_set_prefix (buffer
, prefix
);
340 output_text_length (buffer
) = 0;
341 clear_diagnostic_info (buffer
);
344 /* Initialize BUFFER with a NULL prefix and current diagnostic message
348 default_initialize_buffer (buffer
)
349 output_buffer
*buffer
;
351 init_output_buffer (buffer
, NULL
, diagnostic_message_length_per_line
);
354 /* Recompute diagnostic_buffer's attributes to reflect any change
355 in diagnostic formatting global options. */
358 reshape_diagnostic_buffer ()
360 ideal_line_wrap_cutoff (diagnostic_buffer
) =
361 diagnostic_message_length_per_line
;
362 prefixing_policy (diagnostic_buffer
) = current_prefixing_rule
;
363 set_real_maximum_length (diagnostic_buffer
);
366 /* Reinitialize BUFFER. */
369 output_clear (buffer
)
370 output_buffer
*buffer
;
372 output_clear_message_text (buffer
);
373 clear_diagnostic_info (buffer
);
376 /* Finishes constructing a NULL-terminated character string representing
377 the BUFFERed message. */
380 output_finalize_message (buffer
)
381 output_buffer
*buffer
;
383 obstack_1grow (&buffer
->obstack
, '\0');
384 return output_message_text (buffer
);
388 flush_diagnostic_buffer ()
390 output_buffer_to_stream (diagnostic_buffer
);
391 fflush (output_buffer_attached_stream (diagnostic_buffer
));
394 /* Return the amount of characters BUFFER can accept to
398 output_space_left (buffer
)
399 const output_buffer
*buffer
;
401 return line_wrap_cutoff (buffer
) - output_text_length (buffer
);
404 /* Write out BUFFER's prefix. */
407 output_emit_prefix (buffer
)
408 output_buffer
*buffer
;
410 if (output_prefix (buffer
) != NULL
)
412 switch (prefixing_policy (buffer
))
415 case DIAGNOSTICS_SHOW_PREFIX_NEVER
:
418 case DIAGNOSTICS_SHOW_PREFIX_ONCE
:
419 if (prefix_was_emitted_for (buffer
))
421 output_indent (buffer
);
424 output_indentation (buffer
) += 3;
427 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE
:
429 int prefix_length
= strlen (output_prefix (buffer
));
430 output_append_r (buffer
, output_prefix (buffer
), prefix_length
);
431 prefix_was_emitted_for (buffer
) = 1;
438 /* Have BUFFER start a new line. */
441 output_add_newline (buffer
)
442 output_buffer
*buffer
;
444 obstack_1grow (&buffer
->obstack
, '\n');
445 output_text_length (buffer
) = 0;
448 /* Appends a character to BUFFER. */
451 output_add_character (buffer
, c
)
452 output_buffer
*buffer
;
455 if (output_is_line_wrapping (buffer
) && output_space_left (buffer
) <= 0)
456 output_add_newline (buffer
);
457 obstack_1grow (&buffer
->obstack
, c
);
458 ++output_text_length (buffer
);
461 /* Adds a space to BUFFER. */
464 output_add_space (buffer
)
465 output_buffer
*buffer
;
467 if (output_is_line_wrapping (buffer
) && output_space_left (buffer
) <= 0)
469 output_add_newline (buffer
);
472 obstack_1grow (&buffer
->obstack
, ' ');
473 ++output_text_length (buffer
);
476 /* These functions format an INTEGER into BUFFER as suggested by their
480 output_decimal (buffer
, i
)
481 output_buffer
*buffer
;
484 output_formatted_integer (buffer
, "%d", i
);
488 output_long_decimal (buffer
, i
)
489 output_buffer
*buffer
;
492 output_formatted_integer (buffer
, "%ld", i
);
496 output_unsigned_decimal (buffer
, i
)
497 output_buffer
*buffer
;
500 output_formatted_integer (buffer
, "%u", i
);
504 output_long_unsigned_decimal (buffer
, i
)
505 output_buffer
*buffer
;
508 output_formatted_integer (buffer
, "%lu", i
);
512 output_octal (buffer
, i
)
513 output_buffer
*buffer
;
516 output_formatted_integer (buffer
, "%o", i
);
520 output_long_octal (buffer
, i
)
521 output_buffer
*buffer
;
524 output_formatted_integer (buffer
, "%lo", i
);
528 output_hexadecimal (buffer
, i
)
529 output_buffer
*buffer
;
532 output_formatted_integer (buffer
, "%x", i
);
536 output_long_hexadecimal (buffer
, i
)
537 output_buffer
*buffer
;
540 output_formatted_integer (buffer
, "%lx", i
);
543 /* Append to BUFFER a string specified by its STARTING character
547 output_append_r (buffer
, start
, length
)
548 output_buffer
*buffer
;
552 obstack_grow (&buffer
->obstack
, start
, length
);
553 output_text_length (buffer
) += length
;
556 /* Append a string deliminated by START and END to BUFFER. No wrapping is
557 done. However, if beginning a new line then emit output_prefix (BUFFER)
558 and skip any leading whitespace if appropriate. The caller must ensure
559 that it is safe to do so. */
562 output_append (buffer
, start
, end
)
563 output_buffer
*buffer
;
567 /* Emit prefix and skip whitespace if we're starting a new line. */
568 if (is_starting_newline (buffer
))
570 output_emit_prefix (buffer
);
571 if (output_is_line_wrapping (buffer
))
572 while (start
!= end
&& *start
== ' ')
575 output_append_r (buffer
, start
, end
- start
);
579 output_indent (buffer
)
580 output_buffer
*buffer
;
582 int n
= output_indentation (buffer
);
585 for (i
= 0; i
< n
; ++i
)
586 output_add_character (buffer
, ' ');
589 /* Wrap a text delimited by START and END into BUFFER. */
592 wrap_text (buffer
, start
, end
)
593 output_buffer
*buffer
;
597 int is_wrapping
= output_is_line_wrapping (buffer
);
601 /* Dump anything bodered by whitespaces. */
603 const char *p
= start
;
604 while (p
!= end
&& *p
!= ' ' && *p
!= '\n')
606 if (is_wrapping
&& p
- start
>= output_space_left (buffer
))
607 output_add_newline (buffer
);
608 output_append (buffer
, start
, p
);
612 if (start
!= end
&& *start
== ' ')
614 output_add_space (buffer
);
617 if (start
!= end
&& *start
== '\n')
619 output_add_newline (buffer
);
625 /* Same as wrap_text but wrap text only when in line-wrapping mode. */
628 maybe_wrap_text (buffer
, start
, end
)
629 output_buffer
*buffer
;
633 if (output_is_line_wrapping (buffer
))
634 wrap_text (buffer
, start
, end
);
636 output_append (buffer
, start
, end
);
640 /* Append a STRING to BUFFER; the STRING might be line-wrapped if in
644 output_add_string (buffer
, str
)
645 output_buffer
*buffer
;
648 maybe_wrap_text (buffer
, str
, str
+ (str
? strlen (str
) : 0));
651 /* Flush the content of BUFFER onto the attached stream,
655 output_buffer_to_stream (buffer
)
656 output_buffer
*buffer
;
658 const char *text
= output_finalize_message (buffer
);
659 fputs (text
, output_buffer_attached_stream (buffer
));
660 output_clear_message_text (buffer
);
663 /* Format a message pointed to by output_buffer_text_cursor (BUFFER) using
664 output_buffer_format_args (BUFFER) as appropriate. The following format
665 specifiers are recognized as being language independent:
666 %d, %i: (signed) integer in base ten.
667 %u: unsigned integer in base ten.
668 %o: unsigned integer in base eight.
669 %x: unsigned integer in base sixteen.
670 %ld, %li, %lo, %lu, %lx: long versions of the above.
674 %*.s: a substring the length of which is specified by an integer. */
677 output_format (buffer
)
678 output_buffer
*buffer
;
680 for (; *output_buffer_text_cursor (buffer
);
681 ++output_buffer_text_cursor (buffer
))
683 int long_integer
= 0;
687 const char *p
= output_buffer_text_cursor (buffer
);
688 while (*p
&& *p
!= '%')
690 wrap_text (buffer
, output_buffer_text_cursor (buffer
), p
);
691 output_buffer_text_cursor (buffer
) = p
;
694 if (!*output_buffer_text_cursor (buffer
))
697 /* We got a '%'. Let's see what happens. Record whether we're
698 parsing a long integer format specifier. */
699 if (*++output_buffer_text_cursor (buffer
) == 'l')
702 ++output_buffer_text_cursor (buffer
);
705 /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %o, %s, %u,
706 %x, %.*s; %%. And nothing else. Front-ends should install
707 printers to grok language specific format specifiers. */
708 switch (*output_buffer_text_cursor (buffer
))
712 (buffer
, va_arg (output_buffer_format_args (buffer
), int));
719 (buffer
, va_arg (output_buffer_format_args (buffer
), long int));
722 (buffer
, va_arg (output_buffer_format_args (buffer
), int));
727 output_long_octal (buffer
,
728 va_arg (output_buffer_format_args (buffer
),
731 output_octal (buffer
,
732 va_arg (output_buffer_format_args (buffer
),
737 output_add_string (buffer
,
738 va_arg (output_buffer_format_args (buffer
),
744 output_long_unsigned_decimal
745 (buffer
, va_arg (output_buffer_format_args (buffer
),
748 output_unsigned_decimal
749 (buffer
, va_arg (output_buffer_format_args (buffer
),
755 output_long_hexadecimal
756 (buffer
, va_arg (output_buffer_format_args (buffer
),
760 (buffer
, va_arg (output_buffer_format_args (buffer
),
765 output_add_character (buffer
, '%');
772 /* We handle no precision specifier but `%.*s'. */
773 if (*++output_buffer_text_cursor (buffer
) != '*')
775 else if (*++output_buffer_text_cursor (buffer
) != 's')
777 n
= va_arg (output_buffer_format_args (buffer
), int);
778 s
= va_arg (output_buffer_format_args (buffer
), const char *);
779 output_append (buffer
, s
, s
+ n
);
784 if (! lang_printer
|| !(*lang_printer
) (buffer
))
786 /* Hmmm. The front-end failed to install a format translator
787 but called us with an unrecognized format. Sorry. */
795 vbuild_message_string (msg
, ap
)
801 vasprintf (&str
, msg
, ap
);
805 /* Return a malloc'd string containing MSG formatted a la
806 printf. The caller is reponsible for freeing the memory. */
809 build_message_string
VPARAMS ((const char *msg
, ...))
811 #ifndef ANSI_PROTOTYPES
819 #ifndef ANSI_PROTOTYPES
820 msg
= va_arg (ap
, const char *);
823 str
= vbuild_message_string (msg
, ap
);
830 /* Return a malloc'd string describing a location. The caller is
831 responsible for freeing the memory. */
834 context_as_prefix (file
, line
, warn
)
842 return build_message_string (_("%s:%d: warning: "), file
, line
);
844 return build_message_string ("%s:%d: ", file
, line
);
849 return build_message_string (_("%s: warning: "), progname
);
851 return build_message_string ("%s: ", progname
);
855 /* Same as context_as_prefix, but only the source FILE is given. */
858 file_name_as_prefix (f
)
861 return build_message_string ("%s: ", f
);
864 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
867 output_do_printf (buffer
, msg
)
868 output_buffer
*buffer
;
871 char *message
= vbuild_message_string (msg
,
872 output_buffer_format_args (buffer
));
874 wrap_text (buffer
, message
, message
+ strlen (message
));
879 /* Format a message into BUFFER a la printf. */
882 output_printf
VPARAMS ((struct output_buffer
*buffer
, const char *msgid
, ...))
884 #ifndef ANSI_PROTOTYPES
885 struct output_buffer
*buffer
;
891 VA_START (ap
, msgid
);
892 #ifndef ANSI_PROTOTYPES
893 buffer
= va_arg (ap
, output_buffer
*);
894 msgid
= va_arg (ap
, const char *);
896 old_args
= output_buffer_ptr_to_format_args (buffer
);
897 output_buffer_ptr_to_format_args (buffer
) = &ap
;
898 output_do_printf (buffer
, _(msgid
));
899 output_buffer_ptr_to_format_args (buffer
) = old_args
;
903 /* Print a message relevant to the given DECL. */
906 format_with_decl (buffer
, decl
)
907 output_buffer
*buffer
;
912 /* Do magic to get around lack of varargs support for insertion
913 of arguments into existing list. We know that the decl is first;
914 we ass_u_me that it will be printed with "%s". */
915 for (p
= output_buffer_text_cursor (buffer
); *p
; ++p
)
921 else if (*(p
+ 1) != 's')
928 /* Print the left-hand substring. */
929 maybe_wrap_text (buffer
, output_buffer_text_cursor (buffer
), p
);
931 if (*p
== '%') /* Print the name. */
933 const char *n
= (DECL_NAME (decl
)
934 ? (*decl_printable_name
) (decl
, 2)
935 : _("((anonymous))"));
936 output_add_string (buffer
, n
);
940 if (ISALPHA (*(p
- 1) & 0xFF))
945 if (*p
) /* Print the rest of the message. */
947 output_buffer_text_cursor (buffer
) = p
;
948 output_format (buffer
);
952 /* Figure file and line of the given INSN. */
955 file_and_line_for_asm (insn
, pfile
, pline
)
960 rtx body
= PATTERN (insn
);
963 /* Find the (or one of the) ASM_OPERANDS in the insn. */
964 if (GET_CODE (body
) == SET
&& GET_CODE (SET_SRC (body
)) == ASM_OPERANDS
)
965 asmop
= SET_SRC (body
);
966 else if (GET_CODE (body
) == ASM_OPERANDS
)
968 else if (GET_CODE (body
) == PARALLEL
969 && GET_CODE (XVECEXP (body
, 0, 0)) == SET
)
970 asmop
= SET_SRC (XVECEXP (body
, 0, 0));
971 else if (GET_CODE (body
) == PARALLEL
972 && GET_CODE (XVECEXP (body
, 0, 0)) == ASM_OPERANDS
)
973 asmop
= XVECEXP (body
, 0, 0);
979 *pfile
= ASM_OPERANDS_SOURCE_FILE (asmop
);
980 *pline
= ASM_OPERANDS_SOURCE_LINE (asmop
);
984 *pfile
= input_filename
;
989 /* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
990 of the insn INSN. This is used only when INSN is an `asm' with operands,
991 and each ASM_OPERANDS records its own source file and line. */
994 diagnostic_for_asm (insn
, msg
, args_ptr
, warn
)
1000 diagnostic_context dc
;
1002 set_diagnostic_context (&dc
, msg
, args_ptr
, NULL
, 0, warn
);
1003 file_and_line_for_asm (insn
, &diagnostic_file_location (&dc
),
1004 &diagnostic_line_location (&dc
));
1005 report_diagnostic (&dc
);
1008 /* Report a diagnostic MESSAGE at the declaration DECL.
1009 MSG is a format string which uses %s to substitute the declaration
1010 name; subsequent substitutions are a la output_format. */
1013 diagnostic_for_decl (decl
, msgid
, args_ptr
, warn
)
1021 if (diagnostic_lock
++)
1024 if (count_error (warn
))
1026 os
= output_buffer_state (diagnostic_buffer
);
1027 report_error_function (DECL_SOURCE_FILE (decl
));
1029 (diagnostic_buffer
, context_as_prefix
1030 (DECL_SOURCE_FILE (decl
), DECL_SOURCE_LINE (decl
), warn
));
1031 output_buffer_ptr_to_format_args (diagnostic_buffer
) = args_ptr
;
1032 output_buffer_text_cursor (diagnostic_buffer
) = _(msgid
);
1033 format_with_decl (diagnostic_buffer
, decl
);
1034 finish_diagnostic ();
1035 output_destroy_prefix (diagnostic_buffer
);
1037 output_buffer_state (diagnostic_buffer
) = os
;
1043 /* Count an error or warning. Return 1 if the message should be printed. */
1046 count_error (warningp
)
1049 if (warningp
&& !diagnostic_report_warnings_p ())
1052 if (warningp
&& !warnings_are_errors
)
1056 static int warning_message
= 0;
1058 if (warningp
&& !warning_message
)
1060 verbatim ("%s: warnings being treated as errors\n", progname
);
1061 warning_message
= 1;
1069 /* Print a diagnostic MSGID on FILE. This is just fprintf, except it
1070 runs its second argument through gettext. */
1073 fnotice
VPARAMS ((FILE *file
, const char *msgid
, ...))
1075 #ifndef ANSI_PROTOTYPES
1081 VA_START (ap
, msgid
);
1083 #ifndef ANSI_PROTOTYPES
1084 file
= va_arg (ap
, FILE *);
1085 msgid
= va_arg (ap
, const char *);
1088 vfprintf (file
, _(msgid
), ap
);
1093 /* Print a fatal I/O error message. Argument are like printf.
1094 Also include a system error message based on `errno'. */
1097 fatal_io_error
VPARAMS ((const char *msgid
, ...))
1099 #ifndef ANSI_PROTOTYPES
1105 os
= output_buffer_state (diagnostic_buffer
);
1106 VA_START (ap
, msgid
);
1108 #ifndef ANSI_PROTOTYPES
1109 msgid
= va_arg (ap
, const char *);
1112 output_printf (diagnostic_buffer
, "%s: %s: ", progname
, xstrerror (errno
));
1113 output_buffer_ptr_to_format_args (diagnostic_buffer
) = &ap
;
1114 output_buffer_text_cursor (diagnostic_buffer
) = _(msgid
);
1115 output_format (diagnostic_buffer
);
1116 finish_diagnostic ();
1117 output_buffer_state (diagnostic_buffer
) = os
;
1119 exit (FATAL_EXIT_CODE
);
1122 /* Issue a pedantic warning MSGID. */
1125 pedwarn
VPARAMS ((const char *msgid
, ...))
1127 #ifndef ANSI_PROTOTYPES
1131 diagnostic_context dc
;
1133 VA_START (ap
, msgid
);
1135 #ifndef ANSI_PROTOTYPES
1136 msgid
= va_arg (ap
, const char *);
1139 set_diagnostic_context
1140 (&dc
, msgid
, &ap
, input_filename
, lineno
, !flag_pedantic_errors
);
1141 report_diagnostic (&dc
);
1145 /* Issue a pedantic waring about DECL. */
1148 pedwarn_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1150 #ifndef ANSI_PROTOTYPES
1156 VA_START (ap
, msgid
);
1158 #ifndef ANSI_PROTOTYPES
1159 decl
= va_arg (ap
, tree
);
1160 msgid
= va_arg (ap
, const char *);
1162 /* We don't want -pedantic-errors to cause the compilation to fail from
1163 "errors" in system header files. Sometimes fixincludes can't fix what's
1164 broken (eg: unsigned char bitfields - fixing it may change the alignment
1165 which will cause programs to mysteriously fail because the C library
1166 or kernel uses the original layout). There's no point in issuing a
1167 warning either, it's just unnecessary noise. */
1168 if (!DECL_IN_SYSTEM_HEADER (decl
))
1169 diagnostic_for_decl (decl
, msgid
, &ap
, !flag_pedantic_errors
);
1173 /* Same as above but within the context FILE and LINE. */
1176 pedwarn_with_file_and_line
VPARAMS ((const char *file
, int line
,
1177 const char *msgid
, ...))
1179 #ifndef ANSI_PROTOTYPES
1185 diagnostic_context dc
;
1187 VA_START (ap
, msgid
);
1189 #ifndef ANSI_PROTOTYPES
1190 file
= va_arg (ap
, const char *);
1191 line
= va_arg (ap
, int);
1192 msgid
= va_arg (ap
, const char *);
1195 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, !flag_pedantic_errors
);
1196 report_diagnostic (&dc
);
1200 /* Just apologize with MSGID. */
1203 sorry
VPARAMS ((const char *msgid
, ...))
1205 #ifndef ANSI_PROTOTYPES
1211 os
= output_buffer_state (diagnostic_buffer
);
1212 VA_START (ap
, msgid
);
1214 #ifndef ANSI_PROTOTYPES
1215 msgid
= va_arg (ap
, const char *);
1219 (diagnostic_buffer
, context_as_prefix (input_filename
, lineno
, 0));
1220 output_printf (diagnostic_buffer
, "sorry, not implemented: ");
1221 output_buffer_ptr_to_format_args (diagnostic_buffer
) = &ap
;
1222 output_buffer_text_cursor (diagnostic_buffer
) = _(msgid
);
1223 output_format (diagnostic_buffer
);
1224 finish_diagnostic ();
1225 output_buffer_state (diagnostic_buffer
) = os
;
1229 /* Called when the start of a function definition is parsed,
1230 this function prints on stderr the name of the function. */
1233 announce_function (decl
)
1238 if (rtl_dump_and_exit
)
1239 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl
)));
1241 verbatim (" %s", (*decl_printable_name
) (decl
, 2));
1243 output_needs_newline (diagnostic_buffer
) = 1;
1244 record_last_error_function ();
1248 /* The default function to print out name of current function that caused
1252 default_print_error_function (file
)
1255 if (error_function_changed ())
1257 char *prefix
= file
? build_message_string ("%s: ", file
) : NULL
;
1260 os
= output_buffer_state (diagnostic_buffer
);
1261 output_set_prefix (diagnostic_buffer
, prefix
);
1263 if (current_function_decl
== NULL
)
1264 output_add_string (diagnostic_buffer
, _("At top level:"));
1267 if (TREE_CODE (TREE_TYPE (current_function_decl
)) == METHOD_TYPE
)
1269 (diagnostic_buffer
, "In method `%s':",
1270 (*decl_printable_name
) (current_function_decl
, 2));
1273 (diagnostic_buffer
, "In function `%s':",
1274 (*decl_printable_name
) (current_function_decl
, 2));
1276 output_add_newline (diagnostic_buffer
);
1278 record_last_error_function ();
1279 output_buffer_to_stream (diagnostic_buffer
);
1280 output_buffer_state (diagnostic_buffer
) = os
;
1281 free ((char*) prefix
);
1285 /* Prints out, if necessary, the name of the current function
1286 that caused an error. Called from all error and warning functions.
1287 We ignore the FILE parameter, as it cannot be relied upon. */
1290 report_error_function (file
)
1291 const char *file ATTRIBUTE_UNUSED
;
1293 report_problematic_module (diagnostic_buffer
);
1294 (*print_error_function
) (input_filename
);
1298 error_with_file_and_line
VPARAMS ((const char *file
, int line
,
1299 const char *msgid
, ...))
1301 #ifndef ANSI_PROTOTYPES
1307 diagnostic_context dc
;
1309 VA_START (ap
, msgid
);
1311 #ifndef ANSI_PROTOTYPES
1312 file
= va_arg (ap
, const char *);
1313 line
= va_arg (ap
, int);
1314 msgid
= va_arg (ap
, const char *);
1317 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, /* warn = */ 0);
1318 report_diagnostic (&dc
);
1323 error_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1325 #ifndef ANSI_PROTOTYPES
1331 VA_START (ap
, msgid
);
1333 #ifndef ANSI_PROTOTYPES
1334 decl
= va_arg (ap
, tree
);
1335 msgid
= va_arg (ap
, const char *);
1338 diagnostic_for_decl (decl
, msgid
, &ap
, /* warn = */ 0);
1343 error_for_asm
VPARAMS ((rtx insn
, const char *msgid
, ...))
1345 #ifndef ANSI_PROTOTYPES
1351 VA_START (ap
, msgid
);
1353 #ifndef ANSI_PROTOTYPES
1354 insn
= va_arg (ap
, rtx
);
1355 msgid
= va_arg (ap
, const char *);
1358 diagnostic_for_asm (insn
, msgid
, &ap
, /* warn = */ 0);
1362 /* Report an error message. The arguments are like that of printf. */
1365 error
VPARAMS ((const char *msgid
, ...))
1367 #ifndef ANSI_PROTOTYPES
1371 diagnostic_context dc
;
1373 VA_START (ap
, msgid
);
1375 #ifndef ANSI_PROTOTYPES
1376 msgid
= va_arg (ap
, const char *);
1379 set_diagnostic_context
1380 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 0);
1381 report_diagnostic (&dc
);
1385 /* Likewise, except that the compilation is terminated after printing the
1389 fatal_error
VPARAMS ((const char *msgid
, ...))
1391 #ifndef ANSI_PROTOTYPES
1395 diagnostic_context dc
;
1397 VA_START (ap
, msgid
);
1399 #ifndef ANSI_PROTOTYPES
1400 msgid
= va_arg (ap
, const char *);
1403 set_diagnostic_context
1404 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 0);
1405 report_diagnostic (&dc
);
1408 fnotice (stderr
, "compilation terminated.\n");
1409 exit (FATAL_EXIT_CODE
);
1412 /* Report a compiler error at the current line number. Allow a front end to
1413 intercept the message. */
1415 static void (*internal_error_function
) PARAMS ((const char *, va_list *));
1417 /* Set the function to call when a compiler error occurs. */
1420 set_internal_error_function (f
)
1421 void (*f
) PARAMS ((const char *, va_list *));
1423 internal_error_function
= f
;
1427 internal_error
VPARAMS ((const char *msgid
, ...))
1429 #ifndef ANSI_PROTOTYPES
1433 diagnostic_context dc
;
1435 VA_START (ap
, msgid
);
1437 #ifndef ANSI_PROTOTYPES
1438 msgid
= va_arg (ap
, const char *);
1441 if (errorcount
> 0 || sorrycount
> 0)
1443 fnotice (stderr
, "%s:%d: confused by earlier errors, bailing out\n",
1444 input_filename
, lineno
);
1445 exit (FATAL_EXIT_CODE
);
1448 if (internal_error_function
!= 0)
1449 (*internal_error_function
) (_(msgid
), &ap
);
1451 set_diagnostic_context
1452 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */0);
1453 report_diagnostic (&dc
);
1457 "Please submit a full bug report,\n\
1458 with preprocessed source if appropriate.\n\
1459 See %s for instructions.\n", GCCBUGURL
);
1460 exit (FATAL_EXIT_CODE
);
1464 _fatal_insn (msgid
, insn
, file
, line
, function
)
1469 const char *function
;
1471 error ("%s", _(msgid
));
1473 /* The above incremented error_count, but isn't an error that we want to
1474 count, so reset it here. */
1478 fancy_abort (file
, line
, function
);
1482 _fatal_insn_not_found (insn
, file
, line
, function
)
1486 const char *function
;
1488 if (INSN_CODE (insn
) < 0)
1489 _fatal_insn ("Unrecognizable insn:", insn
, file
, line
, function
);
1491 _fatal_insn ("Insn does not satisfy its constraints:",
1492 insn
, file
, line
, function
);
1496 warning_with_file_and_line
VPARAMS ((const char *file
, int line
,
1497 const char *msgid
, ...))
1499 #ifndef ANSI_PROTOTYPES
1505 diagnostic_context dc
;
1507 VA_START (ap
, msgid
);
1509 #ifndef ANSI_PROTOTYPES
1510 file
= va_arg (ap
, const char *);
1511 line
= va_arg (ap
, int);
1512 msgid
= va_arg (ap
, const char *);
1515 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, /* warn = */ 1);
1516 report_diagnostic (&dc
);
1521 warning_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1523 #ifndef ANSI_PROTOTYPES
1529 VA_START (ap
, msgid
);
1531 #ifndef ANSI_PROTOTYPES
1532 decl
= va_arg (ap
, tree
);
1533 msgid
= va_arg (ap
, const char *);
1536 diagnostic_for_decl (decl
, msgid
, &ap
, /* warn = */ 1);
1541 warning_for_asm
VPARAMS ((rtx insn
, const char *msgid
, ...))
1543 #ifndef ANSI_PROTOTYPES
1549 VA_START (ap
, msgid
);
1551 #ifndef ANSI_PROTOTYPES
1552 insn
= va_arg (ap
, rtx
);
1553 msgid
= va_arg (ap
, const char *);
1556 diagnostic_for_asm (insn
, msgid
, &ap
, /* warn = */ 1);
1561 warning
VPARAMS ((const char *msgid
, ...))
1563 #ifndef ANSI_PROTOTYPES
1567 diagnostic_context dc
;
1569 VA_START (ap
, msgid
);
1571 #ifndef ANSI_PROTOTYPES
1572 msgid
= va_arg (ap
, const char *);
1575 set_diagnostic_context
1576 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 1);
1577 report_diagnostic (&dc
);
1581 /* Flush diagnostic_buffer content on stderr. */
1584 finish_diagnostic ()
1586 output_buffer_to_stream (diagnostic_buffer
);
1587 clear_diagnostic_info (diagnostic_buffer
);
1588 fputc ('\n', output_buffer_attached_stream (diagnostic_buffer
));
1589 fflush (output_buffer_attached_stream (diagnostic_buffer
));
1592 /* Helper subroutine of output_verbatim and verbatim. Do the approriate
1593 settings needed by BUFFER for a verbatim formatting. */
1596 output_do_verbatim (buffer
, msgid
, args_ptr
)
1597 output_buffer
*buffer
;
1603 os
= output_buffer_state (buffer
);
1604 output_prefix (buffer
) = NULL
;
1605 prefixing_policy (buffer
) = DIAGNOSTICS_SHOW_PREFIX_NEVER
;
1606 output_buffer_text_cursor (buffer
) = _(msgid
);
1607 output_buffer_ptr_to_format_args (buffer
) = args_ptr
;
1608 output_set_maximum_length (buffer
, 0);
1609 output_format (buffer
);
1610 output_buffer_state (buffer
) = os
;
1613 /* Output MESSAGE verbatim into BUFFER. */
1616 output_verbatim
VPARAMS ((output_buffer
*buffer
, const char *msgid
, ...))
1618 #ifndef ANSI_PROTOTYPES
1619 output_buffer
*buffer
;
1624 VA_START (ap
, msgid
);
1625 #ifndef ANSI_PROTOTYPES
1626 buffer
= va_arg (ap
, output_buffer
*);
1627 msg
= va_arg (ap
, const char *);
1629 output_do_verbatim (buffer
, msgid
, &ap
);
1633 /* Same as above but use diagnostic_buffer. */
1636 verbatim
VPARAMS ((const char *msgid
, ...))
1638 #ifndef ANSI_PROTOTYPES
1643 VA_START (ap
, msgid
);
1644 #ifndef ANSI_PROTOTYPES
1645 msgid
= va_arg (ap
, const char *);
1647 output_do_verbatim (diagnostic_buffer
, msgid
, &ap
);
1648 output_buffer_to_stream (diagnostic_buffer
);
1652 /* Report a diagnostic message (an error or a warning) as specified by
1653 DC. This function is *the* subroutine in terms of which front-ends
1654 should implement their specific diagnostic handling modules. The
1655 front-end independent format specifiers are exactly those described
1656 in the documentation of output_format. */
1659 report_diagnostic (dc
)
1660 diagnostic_context
*dc
;
1664 if (diagnostic_lock
++)
1667 if (count_error (diagnostic_is_warning (dc
)))
1669 os
= output_buffer_state (diagnostic_buffer
);
1670 diagnostic_msg
= diagnostic_message (dc
);
1671 diagnostic_args
= diagnostic_argument_list (dc
);
1672 (*diagnostic_starter (dc
)) (diagnostic_buffer
, dc
);
1673 output_format (diagnostic_buffer
);
1674 (*diagnostic_finalizer (dc
)) (diagnostic_buffer
, dc
);
1675 finish_diagnostic ();
1676 output_buffer_state (diagnostic_buffer
) = os
;
1682 /* Inform the user that an error occurred while trying to report some
1683 other error. This indicates catastrophic internal inconsistencies,
1684 so give up now. But do try to flush out the previous error.
1685 This mustn't use internal_error, that will cause infinite recursion. */
1690 if (diagnostic_lock
< 3)
1691 finish_diagnostic ();
1694 "Internal compiler error: Error reporting routines re-entered.\n");
1696 "Please submit a full bug report,\n\
1697 with preprocessed source if appropriate.\n\
1698 See %s for instructions.\n", GCCBUGURL
);
1699 exit (FATAL_EXIT_CODE
);
1702 /* Given a partial pathname as input, return another pathname that
1703 shares no directory elements with the pathname of __FILE__. This
1704 is used by fancy_abort() to print `Internal compiler error in expr.c'
1705 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
1708 trim_filename (name
)
1711 static const char this_file
[] = __FILE__
;
1712 const char *p
= name
, *q
= this_file
;
1714 /* First skip any "../" in each filename. This allows us to give a proper
1715 reference to a file in a subdirectory. */
1716 while (p
[0] == '.' && p
[1] == '.'
1717 && (p
[2] == DIR_SEPARATOR
1718 #ifdef DIR_SEPARATOR_2
1719 || p
[2] == DIR_SEPARATOR_2
1724 while (q
[0] == '.' && q
[1] == '.'
1725 && (q
[2] == DIR_SEPARATOR
1726 #ifdef DIR_SEPARATOR_2
1727 || p
[2] == DIR_SEPARATOR_2
1732 /* Now skip any parts the two filenames have in common. */
1733 while (*p
== *q
&& *p
!= 0 && *q
!= 0)
1736 /* Now go backwards until the previous directory separator. */
1737 while (p
> name
&& p
[-1] != DIR_SEPARATOR
1738 #ifdef DIR_SEPARATOR_2
1739 && p
[-1] != DIR_SEPARATOR_2
1747 /* Report an internal compiler error in a friendly manner and without
1751 fancy_abort (file
, line
, function
)
1754 const char *function
;
1756 internal_error ("Internal compiler error in %s, at %s:%d",
1757 function
, trim_filename (file
), line
);
1760 /* Setup DC for reporting a diagnostic MESSAGE (an error or a WARNING),
1761 using arguments pointed to by ARGS_PTR, issued at a location specified
1762 by FILE and LINE. */
1765 set_diagnostic_context (dc
, msgid
, args_ptr
, file
, line
, warn
)
1766 diagnostic_context
*dc
;
1773 memset (dc
, 0, sizeof (diagnostic_context
));
1774 diagnostic_message (dc
) = _(msgid
);
1775 diagnostic_argument_list (dc
) = args_ptr
;
1776 diagnostic_file_location (dc
) = file
;
1777 diagnostic_line_location (dc
) = line
;
1778 diagnostic_is_warning (dc
) = warn
;
1779 diagnostic_starter (dc
) = lang_diagnostic_starter
;
1780 diagnostic_finalizer (dc
) = lang_diagnostic_finalizer
;
1784 report_problematic_module (buffer
)
1785 output_buffer
*buffer
;
1787 struct file_stack
*p
;
1789 if (output_needs_newline (buffer
))
1791 output_add_newline (buffer
);
1792 output_needs_newline (buffer
) = 0;
1795 if (input_file_stack
&& input_file_stack
->next
!= 0
1796 && error_module_changed ())
1798 for (p
= input_file_stack
->next
; p
; p
= p
->next
)
1799 if (p
== input_file_stack
->next
)
1801 (buffer
, "In file included from %s:%d", p
->name
, p
->line
);
1804 (buffer
, ",\n from %s:%d", p
->name
, p
->line
);
1805 output_verbatim (buffer
, ":\n");
1806 record_last_error_module ();
1811 default_diagnostic_starter (buffer
, dc
)
1812 output_buffer
*buffer
;
1813 diagnostic_context
*dc
;
1815 report_error_function (diagnostic_file_location (dc
));
1816 output_set_prefix (buffer
,
1817 context_as_prefix (diagnostic_file_location (dc
),
1818 diagnostic_line_location (dc
),
1819 diagnostic_is_warning (dc
)));
1823 default_diagnostic_finalizer (buffer
, dc
)
1824 output_buffer
*buffer
;
1825 diagnostic_context
*dc
__attribute__((__unused__
));
1827 output_destroy_prefix (buffer
);