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_to_stream
PARAMS ((output_buffer
*, FILE *));
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 inhibit_warnings
;
107 extern int warnings_are_errors
;
108 extern int warningcount
;
109 extern int errorcount
;
111 /* Front-end specific tree formatter, if non-NULL. */
112 printer_fn lang_printer
= NULL
;
114 /* This must be large enough to hold any printed integer or
115 floating-point value. */
116 static char digit_buffer
[128];
118 /* An output_buffer surrogate for stderr. */
119 static output_buffer global_output_buffer
;
120 output_buffer
*diagnostic_buffer
= &global_output_buffer
;
122 /* Function of last error message;
123 more generally, function such that if next error message is in it
124 then we don't have to mention the function name. */
125 static tree last_error_function
= NULL
;
127 /* Used to detect when input_file_stack has changed since last described. */
128 static int last_error_tick
;
130 /* Called by report_error_function to print out function name.
131 Default may be overridden by language front-ends. */
133 void (*print_error_function
) PARAMS ((const char *)) =
134 default_print_error_function
;
136 /* Hooks for language specific diagnostic messages pager and finalizer. */
137 diagnostic_starter_fn lang_diagnostic_starter
;
138 diagnostic_finalizer_fn lang_diagnostic_finalizer
;
140 /* Maximum characters per line in automatic line wrapping mode.
141 Zero means don't wrap lines. */
143 int diagnostic_message_length_per_line
;
145 /* Used to control every diagnostic message formatting. Front-ends should
146 call set_message_prefixing_rule to set up their policies. */
147 static int current_prefixing_rule
;
149 /* Prevent recursion into the error handler. */
150 static int diagnostic_lock
;
153 /* Return truthvalue if current input file is different from the most recent
154 file involved in a diagnostic message. */
157 error_module_changed ()
159 return last_error_tick
!= input_file_stack_tick
;
162 /* Remember current file as being the most recent file involved in a
163 diagnostic message. */
166 record_last_error_module ()
168 last_error_tick
= input_file_stack_tick
;
171 /* Same as error_module_changed, but for function. */
174 error_function_changed ()
176 return last_error_function
!= current_function_decl
;
179 /* Same as record_last_error_module, but for function. */
182 record_last_error_function ()
184 last_error_function
= current_function_decl
;
187 /* Initialize the diagnostic message outputting machinery. */
190 initialize_diagnostics ()
192 /* By default, we don't line-wrap messages. */
193 diagnostic_message_length_per_line
= 0;
194 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE
);
196 /* Proceed to actual initialization. */
197 default_initialize_buffer (diagnostic_buffer
);
199 lang_diagnostic_starter
= default_diagnostic_starter
;
200 lang_diagnostic_finalizer
= default_diagnostic_finalizer
;
204 set_message_prefixing_rule (rule
)
207 current_prefixing_rule
= rule
;
210 /* Returns true if BUFFER is in line-wrappind mode. */
213 output_is_line_wrapping (buffer
)
214 output_buffer
*buffer
;
216 return ideal_line_wrap_cutoff (buffer
) > 0;
219 /* Return BUFFER's prefix. */
222 output_get_prefix (buffer
)
223 const output_buffer
*buffer
;
225 return output_prefix (buffer
);
228 /* Subroutine of output_set_maximum_length. Set up BUFFER's
229 internal maximum characters per line. */
232 set_real_maximum_length (buffer
)
233 output_buffer
*buffer
;
235 /* If we're told not to wrap lines then do the obvious thing. In case
236 we'll emit prefix only once per diagnostic message, it is appropriate
237 not to increase unncessarily the line-length cut-off. */
238 if (! output_is_line_wrapping (buffer
)
239 || prefixing_policy (buffer
) == DIAGNOSTICS_SHOW_PREFIX_ONCE
240 || prefixing_policy (buffer
) == DIAGNOSTICS_SHOW_PREFIX_NEVER
)
241 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
);
245 output_prefix (buffer
) ? strlen (output_prefix (buffer
)) : 0;
246 /* If the prefix is ridiculously too long, output at least
248 if (ideal_line_wrap_cutoff (buffer
) - prefix_length
< 32)
249 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
) + 32;
251 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
);
255 /* Sets the number of maximum characters per line BUFFER can output
256 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
259 output_set_maximum_length (buffer
, length
)
260 output_buffer
*buffer
;
263 ideal_line_wrap_cutoff (buffer
) = length
;
264 set_real_maximum_length (buffer
);
267 /* Sets BUFFER's PREFIX. */
270 output_set_prefix (buffer
, prefix
)
271 output_buffer
*buffer
;
274 output_prefix (buffer
) = prefix
;
275 set_real_maximum_length (buffer
);
276 prefix_was_emitted_for (buffer
) = 0;
277 output_indentation (buffer
) = 0;
280 /* Return a pointer to the last character emitted in the output
281 BUFFER area. A NULL pointer means no character available. */
283 output_last_position (buffer
)
284 const output_buffer
*buffer
;
286 const char *p
= NULL
;
288 if (obstack_base (&buffer
->obstack
) != obstack_next_free (&buffer
->obstack
))
289 p
= ((const char *) obstack_next_free (&buffer
->obstack
)) - 1;
293 /* Free BUFFER's prefix, a previously malloc'd string. */
296 output_destroy_prefix (buffer
)
297 output_buffer
*buffer
;
299 if (output_prefix (buffer
) != NULL
)
301 free ((char *) output_prefix (buffer
));
302 output_prefix (buffer
) = NULL
;
306 /* Zero out any text output so far in BUFFER. */
309 output_clear_message_text (buffer
)
310 output_buffer
*buffer
;
312 obstack_free (&buffer
->obstack
, obstack_base (&buffer
->obstack
));
313 output_text_length (buffer
) = 0;
316 /* Zero out any diagnostic data used so far by BUFFER. */
319 clear_diagnostic_info (buffer
)
320 output_buffer
*buffer
;
322 output_buffer_text_cursor (buffer
) = NULL
;
323 output_buffer_ptr_to_format_args (buffer
) = NULL
;
324 prefix_was_emitted_for (buffer
) = 0;
325 output_indentation (buffer
) = 0;
328 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
329 characters per line. */
332 init_output_buffer (buffer
, prefix
, maximum_length
)
333 output_buffer
*buffer
;
337 memset (buffer
, 0, sizeof (output_buffer
));
338 obstack_init (&buffer
->obstack
);
339 ideal_line_wrap_cutoff (buffer
) = maximum_length
;
340 prefixing_policy (buffer
) = current_prefixing_rule
;
341 output_set_prefix (buffer
, prefix
);
342 output_text_length (buffer
) = 0;
343 clear_diagnostic_info (buffer
);
346 /* Initialize BUFFER with a NULL prefix and current diagnostic message
350 default_initialize_buffer (buffer
)
351 output_buffer
*buffer
;
353 init_output_buffer (buffer
, NULL
, diagnostic_message_length_per_line
);
356 /* Recompute diagnostic_buffer's attributes to reflect any change
357 in diagnostic formatting global options. */
360 reshape_diagnostic_buffer ()
362 ideal_line_wrap_cutoff (diagnostic_buffer
) =
363 diagnostic_message_length_per_line
;
364 prefixing_policy (diagnostic_buffer
) = current_prefixing_rule
;
365 set_real_maximum_length (diagnostic_buffer
);
368 /* Reinitialize BUFFER. */
371 output_clear (buffer
)
372 output_buffer
*buffer
;
374 output_clear_message_text (buffer
);
375 clear_diagnostic_info (buffer
);
378 /* Finishes constructing a NULL-terminated character string representing
379 the BUFFERed message. */
382 output_finalize_message (buffer
)
383 output_buffer
*buffer
;
385 obstack_1grow (&buffer
->obstack
, '\0');
386 return output_message_text (buffer
);
390 flush_diagnostic_buffer ()
392 output_to_stream (diagnostic_buffer
, stderr
);
396 /* Return the amount of characters BUFFER can accept to
400 output_space_left (buffer
)
401 const output_buffer
*buffer
;
403 return line_wrap_cutoff (buffer
) - output_text_length (buffer
);
406 /* Write out BUFFER's prefix. */
409 output_emit_prefix (buffer
)
410 output_buffer
*buffer
;
412 if (output_prefix (buffer
) != NULL
)
414 switch (prefixing_policy (buffer
))
417 case DIAGNOSTICS_SHOW_PREFIX_NEVER
:
420 case DIAGNOSTICS_SHOW_PREFIX_ONCE
:
421 if (prefix_was_emitted_for (buffer
))
423 output_indent (buffer
);
426 output_indentation (buffer
) += 3;
429 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE
:
431 int prefix_length
= strlen (output_prefix (buffer
));
432 output_append_r (buffer
, output_prefix (buffer
), prefix_length
);
433 prefix_was_emitted_for (buffer
) = 1;
440 /* Have BUFFER start a new line. */
443 output_add_newline (buffer
)
444 output_buffer
*buffer
;
446 obstack_1grow (&buffer
->obstack
, '\n');
447 output_text_length (buffer
) = 0;
450 /* Appends a character to BUFFER. */
453 output_add_character (buffer
, c
)
454 output_buffer
*buffer
;
457 if (output_is_line_wrapping (buffer
) && output_space_left (buffer
) <= 0)
458 output_add_newline (buffer
);
459 obstack_1grow (&buffer
->obstack
, c
);
460 ++output_text_length (buffer
);
463 /* Adds a space to BUFFER. */
466 output_add_space (buffer
)
467 output_buffer
*buffer
;
469 if (output_is_line_wrapping (buffer
) && output_space_left (buffer
) <= 0)
471 output_add_newline (buffer
);
474 obstack_1grow (&buffer
->obstack
, ' ');
475 ++output_text_length (buffer
);
478 /* These functions format an INTEGER into BUFFER as suggested by their
482 output_decimal (buffer
, i
)
483 output_buffer
*buffer
;
486 output_formatted_integer (buffer
, "%d", i
);
490 output_long_decimal (buffer
, i
)
491 output_buffer
*buffer
;
494 output_formatted_integer (buffer
, "%ld", i
);
498 output_unsigned_decimal (buffer
, i
)
499 output_buffer
*buffer
;
502 output_formatted_integer (buffer
, "%u", i
);
506 output_long_unsigned_decimal (buffer
, i
)
507 output_buffer
*buffer
;
510 output_formatted_integer (buffer
, "%lu", i
);
514 output_octal (buffer
, i
)
515 output_buffer
*buffer
;
518 output_formatted_integer (buffer
, "%o", i
);
522 output_long_octal (buffer
, i
)
523 output_buffer
*buffer
;
526 output_formatted_integer (buffer
, "%lo", i
);
530 output_hexadecimal (buffer
, i
)
531 output_buffer
*buffer
;
534 output_formatted_integer (buffer
, "%x", i
);
538 output_long_hexadecimal (buffer
, i
)
539 output_buffer
*buffer
;
542 output_formatted_integer (buffer
, "%lx", i
);
545 /* Append to BUFFER a string specified by its STARTING character
549 output_append_r (buffer
, start
, length
)
550 output_buffer
*buffer
;
554 obstack_grow (&buffer
->obstack
, start
, length
);
555 output_text_length (buffer
) += length
;
558 /* Append a string deliminated by START and END to BUFFER. No wrapping is
559 done. However, if beginning a new line then emit output_prefix (BUFFER)
560 and skip any leading whitespace if appropriate. The caller must ensure
561 that it is safe to do so. */
564 output_append (buffer
, start
, end
)
565 output_buffer
*buffer
;
569 /* Emit prefix and skip whitespace if we're starting a new line. */
570 if (is_starting_newline (buffer
))
572 output_emit_prefix (buffer
);
573 if (output_is_line_wrapping (buffer
))
574 while (start
!= end
&& *start
== ' ')
577 output_append_r (buffer
, start
, end
- start
);
581 output_indent (buffer
)
582 output_buffer
*buffer
;
584 int n
= output_indentation (buffer
);
587 for (i
= 0; i
< n
; ++i
)
588 output_add_character (buffer
, ' ');
591 /* Wrap a text delimited by START and END into BUFFER. */
594 wrap_text (buffer
, start
, end
)
595 output_buffer
*buffer
;
599 int is_wrapping
= output_is_line_wrapping (buffer
);
603 /* Dump anything bodered by whitespaces. */
605 const char *p
= start
;
606 while (p
!= end
&& *p
!= ' ' && *p
!= '\n')
608 if (is_wrapping
&& p
- start
>= output_space_left (buffer
))
609 output_add_newline (buffer
);
610 output_append (buffer
, start
, p
);
614 if (start
!= end
&& *start
== ' ')
616 output_add_space (buffer
);
619 if (start
!= end
&& *start
== '\n')
621 output_add_newline (buffer
);
627 /* Same as wrap_text but wrap text only when in line-wrapping mode. */
630 maybe_wrap_text (buffer
, start
, end
)
631 output_buffer
*buffer
;
635 if (output_is_line_wrapping (buffer
))
636 wrap_text (buffer
, start
, end
);
638 output_append (buffer
, start
, end
);
642 /* Append a STRING to BUFFER; the STRING might be line-wrapped if in
646 output_add_string (buffer
, str
)
647 output_buffer
*buffer
;
650 maybe_wrap_text (buffer
, str
, str
+ (str
? strlen (str
) : 0));
653 /* Flush the content of BUFFER onto FILE and reinitialize BUFFER. */
656 output_to_stream (buffer
, file
)
657 output_buffer
*buffer
;
660 const char *text
= output_finalize_message (buffer
);
662 output_clear_message_text (buffer
);
665 /* Format a message pointed to by output_buffer_text_cursor (BUFFER) using
666 output_buffer_format_args (BUFFER) as appropriate. The following format
667 specifiers are recognized as being language independent:
668 %d, %i: (signed) integer in base ten.
669 %u: unsigned integer in base ten.
670 %o: unsigned integer in base eight.
671 %x: unsigned integer in base sixteen.
672 %ld, %li, %lo, %lu, %lx: long versions of the above.
676 %*.s: a substring the length of which is specified by an integer. */
679 output_format (buffer
)
680 output_buffer
*buffer
;
682 for (; *output_buffer_text_cursor (buffer
);
683 ++output_buffer_text_cursor (buffer
))
685 int long_integer
= 0;
689 const char *p
= output_buffer_text_cursor (buffer
);
690 while (*p
&& *p
!= '%')
692 wrap_text (buffer
, output_buffer_text_cursor (buffer
), p
);
693 output_buffer_text_cursor (buffer
) = p
;
696 if (!*output_buffer_text_cursor (buffer
))
699 /* We got a '%'. Let's see what happens. Record whether we're
700 parsing a long integer format specifier. */
701 if (*++output_buffer_text_cursor (buffer
) == 'l')
704 ++output_buffer_text_cursor (buffer
);
707 /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %o, %s, %u,
708 %x, %.*s; %%. And nothing else. Front-ends should install
709 printers to grok language specific format specifiers. */
710 switch (*output_buffer_text_cursor (buffer
))
714 (buffer
, va_arg (output_buffer_format_args (buffer
), int));
721 (buffer
, va_arg (output_buffer_format_args (buffer
), long int));
724 (buffer
, va_arg (output_buffer_format_args (buffer
), int));
729 output_long_octal (buffer
,
730 va_arg (output_buffer_format_args (buffer
),
733 output_octal (buffer
,
734 va_arg (output_buffer_format_args (buffer
),
739 output_add_string (buffer
,
740 va_arg (output_buffer_format_args (buffer
),
746 output_long_unsigned_decimal
747 (buffer
, va_arg (output_buffer_format_args (buffer
),
750 output_unsigned_decimal
751 (buffer
, va_arg (output_buffer_format_args (buffer
),
757 output_long_hexadecimal
758 (buffer
, va_arg (output_buffer_format_args (buffer
),
762 (buffer
, va_arg (output_buffer_format_args (buffer
),
767 output_add_character (buffer
, '%');
774 /* We handle no precision specifier but `%.*s'. */
775 if (*++output_buffer_text_cursor (buffer
) != '*')
777 else if (*++output_buffer_text_cursor (buffer
) != 's')
779 n
= va_arg (output_buffer_format_args (buffer
), int);
780 s
= va_arg (output_buffer_format_args (buffer
), const char *);
781 output_append (buffer
, s
, s
+ n
);
786 if (! lang_printer
|| !(*lang_printer
) (buffer
))
788 /* Hmmm. The front-end failed to install a format translator
789 but called us with an unrecognized format. Sorry. */
797 vbuild_message_string (msg
, ap
)
803 vasprintf (&str
, msg
, ap
);
807 /* Return a malloc'd string containing MSG formatted a la
808 printf. The caller is reponsible for freeing the memory. */
811 build_message_string
VPARAMS ((const char *msg
, ...))
813 #ifndef ANSI_PROTOTYPES
821 #ifndef ANSI_PROTOTYPES
822 msg
= va_arg (ap
, const char *);
825 str
= vbuild_message_string (msg
, ap
);
832 /* Return a malloc'd string describing a location. The caller is
833 responsible for freeing the memory. */
836 context_as_prefix (file
, line
, warn
)
844 return build_message_string (_("%s:%d: warning: "), file
, line
);
846 return build_message_string ("%s:%d: ", file
, line
);
851 return build_message_string (_("%s: warning: "), progname
);
853 return build_message_string ("%s: ", progname
);
857 /* Same as context_as_prefix, but only the source FILE is given. */
860 file_name_as_prefix (f
)
863 return build_message_string ("%s: ", f
);
866 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
869 output_do_printf (buffer
, msg
)
870 output_buffer
*buffer
;
873 char *message
= vbuild_message_string (msg
,
874 output_buffer_format_args (buffer
));
876 wrap_text (buffer
, message
, message
+ strlen (message
));
881 /* Format a message into BUFFER a la printf. */
884 output_printf
VPARAMS ((struct output_buffer
*buffer
, const char *msgid
, ...))
886 #ifndef ANSI_PROTOTYPES
887 struct output_buffer
*buffer
;
893 VA_START (ap
, msgid
);
894 #ifndef ANSI_PROTOTYPES
895 buffer
= va_arg (ap
, output_buffer
*);
896 msgid
= va_arg (ap
, const char *);
898 old_args
= output_buffer_ptr_to_format_args (buffer
);
899 output_buffer_ptr_to_format_args (buffer
) = &ap
;
900 output_do_printf (buffer
, _(msgid
));
901 output_buffer_ptr_to_format_args (buffer
) = old_args
;
905 /* Print a message relevant to the given DECL. */
908 format_with_decl (buffer
, decl
)
909 output_buffer
*buffer
;
914 /* Do magic to get around lack of varargs support for insertion
915 of arguments into existing list. We know that the decl is first;
916 we ass_u_me that it will be printed with "%s". */
917 for (p
= output_buffer_text_cursor (buffer
); *p
; ++p
)
923 else if (*(p
+ 1) != 's')
930 /* Print the left-hand substring. */
931 maybe_wrap_text (buffer
, output_buffer_text_cursor (buffer
), p
);
933 if (*p
== '%') /* Print the name. */
935 const char *n
= (DECL_NAME (decl
)
936 ? (*decl_printable_name
) (decl
, 2)
937 : _("((anonymous))"));
938 output_add_string (buffer
, n
);
942 if (ISALPHA (*(p
- 1) & 0xFF))
947 if (*p
) /* Print the rest of the message. */
949 output_buffer_text_cursor (buffer
) = p
;
950 output_format (buffer
);
954 /* Figure file and line of the given INSN. */
957 file_and_line_for_asm (insn
, pfile
, pline
)
962 rtx body
= PATTERN (insn
);
965 /* Find the (or one of the) ASM_OPERANDS in the insn. */
966 if (GET_CODE (body
) == SET
&& GET_CODE (SET_SRC (body
)) == ASM_OPERANDS
)
967 asmop
= SET_SRC (body
);
968 else if (GET_CODE (body
) == ASM_OPERANDS
)
970 else if (GET_CODE (body
) == PARALLEL
971 && GET_CODE (XVECEXP (body
, 0, 0)) == SET
)
972 asmop
= SET_SRC (XVECEXP (body
, 0, 0));
973 else if (GET_CODE (body
) == PARALLEL
974 && GET_CODE (XVECEXP (body
, 0, 0)) == ASM_OPERANDS
)
975 asmop
= XVECEXP (body
, 0, 0);
981 *pfile
= ASM_OPERANDS_SOURCE_FILE (asmop
);
982 *pline
= ASM_OPERANDS_SOURCE_LINE (asmop
);
986 *pfile
= input_filename
;
991 /* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
992 of the insn INSN. This is used only when INSN is an `asm' with operands,
993 and each ASM_OPERANDS records its own source file and line. */
996 diagnostic_for_asm (insn
, msg
, args_ptr
, warn
)
1002 diagnostic_context dc
;
1004 set_diagnostic_context (&dc
, msg
, args_ptr
, NULL
, 0, warn
);
1005 file_and_line_for_asm (insn
, &diagnostic_file_location (&dc
),
1006 &diagnostic_line_location (&dc
));
1007 report_diagnostic (&dc
);
1010 /* Report a diagnostic MESSAGE at the declaration DECL.
1011 MSG is a format string which uses %s to substitute the declaration
1012 name; subsequent substitutions are a la output_format. */
1015 diagnostic_for_decl (decl
, msgid
, args_ptr
, warn
)
1023 if (diagnostic_lock
++)
1026 if (count_error (warn
))
1028 os
= output_buffer_state (diagnostic_buffer
);
1029 report_error_function (DECL_SOURCE_FILE (decl
));
1031 (diagnostic_buffer
, context_as_prefix
1032 (DECL_SOURCE_FILE (decl
), DECL_SOURCE_LINE (decl
), warn
));
1033 output_buffer_ptr_to_format_args (diagnostic_buffer
) = args_ptr
;
1034 output_buffer_text_cursor (diagnostic_buffer
) = _(msgid
);
1035 format_with_decl (diagnostic_buffer
, decl
);
1036 finish_diagnostic ();
1037 output_destroy_prefix (diagnostic_buffer
);
1039 output_buffer_state (diagnostic_buffer
) = os
;
1045 /* Count an error or warning. Return 1 if the message should be printed. */
1048 count_error (warningp
)
1052 && (inhibit_warnings
1053 || (in_system_header
&& !warn_system_headers
)))
1056 if (warningp
&& !warnings_are_errors
)
1060 static int warning_message
= 0;
1062 if (warningp
&& !warning_message
)
1064 verbatim ("%s: warnings being treated as errors\n", progname
);
1065 warning_message
= 1;
1073 /* Print a diagnostic MSGID on FILE. This is just fprintf, except it
1074 runs its second argument through gettext. */
1077 fnotice
VPARAMS ((FILE *file
, const char *msgid
, ...))
1079 #ifndef ANSI_PROTOTYPES
1085 VA_START (ap
, msgid
);
1087 #ifndef ANSI_PROTOTYPES
1088 file
= va_arg (ap
, FILE *);
1089 msgid
= va_arg (ap
, const char *);
1092 vfprintf (file
, _(msgid
), ap
);
1097 /* Print a fatal I/O error message. Argument are like printf.
1098 Also include a system error message based on `errno'. */
1101 fatal_io_error
VPARAMS ((const char *msgid
, ...))
1103 #ifndef ANSI_PROTOTYPES
1109 os
= output_buffer_state (diagnostic_buffer
);
1110 VA_START (ap
, msgid
);
1112 #ifndef ANSI_PROTOTYPES
1113 msgid
= va_arg (ap
, const char *);
1116 output_printf (diagnostic_buffer
, "%s: %s: ", progname
, xstrerror (errno
));
1117 output_buffer_ptr_to_format_args (diagnostic_buffer
) = &ap
;
1118 output_buffer_text_cursor (diagnostic_buffer
) = _(msgid
);
1119 output_format (diagnostic_buffer
);
1120 finish_diagnostic ();
1121 output_buffer_state (diagnostic_buffer
) = os
;
1123 exit (FATAL_EXIT_CODE
);
1126 /* Issue a pedantic warning MSGID. */
1129 pedwarn
VPARAMS ((const char *msgid
, ...))
1131 #ifndef ANSI_PROTOTYPES
1135 diagnostic_context dc
;
1137 VA_START (ap
, msgid
);
1139 #ifndef ANSI_PROTOTYPES
1140 msgid
= va_arg (ap
, const char *);
1143 set_diagnostic_context
1144 (&dc
, msgid
, &ap
, input_filename
, lineno
, !flag_pedantic_errors
);
1145 report_diagnostic (&dc
);
1149 /* Issue a pedantic waring about DECL. */
1152 pedwarn_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1154 #ifndef ANSI_PROTOTYPES
1160 VA_START (ap
, msgid
);
1162 #ifndef ANSI_PROTOTYPES
1163 decl
= va_arg (ap
, tree
);
1164 msgid
= va_arg (ap
, const char *);
1166 /* We don't want -pedantic-errors to cause the compilation to fail from
1167 "errors" in system header files. Sometimes fixincludes can't fix what's
1168 broken (eg: unsigned char bitfields - fixing it may change the alignment
1169 which will cause programs to mysteriously fail because the C library
1170 or kernel uses the original layout). There's no point in issuing a
1171 warning either, it's just unnecessary noise. */
1172 if (!DECL_IN_SYSTEM_HEADER (decl
))
1173 diagnostic_for_decl (decl
, msgid
, &ap
, !flag_pedantic_errors
);
1177 /* Same as above but within the context FILE and LINE. */
1180 pedwarn_with_file_and_line
VPARAMS ((const char *file
, int line
,
1181 const char *msgid
, ...))
1183 #ifndef ANSI_PROTOTYPES
1189 diagnostic_context dc
;
1191 VA_START (ap
, msgid
);
1193 #ifndef ANSI_PROTOTYPES
1194 file
= va_arg (ap
, const char *);
1195 line
= va_arg (ap
, int);
1196 msgid
= va_arg (ap
, const char *);
1199 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, !flag_pedantic_errors
);
1200 report_diagnostic (&dc
);
1204 /* Just apologize with MSGID. */
1207 sorry
VPARAMS ((const char *msgid
, ...))
1209 #ifndef ANSI_PROTOTYPES
1215 os
= output_buffer_state (diagnostic_buffer
);
1216 VA_START (ap
, msgid
);
1218 #ifndef ANSI_PROTOTYPES
1219 msgid
= va_arg (ap
, const char *);
1223 (diagnostic_buffer
, context_as_prefix (input_filename
, lineno
, 0));
1224 output_printf (diagnostic_buffer
, "sorry, not implemented: ");
1225 output_buffer_ptr_to_format_args (diagnostic_buffer
) = &ap
;
1226 output_buffer_text_cursor (diagnostic_buffer
) = _(msgid
);
1227 output_format (diagnostic_buffer
);
1228 finish_diagnostic ();
1229 output_buffer_state (diagnostic_buffer
) = os
;
1233 /* Called when the start of a function definition is parsed,
1234 this function prints on stderr the name of the function. */
1237 announce_function (decl
)
1242 if (rtl_dump_and_exit
)
1243 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl
)));
1245 verbatim (" %s", (*decl_printable_name
) (decl
, 2));
1247 output_needs_newline (diagnostic_buffer
) = 1;
1248 record_last_error_function ();
1252 /* The default function to print out name of current function that caused
1256 default_print_error_function (file
)
1259 if (error_function_changed ())
1261 char *prefix
= file
? build_message_string ("%s: ", file
) : NULL
;
1264 os
= output_buffer_state (diagnostic_buffer
);
1265 output_set_prefix (diagnostic_buffer
, prefix
);
1267 if (current_function_decl
== NULL
)
1268 output_add_string (diagnostic_buffer
, _("At top level:"));
1271 if (TREE_CODE (TREE_TYPE (current_function_decl
)) == METHOD_TYPE
)
1273 (diagnostic_buffer
, "In method `%s':",
1274 (*decl_printable_name
) (current_function_decl
, 2));
1277 (diagnostic_buffer
, "In function `%s':",
1278 (*decl_printable_name
) (current_function_decl
, 2));
1280 output_add_newline (diagnostic_buffer
);
1282 record_last_error_function ();
1283 output_to_stream (diagnostic_buffer
, stderr
);
1284 output_buffer_state (diagnostic_buffer
) = os
;
1285 free ((char*) prefix
);
1289 /* Prints out, if necessary, the name of the current function
1290 that caused an error. Called from all error and warning functions.
1291 We ignore the FILE parameter, as it cannot be relied upon. */
1294 report_error_function (file
)
1295 const char *file ATTRIBUTE_UNUSED
;
1297 report_problematic_module (diagnostic_buffer
);
1298 (*print_error_function
) (input_filename
);
1302 error_with_file_and_line
VPARAMS ((const char *file
, int line
,
1303 const char *msgid
, ...))
1305 #ifndef ANSI_PROTOTYPES
1311 diagnostic_context dc
;
1313 VA_START (ap
, msgid
);
1315 #ifndef ANSI_PROTOTYPES
1316 file
= va_arg (ap
, const char *);
1317 line
= va_arg (ap
, int);
1318 msgid
= va_arg (ap
, const char *);
1321 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, /* warn = */ 0);
1322 report_diagnostic (&dc
);
1327 error_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1329 #ifndef ANSI_PROTOTYPES
1335 VA_START (ap
, msgid
);
1337 #ifndef ANSI_PROTOTYPES
1338 decl
= va_arg (ap
, tree
);
1339 msgid
= va_arg (ap
, const char *);
1342 diagnostic_for_decl (decl
, msgid
, &ap
, /* warn = */ 0);
1347 error_for_asm
VPARAMS ((rtx insn
, const char *msgid
, ...))
1349 #ifndef ANSI_PROTOTYPES
1355 VA_START (ap
, msgid
);
1357 #ifndef ANSI_PROTOTYPES
1358 insn
= va_arg (ap
, rtx
);
1359 msgid
= va_arg (ap
, const char *);
1362 diagnostic_for_asm (insn
, msgid
, &ap
, /* warn = */ 0);
1366 /* Report an error message. The arguments are like that of printf. */
1369 error
VPARAMS ((const char *msgid
, ...))
1371 #ifndef ANSI_PROTOTYPES
1375 diagnostic_context dc
;
1377 VA_START (ap
, msgid
);
1379 #ifndef ANSI_PROTOTYPES
1380 msgid
= va_arg (ap
, const char *);
1383 set_diagnostic_context
1384 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 0);
1385 report_diagnostic (&dc
);
1389 /* Likewise, except that the compilation is terminated after printing the
1393 fatal_error
VPARAMS ((const char *msgid
, ...))
1395 #ifndef ANSI_PROTOTYPES
1399 diagnostic_context dc
;
1401 VA_START (ap
, msgid
);
1403 #ifndef ANSI_PROTOTYPES
1404 msgid
= va_arg (ap
, const char *);
1407 set_diagnostic_context
1408 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 0);
1409 report_diagnostic (&dc
);
1412 fnotice (stderr
, "compilation terminated.\n");
1413 exit (FATAL_EXIT_CODE
);
1416 /* Report a compiler error at the current line number. Allow a front end to
1417 intercept the message. */
1419 static void (*internal_error_function
) PARAMS ((const char *, va_list *));
1421 /* Set the function to call when a compiler error occurs. */
1424 set_internal_error_function (f
)
1425 void (*f
) PARAMS ((const char *, va_list *));
1427 internal_error_function
= f
;
1431 internal_error
VPARAMS ((const char *msgid
, ...))
1433 #ifndef ANSI_PROTOTYPES
1437 diagnostic_context dc
;
1439 VA_START (ap
, msgid
);
1441 #ifndef ANSI_PROTOTYPES
1442 msgid
= va_arg (ap
, const char *);
1445 if (errorcount
> 0 || sorrycount
> 0)
1447 fnotice (stderr
, "%s:%d: confused by earlier errors, bailing out\n",
1448 input_filename
, lineno
);
1449 exit (FATAL_EXIT_CODE
);
1452 if (internal_error_function
!= 0)
1453 (*internal_error_function
) (_(msgid
), &ap
);
1455 set_diagnostic_context
1456 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */0);
1457 report_diagnostic (&dc
);
1461 "Please submit a full bug report,\n\
1462 with preprocessed source if appropriate.\n\
1463 See %s for instructions.\n", GCCBUGURL
);
1464 exit (FATAL_EXIT_CODE
);
1468 _fatal_insn (msgid
, insn
, file
, line
, function
)
1473 const char *function
;
1475 error ("%s", _(msgid
));
1477 /* The above incremented error_count, but isn't an error that we want to
1478 count, so reset it here. */
1482 fancy_abort (file
, line
, function
);
1486 _fatal_insn_not_found (insn
, file
, line
, function
)
1490 const char *function
;
1492 if (INSN_CODE (insn
) < 0)
1493 _fatal_insn ("Unrecognizable insn:", insn
, file
, line
, function
);
1495 _fatal_insn ("Insn does not satisfy its constraints:",
1496 insn
, file
, line
, function
);
1500 warning_with_file_and_line
VPARAMS ((const char *file
, int line
,
1501 const char *msgid
, ...))
1503 #ifndef ANSI_PROTOTYPES
1509 diagnostic_context dc
;
1511 VA_START (ap
, msgid
);
1513 #ifndef ANSI_PROTOTYPES
1514 file
= va_arg (ap
, const char *);
1515 line
= va_arg (ap
, int);
1516 msgid
= va_arg (ap
, const char *);
1519 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, /* warn = */ 1);
1520 report_diagnostic (&dc
);
1525 warning_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1527 #ifndef ANSI_PROTOTYPES
1533 VA_START (ap
, msgid
);
1535 #ifndef ANSI_PROTOTYPES
1536 decl
= va_arg (ap
, tree
);
1537 msgid
= va_arg (ap
, const char *);
1540 diagnostic_for_decl (decl
, msgid
, &ap
, /* warn = */ 1);
1545 warning_for_asm
VPARAMS ((rtx insn
, const char *msgid
, ...))
1547 #ifndef ANSI_PROTOTYPES
1553 VA_START (ap
, msgid
);
1555 #ifndef ANSI_PROTOTYPES
1556 insn
= va_arg (ap
, rtx
);
1557 msgid
= va_arg (ap
, const char *);
1560 diagnostic_for_asm (insn
, msgid
, &ap
, /* warn = */ 1);
1565 warning
VPARAMS ((const char *msgid
, ...))
1567 #ifndef ANSI_PROTOTYPES
1571 diagnostic_context dc
;
1573 VA_START (ap
, msgid
);
1575 #ifndef ANSI_PROTOTYPES
1576 msgid
= va_arg (ap
, const char *);
1579 set_diagnostic_context
1580 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 1);
1581 report_diagnostic (&dc
);
1585 /* Flush diagnostic_buffer content on stderr. */
1588 finish_diagnostic ()
1590 output_to_stream (diagnostic_buffer
, stderr
);
1591 clear_diagnostic_info (diagnostic_buffer
);
1592 fputc ('\n', stderr
);
1596 /* Helper subroutine of output_verbatim and verbatim. Do the approriate
1597 settings needed by BUFFER for a verbatim formatting. */
1600 output_do_verbatim (buffer
, msgid
, args_ptr
)
1601 output_buffer
*buffer
;
1607 os
= output_buffer_state (buffer
);
1608 output_prefix (buffer
) = NULL
;
1609 prefixing_policy (buffer
) = DIAGNOSTICS_SHOW_PREFIX_NEVER
;
1610 output_buffer_text_cursor (buffer
) = _(msgid
);
1611 output_buffer_ptr_to_format_args (buffer
) = args_ptr
;
1612 output_set_maximum_length (buffer
, 0);
1613 output_format (buffer
);
1614 output_buffer_state (buffer
) = os
;
1617 /* Output MESSAGE verbatim into BUFFER. */
1620 output_verbatim
VPARAMS ((output_buffer
*buffer
, const char *msgid
, ...))
1622 #ifndef ANSI_PROTOTYPES
1623 output_buffer
*buffer
;
1628 VA_START (ap
, msgid
);
1629 #ifndef ANSI_PROTOTYPES
1630 buffer
= va_arg (ap
, output_buffer
*);
1631 msgid
= va_arg (ap
, const char *);
1633 output_do_verbatim (buffer
, msgid
, &ap
);
1637 /* Same as above but use diagnostic_buffer. */
1640 verbatim
VPARAMS ((const char *msgid
, ...))
1642 #ifndef ANSI_PROTOTYPES
1647 VA_START (ap
, msgid
);
1648 #ifndef ANSI_PROTOTYPES
1649 msgid
= va_arg (ap
, const char *);
1651 output_do_verbatim (diagnostic_buffer
, msgid
, &ap
);
1652 output_to_stream (diagnostic_buffer
, stderr
);
1656 /* Report a diagnostic message (an error or a warning) as specified by
1657 DC. This function is *the* subroutine in terms of which front-ends
1658 should implement their specific diagnostic handling modules. The
1659 front-end independent format specifiers are exactly those described
1660 in the documentation of output_format. */
1663 report_diagnostic (dc
)
1664 diagnostic_context
*dc
;
1668 if (diagnostic_lock
++)
1671 if (count_error (diagnostic_is_warning (dc
)))
1673 os
= output_buffer_state (diagnostic_buffer
);
1674 diagnostic_msg
= diagnostic_message (dc
);
1675 diagnostic_args
= diagnostic_argument_list (dc
);
1676 (*diagnostic_starter (dc
)) (diagnostic_buffer
, dc
);
1677 output_format (diagnostic_buffer
);
1678 (*diagnostic_finalizer (dc
)) (diagnostic_buffer
, dc
);
1679 finish_diagnostic ();
1680 output_buffer_state (diagnostic_buffer
) = os
;
1686 /* Inform the user that an error occurred while trying to report some
1687 other error. This indicates catastrophic internal inconsistencies,
1688 so give up now. But do try to flush out the previous error.
1689 This mustn't use internal_error, that will cause infinite recursion. */
1694 if (diagnostic_lock
< 3)
1695 finish_diagnostic ();
1698 "Internal compiler error: Error reporting routines re-entered.\n");
1700 "Please submit a full bug report,\n\
1701 with preprocessed source if appropriate.\n\
1702 See %s for instructions.\n", GCCBUGURL
);
1703 exit (FATAL_EXIT_CODE
);
1706 /* Given a partial pathname as input, return another pathname that
1707 shares no directory elements with the pathname of __FILE__. This
1708 is used by fancy_abort() to print `Internal compiler error in expr.c'
1709 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
1712 trim_filename (name
)
1715 static const char this_file
[] = __FILE__
;
1716 const char *p
= name
, *q
= this_file
;
1718 /* First skip any "../" in each filename. This allows us to give a proper
1719 reference to a file in a subdirectory. */
1720 while (p
[0] == '.' && p
[1] == '.'
1721 && (p
[2] == DIR_SEPARATOR
1722 #ifdef DIR_SEPARATOR_2
1723 || p
[2] == DIR_SEPARATOR_2
1728 while (q
[0] == '.' && q
[1] == '.'
1729 && (q
[2] == DIR_SEPARATOR
1730 #ifdef DIR_SEPARATOR_2
1731 || p
[2] == DIR_SEPARATOR_2
1736 /* Now skip any parts the two filenames have in common. */
1737 while (*p
== *q
&& *p
!= 0 && *q
!= 0)
1740 /* Now go backwards until the previous directory separator. */
1741 while (p
> name
&& p
[-1] != DIR_SEPARATOR
1742 #ifdef DIR_SEPARATOR_2
1743 && p
[-1] != DIR_SEPARATOR_2
1751 /* Report an internal compiler error in a friendly manner and without
1755 fancy_abort (file
, line
, function
)
1758 const char *function
;
1760 internal_error ("Internal compiler error in %s, at %s:%d",
1761 function
, trim_filename (file
), line
);
1764 /* Setup DC for reporting a diagnostic MESSAGE (an error or a WARNING),
1765 using arguments pointed to by ARGS_PTR, issued at a location specified
1766 by FILE and LINE. */
1769 set_diagnostic_context (dc
, msgid
, args_ptr
, file
, line
, warn
)
1770 diagnostic_context
*dc
;
1777 memset (dc
, 0, sizeof (diagnostic_context
));
1778 diagnostic_message (dc
) = _(msgid
);
1779 diagnostic_argument_list (dc
) = args_ptr
;
1780 diagnostic_file_location (dc
) = file
;
1781 diagnostic_line_location (dc
) = line
;
1782 diagnostic_is_warning (dc
) = warn
;
1783 diagnostic_starter (dc
) = lang_diagnostic_starter
;
1784 diagnostic_finalizer (dc
) = lang_diagnostic_finalizer
;
1788 report_problematic_module (buffer
)
1789 output_buffer
*buffer
;
1791 struct file_stack
*p
;
1793 if (output_needs_newline (buffer
))
1795 output_add_newline (buffer
);
1796 output_needs_newline (buffer
) = 0;
1799 if (input_file_stack
&& input_file_stack
->next
!= 0
1800 && error_module_changed ())
1802 for (p
= input_file_stack
->next
; p
; p
= p
->next
)
1803 if (p
== input_file_stack
->next
)
1805 (buffer
, "In file included from %s:%d", p
->name
, p
->line
);
1808 (buffer
, ",\n from %s:%d", p
->name
, p
->line
);
1809 output_verbatim (buffer
, ":\n");
1810 record_last_error_module ();
1815 default_diagnostic_starter (buffer
, dc
)
1816 output_buffer
*buffer
;
1817 diagnostic_context
*dc
;
1819 report_error_function (diagnostic_file_location (dc
));
1820 output_set_prefix (buffer
,
1821 context_as_prefix (diagnostic_file_location (dc
),
1822 diagnostic_line_location (dc
),
1823 diagnostic_is_warning (dc
)));
1827 default_diagnostic_finalizer (buffer
, dc
)
1828 output_buffer
*buffer
;
1829 diagnostic_context
*dc
__attribute__((__unused__
));
1831 output_destroy_prefix (buffer
);