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 ((BUFFER)->digit_buffer, FORMAT, INTEGER); \
48 output_add_string (BUFFER, (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 /* A diagnostic_context surrogate for stderr. */
112 static diagnostic_context global_diagnostic_context
;
113 diagnostic_context
*global_dc
= &global_diagnostic_context
;
115 /* This will be removed shortly. */
116 output_buffer
*diagnostic_buffer
= &global_diagnostic_context
.buffer
;
118 /* Function of last error message;
119 more generally, function such that if next error message is in it
120 then we don't have to mention the function name. */
121 static tree last_error_function
= NULL
;
123 /* Used to detect when input_file_stack has changed since last described. */
124 static int last_error_tick
;
126 /* Called by report_error_function to print out function name.
127 Default may be overridden by language front-ends. */
129 void (*print_error_function
) PARAMS ((const char *)) =
130 default_print_error_function
;
132 /* Maximum characters per line in automatic line wrapping mode.
133 Zero means don't wrap lines. */
135 int diagnostic_message_length_per_line
;
137 /* Used to control every diagnostic message formatting. Front-ends should
138 call set_message_prefixing_rule to set up their policies. */
139 static diagnostic_prefixing_rule_t current_prefixing_rule
;
141 /* Prevent recursion into the error handler. */
142 static int diagnostic_lock
;
145 /* Return truthvalue if current input file is different from the most recent
146 file involved in a diagnostic message. */
149 error_module_changed ()
151 return last_error_tick
!= input_file_stack_tick
;
154 /* Remember current file as being the most recent file involved in a
155 diagnostic message. */
158 record_last_error_module ()
160 last_error_tick
= input_file_stack_tick
;
163 /* Same as error_module_changed, but for function. */
166 error_function_changed ()
168 return last_error_function
!= current_function_decl
;
171 /* Same as record_last_error_module, but for function. */
174 record_last_error_function ()
176 last_error_function
= current_function_decl
;
179 /* Initialize the diagnostic message outputting machinery. */
182 initialize_diagnostics ()
184 /* By default, we don't line-wrap messages. */
185 diagnostic_message_length_per_line
= 0;
186 set_message_prefixing_rule (DIAGNOSTICS_SHOW_PREFIX_ONCE
);
188 /* Proceed to actual initialization. */
189 default_initialize_buffer (diagnostic_buffer
);
191 diagnostic_starter (global_dc
) = default_diagnostic_starter
;
192 diagnostic_finalizer (global_dc
) = default_diagnostic_finalizer
;
196 set_message_prefixing_rule (rule
)
197 diagnostic_prefixing_rule_t rule
;
199 current_prefixing_rule
= rule
;
202 /* Returns true if BUFFER is in line-wrappind mode. */
205 output_is_line_wrapping (buffer
)
206 output_buffer
*buffer
;
208 return ideal_line_wrap_cutoff (buffer
) > 0;
211 /* Return BUFFER's prefix. */
214 output_get_prefix (buffer
)
215 const output_buffer
*buffer
;
217 return output_prefix (buffer
);
220 /* Subroutine of output_set_maximum_length. Set up BUFFER's
221 internal maximum characters per line. */
224 set_real_maximum_length (buffer
)
225 output_buffer
*buffer
;
227 /* If we're told not to wrap lines then do the obvious thing. In case
228 we'll emit prefix only once per diagnostic message, it is appropriate
229 not to increase unncessarily the line-length cut-off. */
230 if (! output_is_line_wrapping (buffer
)
231 || prefixing_policy (buffer
) == DIAGNOSTICS_SHOW_PREFIX_ONCE
232 || prefixing_policy (buffer
) == DIAGNOSTICS_SHOW_PREFIX_NEVER
)
233 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
);
237 output_prefix (buffer
) ? strlen (output_prefix (buffer
)) : 0;
238 /* If the prefix is ridiculously too long, output at least
240 if (ideal_line_wrap_cutoff (buffer
) - prefix_length
< 32)
241 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
) + 32;
243 line_wrap_cutoff (buffer
) = ideal_line_wrap_cutoff (buffer
);
247 /* Sets the number of maximum characters per line BUFFER can output
248 in line-wrapping mode. A LENGTH value 0 suppresses line-wrapping. */
251 output_set_maximum_length (buffer
, length
)
252 output_buffer
*buffer
;
255 ideal_line_wrap_cutoff (buffer
) = length
;
256 set_real_maximum_length (buffer
);
259 /* Sets BUFFER's PREFIX. */
262 output_set_prefix (buffer
, prefix
)
263 output_buffer
*buffer
;
266 output_prefix (buffer
) = prefix
;
267 set_real_maximum_length (buffer
);
268 prefix_was_emitted_for (buffer
) = 0;
269 output_indentation (buffer
) = 0;
272 /* Return a pointer to the last character emitted in the output
273 BUFFER area. A NULL pointer means no character available. */
275 output_last_position (buffer
)
276 const output_buffer
*buffer
;
278 const char *p
= NULL
;
280 if (obstack_base (&buffer
->obstack
) != obstack_next_free (&buffer
->obstack
))
281 p
= ((const char *) obstack_next_free (&buffer
->obstack
)) - 1;
285 /* Free BUFFER's prefix, a previously malloc'd string. */
288 output_destroy_prefix (buffer
)
289 output_buffer
*buffer
;
291 if (output_prefix (buffer
) != NULL
)
293 free ((char *) output_prefix (buffer
));
294 output_prefix (buffer
) = NULL
;
298 /* Zero out any text output so far in BUFFER. */
301 output_clear_message_text (buffer
)
302 output_buffer
*buffer
;
304 obstack_free (&buffer
->obstack
, obstack_base (&buffer
->obstack
));
305 output_text_length (buffer
) = 0;
308 /* Zero out any diagnostic data used so far by BUFFER. */
311 clear_diagnostic_info (buffer
)
312 output_buffer
*buffer
;
314 output_buffer_text_cursor (buffer
) = NULL
;
315 output_buffer_ptr_to_format_args (buffer
) = NULL
;
316 prefix_was_emitted_for (buffer
) = 0;
317 output_indentation (buffer
) = 0;
320 /* Construct an output BUFFER with PREFIX and of MAXIMUM_LENGTH
321 characters per line. */
324 init_output_buffer (buffer
, prefix
, maximum_length
)
325 output_buffer
*buffer
;
329 memset (buffer
, 0, sizeof (output_buffer
));
330 obstack_init (&buffer
->obstack
);
331 output_buffer_attached_stream (buffer
) = stderr
;
332 ideal_line_wrap_cutoff (buffer
) = maximum_length
;
333 prefixing_policy (buffer
) = current_prefixing_rule
;
334 output_set_prefix (buffer
, prefix
);
335 output_text_length (buffer
) = 0;
336 clear_diagnostic_info (buffer
);
339 /* Initialize BUFFER with a NULL prefix and current diagnostic message
343 default_initialize_buffer (buffer
)
344 output_buffer
*buffer
;
346 init_output_buffer (buffer
, NULL
, diagnostic_message_length_per_line
);
349 /* Recompute diagnostic_buffer's attributes to reflect any change
350 in diagnostic formatting global options. */
353 reshape_diagnostic_buffer ()
355 ideal_line_wrap_cutoff (diagnostic_buffer
) =
356 diagnostic_message_length_per_line
;
357 prefixing_policy (diagnostic_buffer
) = current_prefixing_rule
;
358 set_real_maximum_length (diagnostic_buffer
);
361 /* Reinitialize BUFFER. */
364 output_clear (buffer
)
365 output_buffer
*buffer
;
367 output_clear_message_text (buffer
);
368 clear_diagnostic_info (buffer
);
371 /* Finishes constructing a NULL-terminated character string representing
372 the BUFFERed message. */
375 output_finalize_message (buffer
)
376 output_buffer
*buffer
;
378 obstack_1grow (&buffer
->obstack
, '\0');
379 return output_message_text (buffer
);
383 flush_diagnostic_buffer ()
385 output_buffer_to_stream (diagnostic_buffer
);
386 fflush (output_buffer_attached_stream (diagnostic_buffer
));
389 /* Return the amount of characters BUFFER can accept to
393 output_space_left (buffer
)
394 const output_buffer
*buffer
;
396 return line_wrap_cutoff (buffer
) - output_text_length (buffer
);
399 /* Write out BUFFER's prefix. */
402 output_emit_prefix (buffer
)
403 output_buffer
*buffer
;
405 if (output_prefix (buffer
) != NULL
)
407 switch (prefixing_policy (buffer
))
410 case DIAGNOSTICS_SHOW_PREFIX_NEVER
:
413 case DIAGNOSTICS_SHOW_PREFIX_ONCE
:
414 if (prefix_was_emitted_for (buffer
))
416 output_indent (buffer
);
419 output_indentation (buffer
) += 3;
422 case DIAGNOSTICS_SHOW_PREFIX_EVERY_LINE
:
424 int prefix_length
= strlen (output_prefix (buffer
));
425 output_append_r (buffer
, output_prefix (buffer
), prefix_length
);
426 prefix_was_emitted_for (buffer
) = 1;
433 /* Have BUFFER start a new line. */
436 output_add_newline (buffer
)
437 output_buffer
*buffer
;
439 obstack_1grow (&buffer
->obstack
, '\n');
440 output_text_length (buffer
) = 0;
443 /* Appends a character to BUFFER. */
446 output_add_character (buffer
, c
)
447 output_buffer
*buffer
;
450 if (output_is_line_wrapping (buffer
) && output_space_left (buffer
) <= 0)
451 output_add_newline (buffer
);
452 obstack_1grow (&buffer
->obstack
, c
);
453 ++output_text_length (buffer
);
456 /* Adds a space to BUFFER. */
459 output_add_space (buffer
)
460 output_buffer
*buffer
;
462 if (output_is_line_wrapping (buffer
) && output_space_left (buffer
) <= 0)
464 output_add_newline (buffer
);
467 obstack_1grow (&buffer
->obstack
, ' ');
468 ++output_text_length (buffer
);
471 /* These functions format an INTEGER into BUFFER as suggested by their
475 output_decimal (buffer
, i
)
476 output_buffer
*buffer
;
479 output_formatted_integer (buffer
, "%d", i
);
483 output_long_decimal (buffer
, i
)
484 output_buffer
*buffer
;
487 output_formatted_integer (buffer
, "%ld", i
);
491 output_unsigned_decimal (buffer
, i
)
492 output_buffer
*buffer
;
495 output_formatted_integer (buffer
, "%u", i
);
499 output_long_unsigned_decimal (buffer
, i
)
500 output_buffer
*buffer
;
503 output_formatted_integer (buffer
, "%lu", i
);
507 output_octal (buffer
, i
)
508 output_buffer
*buffer
;
511 output_formatted_integer (buffer
, "%o", i
);
515 output_long_octal (buffer
, i
)
516 output_buffer
*buffer
;
519 output_formatted_integer (buffer
, "%lo", i
);
523 output_hexadecimal (buffer
, i
)
524 output_buffer
*buffer
;
527 output_formatted_integer (buffer
, "%x", i
);
531 output_long_hexadecimal (buffer
, i
)
532 output_buffer
*buffer
;
535 output_formatted_integer (buffer
, "%lx", i
);
538 /* Append to BUFFER a string specified by its STARTING character
542 output_append_r (buffer
, start
, length
)
543 output_buffer
*buffer
;
547 obstack_grow (&buffer
->obstack
, start
, length
);
548 output_text_length (buffer
) += length
;
551 /* Append a string deliminated by START and END to BUFFER. No wrapping is
552 done. However, if beginning a new line then emit output_prefix (BUFFER)
553 and skip any leading whitespace if appropriate. The caller must ensure
554 that it is safe to do so. */
557 output_append (buffer
, start
, end
)
558 output_buffer
*buffer
;
562 /* Emit prefix and skip whitespace if we're starting a new line. */
563 if (is_starting_newline (buffer
))
565 output_emit_prefix (buffer
);
566 if (output_is_line_wrapping (buffer
))
567 while (start
!= end
&& *start
== ' ')
570 output_append_r (buffer
, start
, end
- start
);
574 output_indent (buffer
)
575 output_buffer
*buffer
;
577 int n
= output_indentation (buffer
);
580 for (i
= 0; i
< n
; ++i
)
581 output_add_character (buffer
, ' ');
584 /* Wrap a text delimited by START and END into BUFFER. */
587 wrap_text (buffer
, start
, end
)
588 output_buffer
*buffer
;
592 int is_wrapping
= output_is_line_wrapping (buffer
);
596 /* Dump anything bodered by whitespaces. */
598 const char *p
= start
;
599 while (p
!= end
&& *p
!= ' ' && *p
!= '\n')
601 if (is_wrapping
&& p
- start
>= output_space_left (buffer
))
602 output_add_newline (buffer
);
603 output_append (buffer
, start
, p
);
607 if (start
!= end
&& *start
== ' ')
609 output_add_space (buffer
);
612 if (start
!= end
&& *start
== '\n')
614 output_add_newline (buffer
);
620 /* Same as wrap_text but wrap text only when in line-wrapping mode. */
623 maybe_wrap_text (buffer
, start
, end
)
624 output_buffer
*buffer
;
628 if (output_is_line_wrapping (buffer
))
629 wrap_text (buffer
, start
, end
);
631 output_append (buffer
, start
, end
);
635 /* Append a STRING to BUFFER; the STRING might be line-wrapped if in
639 output_add_string (buffer
, str
)
640 output_buffer
*buffer
;
643 maybe_wrap_text (buffer
, str
, str
+ (str
? strlen (str
) : 0));
646 /* Flush the content of BUFFER onto the attached stream,
650 output_buffer_to_stream (buffer
)
651 output_buffer
*buffer
;
653 const char *text
= output_finalize_message (buffer
);
654 fputs (text
, output_buffer_attached_stream (buffer
));
655 output_clear_message_text (buffer
);
658 /* Format a message pointed to by output_buffer_text_cursor (BUFFER) using
659 output_buffer_format_args (BUFFER) as appropriate. The following format
660 specifiers are recognized as being language independent:
661 %d, %i: (signed) integer in base ten.
662 %u: unsigned integer in base ten.
663 %o: unsigned integer in base eight.
664 %x: unsigned integer in base sixteen.
665 %ld, %li, %lo, %lu, %lx: long versions of the above.
669 %*.s: a substring the length of which is specified by an integer. */
672 output_format (buffer
)
673 output_buffer
*buffer
;
675 for (; *output_buffer_text_cursor (buffer
);
676 ++output_buffer_text_cursor (buffer
))
678 int long_integer
= 0;
682 const char *p
= output_buffer_text_cursor (buffer
);
683 while (*p
&& *p
!= '%')
685 wrap_text (buffer
, output_buffer_text_cursor (buffer
), p
);
686 output_buffer_text_cursor (buffer
) = p
;
689 if (!*output_buffer_text_cursor (buffer
))
692 /* We got a '%'. Let's see what happens. Record whether we're
693 parsing a long integer format specifier. */
694 if (*++output_buffer_text_cursor (buffer
) == 'l')
697 ++output_buffer_text_cursor (buffer
);
700 /* Handle %c, %d, %i, %ld, %li, %lo, %lu, %lx, %o, %s, %u,
701 %x, %.*s; %%. And nothing else. Front-ends should install
702 printers to grok language specific format specifiers. */
703 switch (*output_buffer_text_cursor (buffer
))
707 (buffer
, va_arg (output_buffer_format_args (buffer
), int));
714 (buffer
, va_arg (output_buffer_format_args (buffer
), long int));
717 (buffer
, va_arg (output_buffer_format_args (buffer
), int));
722 output_long_octal (buffer
,
723 va_arg (output_buffer_format_args (buffer
),
726 output_octal (buffer
,
727 va_arg (output_buffer_format_args (buffer
),
732 output_add_string (buffer
,
733 va_arg (output_buffer_format_args (buffer
),
739 output_long_unsigned_decimal
740 (buffer
, va_arg (output_buffer_format_args (buffer
),
743 output_unsigned_decimal
744 (buffer
, va_arg (output_buffer_format_args (buffer
),
750 output_long_hexadecimal
751 (buffer
, va_arg (output_buffer_format_args (buffer
),
755 (buffer
, va_arg (output_buffer_format_args (buffer
),
760 output_add_character (buffer
, '%');
767 /* We handle no precision specifier but `%.*s'. */
768 if (*++output_buffer_text_cursor (buffer
) != '*')
770 else if (*++output_buffer_text_cursor (buffer
) != 's')
772 n
= va_arg (output_buffer_format_args (buffer
), int);
773 s
= va_arg (output_buffer_format_args (buffer
), const char *);
774 output_append (buffer
, s
, s
+ n
);
779 if (! lang_printer
|| !(*lang_printer
) (buffer
))
781 /* Hmmm. The front-end failed to install a format translator
782 but called us with an unrecognized format. Sorry. */
790 vbuild_message_string (msg
, ap
)
796 vasprintf (&str
, msg
, ap
);
800 /* Return a malloc'd string containing MSG formatted a la
801 printf. The caller is reponsible for freeing the memory. */
804 build_message_string
VPARAMS ((const char *msg
, ...))
806 #ifndef ANSI_PROTOTYPES
814 #ifndef ANSI_PROTOTYPES
815 msg
= va_arg (ap
, const char *);
818 str
= vbuild_message_string (msg
, ap
);
825 /* Return a malloc'd string describing a location. The caller is
826 responsible for freeing the memory. */
829 context_as_prefix (file
, line
, warn
)
837 return build_message_string (_("%s:%d: warning: "), file
, line
);
839 return build_message_string ("%s:%d: ", file
, line
);
844 return build_message_string (_("%s: warning: "), progname
);
846 return build_message_string ("%s: ", progname
);
850 /* Same as context_as_prefix, but only the source FILE is given. */
853 file_name_as_prefix (f
)
856 return build_message_string ("%s: ", f
);
859 /* Format a MESSAGE into BUFFER. Automatically wrap lines. */
862 output_do_printf (buffer
, msg
)
863 output_buffer
*buffer
;
866 char *message
= vbuild_message_string (msg
,
867 output_buffer_format_args (buffer
));
869 wrap_text (buffer
, message
, message
+ strlen (message
));
874 /* Format a message into BUFFER a la printf. */
877 output_printf
VPARAMS ((struct output_buffer
*buffer
, const char *msgid
, ...))
879 #ifndef ANSI_PROTOTYPES
880 struct output_buffer
*buffer
;
886 VA_START (ap
, msgid
);
887 #ifndef ANSI_PROTOTYPES
888 buffer
= va_arg (ap
, output_buffer
*);
889 msgid
= va_arg (ap
, const char *);
891 old_args
= output_buffer_ptr_to_format_args (buffer
);
892 output_buffer_ptr_to_format_args (buffer
) = &ap
;
893 output_do_printf (buffer
, _(msgid
));
894 output_buffer_ptr_to_format_args (buffer
) = old_args
;
898 /* Print a message relevant to the given DECL. */
901 format_with_decl (buffer
, decl
)
902 output_buffer
*buffer
;
907 /* Do magic to get around lack of varargs support for insertion
908 of arguments into existing list. We know that the decl is first;
909 we ass_u_me that it will be printed with "%s". */
910 for (p
= output_buffer_text_cursor (buffer
); *p
; ++p
)
916 else if (*(p
+ 1) != 's')
923 /* Print the left-hand substring. */
924 maybe_wrap_text (buffer
, output_buffer_text_cursor (buffer
), p
);
926 if (*p
== '%') /* Print the name. */
928 const char *n
= (DECL_NAME (decl
)
929 ? (*decl_printable_name
) (decl
, 2)
930 : _("((anonymous))"));
931 output_add_string (buffer
, n
);
935 if (ISALPHA (*(p
- 1) & 0xFF))
940 if (*p
) /* Print the rest of the message. */
942 output_buffer_text_cursor (buffer
) = p
;
943 output_format (buffer
);
947 /* Figure file and line of the given INSN. */
950 file_and_line_for_asm (insn
, pfile
, pline
)
955 rtx body
= PATTERN (insn
);
958 /* Find the (or one of the) ASM_OPERANDS in the insn. */
959 if (GET_CODE (body
) == SET
&& GET_CODE (SET_SRC (body
)) == ASM_OPERANDS
)
960 asmop
= SET_SRC (body
);
961 else if (GET_CODE (body
) == ASM_OPERANDS
)
963 else if (GET_CODE (body
) == PARALLEL
964 && GET_CODE (XVECEXP (body
, 0, 0)) == SET
)
965 asmop
= SET_SRC (XVECEXP (body
, 0, 0));
966 else if (GET_CODE (body
) == PARALLEL
967 && GET_CODE (XVECEXP (body
, 0, 0)) == ASM_OPERANDS
)
968 asmop
= XVECEXP (body
, 0, 0);
974 *pfile
= ASM_OPERANDS_SOURCE_FILE (asmop
);
975 *pline
= ASM_OPERANDS_SOURCE_LINE (asmop
);
979 *pfile
= input_filename
;
984 /* Report a diagnostic MESSAGE (an errror or a WARNING) at the line number
985 of the insn INSN. This is used only when INSN is an `asm' with operands,
986 and each ASM_OPERANDS records its own source file and line. */
989 diagnostic_for_asm (insn
, msg
, args_ptr
, warn
)
995 diagnostic_context dc
;
997 set_diagnostic_context (&dc
, msg
, args_ptr
, NULL
, 0, warn
);
998 file_and_line_for_asm (insn
, &diagnostic_file_location (&dc
),
999 &diagnostic_line_location (&dc
));
1000 report_diagnostic (&dc
);
1003 /* Report a diagnostic MESSAGE at the declaration DECL.
1004 MSG is a format string which uses %s to substitute the declaration
1005 name; subsequent substitutions are a la output_format. */
1008 diagnostic_for_decl (decl
, msgid
, args_ptr
, warn
)
1016 if (diagnostic_lock
++)
1019 if (count_error (warn
))
1021 os
= output_buffer_state (diagnostic_buffer
);
1022 report_error_function (DECL_SOURCE_FILE (decl
));
1024 (diagnostic_buffer
, context_as_prefix
1025 (DECL_SOURCE_FILE (decl
), DECL_SOURCE_LINE (decl
), warn
));
1026 output_buffer_ptr_to_format_args (diagnostic_buffer
) = args_ptr
;
1027 output_buffer_text_cursor (diagnostic_buffer
) = _(msgid
);
1028 format_with_decl (diagnostic_buffer
, decl
);
1029 finish_diagnostic ();
1030 output_destroy_prefix (diagnostic_buffer
);
1032 output_buffer_state (diagnostic_buffer
) = os
;
1038 /* Count an error or warning. Return 1 if the message should be printed. */
1041 count_error (warningp
)
1044 if (warningp
&& !diagnostic_report_warnings_p ())
1047 if (warningp
&& !warnings_are_errors
)
1051 static int warning_message
= 0;
1053 if (warningp
&& !warning_message
)
1055 verbatim ("%s: warnings being treated as errors\n", progname
);
1056 warning_message
= 1;
1064 /* Print a diagnostic MSGID on FILE. This is just fprintf, except it
1065 runs its second argument through gettext. */
1068 fnotice
VPARAMS ((FILE *file
, const char *msgid
, ...))
1070 #ifndef ANSI_PROTOTYPES
1076 VA_START (ap
, msgid
);
1078 #ifndef ANSI_PROTOTYPES
1079 file
= va_arg (ap
, FILE *);
1080 msgid
= va_arg (ap
, const char *);
1083 vfprintf (file
, _(msgid
), ap
);
1088 /* Print a fatal I/O error message. Argument are like printf.
1089 Also include a system error message based on `errno'. */
1092 fatal_io_error
VPARAMS ((const char *msgid
, ...))
1094 #ifndef ANSI_PROTOTYPES
1100 os
= output_buffer_state (diagnostic_buffer
);
1101 VA_START (ap
, msgid
);
1103 #ifndef ANSI_PROTOTYPES
1104 msgid
= va_arg (ap
, const char *);
1107 output_printf (diagnostic_buffer
, "%s: %s: ", progname
, xstrerror (errno
));
1108 output_buffer_ptr_to_format_args (diagnostic_buffer
) = &ap
;
1109 output_buffer_text_cursor (diagnostic_buffer
) = _(msgid
);
1110 output_format (diagnostic_buffer
);
1111 finish_diagnostic ();
1112 output_buffer_state (diagnostic_buffer
) = os
;
1114 exit (FATAL_EXIT_CODE
);
1117 /* Issue a pedantic warning MSGID. */
1120 pedwarn
VPARAMS ((const char *msgid
, ...))
1122 #ifndef ANSI_PROTOTYPES
1126 diagnostic_context dc
;
1128 VA_START (ap
, msgid
);
1130 #ifndef ANSI_PROTOTYPES
1131 msgid
= va_arg (ap
, const char *);
1134 set_diagnostic_context
1135 (&dc
, msgid
, &ap
, input_filename
, lineno
, !flag_pedantic_errors
);
1136 report_diagnostic (&dc
);
1140 /* Issue a pedantic waring about DECL. */
1143 pedwarn_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1145 #ifndef ANSI_PROTOTYPES
1151 VA_START (ap
, msgid
);
1153 #ifndef ANSI_PROTOTYPES
1154 decl
= va_arg (ap
, tree
);
1155 msgid
= va_arg (ap
, const char *);
1157 /* We don't want -pedantic-errors to cause the compilation to fail from
1158 "errors" in system header files. Sometimes fixincludes can't fix what's
1159 broken (eg: unsigned char bitfields - fixing it may change the alignment
1160 which will cause programs to mysteriously fail because the C library
1161 or kernel uses the original layout). There's no point in issuing a
1162 warning either, it's just unnecessary noise. */
1163 if (!DECL_IN_SYSTEM_HEADER (decl
))
1164 diagnostic_for_decl (decl
, msgid
, &ap
, !flag_pedantic_errors
);
1168 /* Same as above but within the context FILE and LINE. */
1171 pedwarn_with_file_and_line
VPARAMS ((const char *file
, int line
,
1172 const char *msgid
, ...))
1174 #ifndef ANSI_PROTOTYPES
1180 diagnostic_context dc
;
1182 VA_START (ap
, msgid
);
1184 #ifndef ANSI_PROTOTYPES
1185 file
= va_arg (ap
, const char *);
1186 line
= va_arg (ap
, int);
1187 msgid
= va_arg (ap
, const char *);
1190 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, !flag_pedantic_errors
);
1191 report_diagnostic (&dc
);
1195 /* Just apologize with MSGID. */
1198 sorry
VPARAMS ((const char *msgid
, ...))
1200 #ifndef ANSI_PROTOTYPES
1206 os
= output_buffer_state (diagnostic_buffer
);
1207 VA_START (ap
, msgid
);
1209 #ifndef ANSI_PROTOTYPES
1210 msgid
= va_arg (ap
, const char *);
1214 (diagnostic_buffer
, context_as_prefix (input_filename
, lineno
, 0));
1215 output_printf (diagnostic_buffer
, "sorry, not implemented: ");
1216 output_buffer_ptr_to_format_args (diagnostic_buffer
) = &ap
;
1217 output_buffer_text_cursor (diagnostic_buffer
) = _(msgid
);
1218 output_format (diagnostic_buffer
);
1219 finish_diagnostic ();
1220 output_buffer_state (diagnostic_buffer
) = os
;
1224 /* Called when the start of a function definition is parsed,
1225 this function prints on stderr the name of the function. */
1228 announce_function (decl
)
1233 if (rtl_dump_and_exit
)
1234 verbatim ("%s ", IDENTIFIER_POINTER (DECL_NAME (decl
)));
1236 verbatim (" %s", (*decl_printable_name
) (decl
, 2));
1238 output_needs_newline (diagnostic_buffer
) = 1;
1239 record_last_error_function ();
1243 /* The default function to print out name of current function that caused
1247 default_print_error_function (file
)
1250 if (error_function_changed ())
1252 char *prefix
= file
? build_message_string ("%s: ", file
) : NULL
;
1255 os
= output_buffer_state (diagnostic_buffer
);
1256 output_set_prefix (diagnostic_buffer
, prefix
);
1258 if (current_function_decl
== NULL
)
1259 output_add_string (diagnostic_buffer
, _("At top level:"));
1262 if (TREE_CODE (TREE_TYPE (current_function_decl
)) == METHOD_TYPE
)
1264 (diagnostic_buffer
, "In method `%s':",
1265 (*decl_printable_name
) (current_function_decl
, 2));
1268 (diagnostic_buffer
, "In function `%s':",
1269 (*decl_printable_name
) (current_function_decl
, 2));
1271 output_add_newline (diagnostic_buffer
);
1273 record_last_error_function ();
1274 output_buffer_to_stream (diagnostic_buffer
);
1275 output_buffer_state (diagnostic_buffer
) = os
;
1276 free ((char*) prefix
);
1280 /* Prints out, if necessary, the name of the current function
1281 that caused an error. Called from all error and warning functions.
1282 We ignore the FILE parameter, as it cannot be relied upon. */
1285 report_error_function (file
)
1286 const char *file ATTRIBUTE_UNUSED
;
1288 report_problematic_module (diagnostic_buffer
);
1289 (*print_error_function
) (input_filename
);
1293 error_with_file_and_line
VPARAMS ((const char *file
, int line
,
1294 const char *msgid
, ...))
1296 #ifndef ANSI_PROTOTYPES
1302 diagnostic_context dc
;
1304 VA_START (ap
, msgid
);
1306 #ifndef ANSI_PROTOTYPES
1307 file
= va_arg (ap
, const char *);
1308 line
= va_arg (ap
, int);
1309 msgid
= va_arg (ap
, const char *);
1312 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, /* warn = */ 0);
1313 report_diagnostic (&dc
);
1318 error_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1320 #ifndef ANSI_PROTOTYPES
1326 VA_START (ap
, msgid
);
1328 #ifndef ANSI_PROTOTYPES
1329 decl
= va_arg (ap
, tree
);
1330 msgid
= va_arg (ap
, const char *);
1333 diagnostic_for_decl (decl
, msgid
, &ap
, /* warn = */ 0);
1338 error_for_asm
VPARAMS ((rtx insn
, const char *msgid
, ...))
1340 #ifndef ANSI_PROTOTYPES
1346 VA_START (ap
, msgid
);
1348 #ifndef ANSI_PROTOTYPES
1349 insn
= va_arg (ap
, rtx
);
1350 msgid
= va_arg (ap
, const char *);
1353 diagnostic_for_asm (insn
, msgid
, &ap
, /* warn = */ 0);
1357 /* Report an error message. The arguments are like that of printf. */
1360 error
VPARAMS ((const char *msgid
, ...))
1362 #ifndef ANSI_PROTOTYPES
1366 diagnostic_context dc
;
1368 VA_START (ap
, msgid
);
1370 #ifndef ANSI_PROTOTYPES
1371 msgid
= va_arg (ap
, const char *);
1374 set_diagnostic_context
1375 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 0);
1376 report_diagnostic (&dc
);
1380 /* Likewise, except that the compilation is terminated after printing the
1384 fatal_error
VPARAMS ((const char *msgid
, ...))
1386 #ifndef ANSI_PROTOTYPES
1390 diagnostic_context dc
;
1392 VA_START (ap
, msgid
);
1394 #ifndef ANSI_PROTOTYPES
1395 msgid
= va_arg (ap
, const char *);
1398 set_diagnostic_context
1399 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 0);
1400 report_diagnostic (&dc
);
1403 fnotice (stderr
, "compilation terminated.\n");
1404 exit (FATAL_EXIT_CODE
);
1407 /* Report a compiler error at the current line number. Allow a front end to
1408 intercept the message. */
1410 static void (*internal_error_function
) PARAMS ((const char *, va_list *));
1412 /* Set the function to call when a compiler error occurs. */
1415 set_internal_error_function (f
)
1416 void (*f
) PARAMS ((const char *, va_list *));
1418 internal_error_function
= f
;
1422 internal_error
VPARAMS ((const char *msgid
, ...))
1424 #ifndef ANSI_PROTOTYPES
1428 diagnostic_context dc
;
1430 VA_START (ap
, msgid
);
1432 #ifndef ANSI_PROTOTYPES
1433 msgid
= va_arg (ap
, const char *);
1436 if (errorcount
> 0 || sorrycount
> 0)
1438 fnotice (stderr
, "%s:%d: confused by earlier errors, bailing out\n",
1439 input_filename
, lineno
);
1440 exit (FATAL_EXIT_CODE
);
1443 if (internal_error_function
!= 0)
1444 (*internal_error_function
) (_(msgid
), &ap
);
1446 set_diagnostic_context
1447 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */0);
1448 report_diagnostic (&dc
);
1452 "Please submit a full bug report,\n\
1453 with preprocessed source if appropriate.\n\
1454 See %s for instructions.\n", GCCBUGURL
);
1455 exit (FATAL_EXIT_CODE
);
1459 _fatal_insn (msgid
, insn
, file
, line
, function
)
1464 const char *function
;
1466 error ("%s", _(msgid
));
1468 /* The above incremented error_count, but isn't an error that we want to
1469 count, so reset it here. */
1473 fancy_abort (file
, line
, function
);
1477 _fatal_insn_not_found (insn
, file
, line
, function
)
1481 const char *function
;
1483 if (INSN_CODE (insn
) < 0)
1484 _fatal_insn ("Unrecognizable insn:", insn
, file
, line
, function
);
1486 _fatal_insn ("Insn does not satisfy its constraints:",
1487 insn
, file
, line
, function
);
1491 warning_with_file_and_line
VPARAMS ((const char *file
, int line
,
1492 const char *msgid
, ...))
1494 #ifndef ANSI_PROTOTYPES
1500 diagnostic_context dc
;
1502 VA_START (ap
, msgid
);
1504 #ifndef ANSI_PROTOTYPES
1505 file
= va_arg (ap
, const char *);
1506 line
= va_arg (ap
, int);
1507 msgid
= va_arg (ap
, const char *);
1510 set_diagnostic_context (&dc
, msgid
, &ap
, file
, line
, /* warn = */ 1);
1511 report_diagnostic (&dc
);
1516 warning_with_decl
VPARAMS ((tree decl
, const char *msgid
, ...))
1518 #ifndef ANSI_PROTOTYPES
1524 VA_START (ap
, msgid
);
1526 #ifndef ANSI_PROTOTYPES
1527 decl
= va_arg (ap
, tree
);
1528 msgid
= va_arg (ap
, const char *);
1531 diagnostic_for_decl (decl
, msgid
, &ap
, /* warn = */ 1);
1536 warning_for_asm
VPARAMS ((rtx insn
, const char *msgid
, ...))
1538 #ifndef ANSI_PROTOTYPES
1544 VA_START (ap
, msgid
);
1546 #ifndef ANSI_PROTOTYPES
1547 insn
= va_arg (ap
, rtx
);
1548 msgid
= va_arg (ap
, const char *);
1551 diagnostic_for_asm (insn
, msgid
, &ap
, /* warn = */ 1);
1556 warning
VPARAMS ((const char *msgid
, ...))
1558 #ifndef ANSI_PROTOTYPES
1562 diagnostic_context dc
;
1564 VA_START (ap
, msgid
);
1566 #ifndef ANSI_PROTOTYPES
1567 msgid
= va_arg (ap
, const char *);
1570 set_diagnostic_context
1571 (&dc
, msgid
, &ap
, input_filename
, lineno
, /* warn = */ 1);
1572 report_diagnostic (&dc
);
1576 /* Flush diagnostic_buffer content on stderr. */
1579 finish_diagnostic ()
1581 output_buffer_to_stream (diagnostic_buffer
);
1582 clear_diagnostic_info (diagnostic_buffer
);
1583 fputc ('\n', output_buffer_attached_stream (diagnostic_buffer
));
1584 fflush (output_buffer_attached_stream (diagnostic_buffer
));
1587 /* Helper subroutine of output_verbatim and verbatim. Do the approriate
1588 settings needed by BUFFER for a verbatim formatting. */
1591 output_do_verbatim (buffer
, msgid
, args_ptr
)
1592 output_buffer
*buffer
;
1598 os
= output_buffer_state (buffer
);
1599 output_prefix (buffer
) = NULL
;
1600 prefixing_policy (buffer
) = DIAGNOSTICS_SHOW_PREFIX_NEVER
;
1601 output_buffer_text_cursor (buffer
) = _(msgid
);
1602 output_buffer_ptr_to_format_args (buffer
) = args_ptr
;
1603 output_set_maximum_length (buffer
, 0);
1604 output_format (buffer
);
1605 output_buffer_state (buffer
) = os
;
1608 /* Output MESSAGE verbatim into BUFFER. */
1611 output_verbatim
VPARAMS ((output_buffer
*buffer
, const char *msgid
, ...))
1613 #ifndef ANSI_PROTOTYPES
1614 output_buffer
*buffer
;
1619 VA_START (ap
, msgid
);
1620 #ifndef ANSI_PROTOTYPES
1621 buffer
= va_arg (ap
, output_buffer
*);
1622 msg
= va_arg (ap
, const char *);
1624 output_do_verbatim (buffer
, msgid
, &ap
);
1628 /* Same as above but use diagnostic_buffer. */
1631 verbatim
VPARAMS ((const char *msgid
, ...))
1633 #ifndef ANSI_PROTOTYPES
1638 VA_START (ap
, msgid
);
1639 #ifndef ANSI_PROTOTYPES
1640 msgid
= va_arg (ap
, const char *);
1642 output_do_verbatim (diagnostic_buffer
, msgid
, &ap
);
1643 output_buffer_to_stream (diagnostic_buffer
);
1647 /* Report a diagnostic message (an error or a warning) as specified by
1648 DC. This function is *the* subroutine in terms of which front-ends
1649 should implement their specific diagnostic handling modules. The
1650 front-end independent format specifiers are exactly those described
1651 in the documentation of output_format. */
1654 report_diagnostic (dc
)
1655 diagnostic_context
*dc
;
1659 if (diagnostic_lock
++)
1662 if (count_error (diagnostic_is_warning (dc
)))
1664 os
= output_buffer_state (diagnostic_buffer
);
1665 diagnostic_msg
= diagnostic_message (dc
);
1666 diagnostic_args
= diagnostic_argument_list (dc
);
1667 (*diagnostic_starter (dc
)) (diagnostic_buffer
, dc
);
1668 output_format (diagnostic_buffer
);
1669 (*diagnostic_finalizer (dc
)) (diagnostic_buffer
, dc
);
1670 finish_diagnostic ();
1671 output_buffer_state (diagnostic_buffer
) = os
;
1677 /* Inform the user that an error occurred while trying to report some
1678 other error. This indicates catastrophic internal inconsistencies,
1679 so give up now. But do try to flush out the previous error.
1680 This mustn't use internal_error, that will cause infinite recursion. */
1685 if (diagnostic_lock
< 3)
1686 finish_diagnostic ();
1689 "Internal compiler error: Error reporting routines re-entered.\n");
1691 "Please submit a full bug report,\n\
1692 with preprocessed source if appropriate.\n\
1693 See %s for instructions.\n", GCCBUGURL
);
1694 exit (FATAL_EXIT_CODE
);
1697 /* Given a partial pathname as input, return another pathname that
1698 shares no directory elements with the pathname of __FILE__. This
1699 is used by fancy_abort() to print `Internal compiler error in expr.c'
1700 instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
1703 trim_filename (name
)
1706 static const char this_file
[] = __FILE__
;
1707 const char *p
= name
, *q
= this_file
;
1709 /* First skip any "../" in each filename. This allows us to give a proper
1710 reference to a file in a subdirectory. */
1711 while (p
[0] == '.' && p
[1] == '.'
1712 && (p
[2] == DIR_SEPARATOR
1713 #ifdef DIR_SEPARATOR_2
1714 || p
[2] == DIR_SEPARATOR_2
1719 while (q
[0] == '.' && q
[1] == '.'
1720 && (q
[2] == DIR_SEPARATOR
1721 #ifdef DIR_SEPARATOR_2
1722 || p
[2] == DIR_SEPARATOR_2
1727 /* Now skip any parts the two filenames have in common. */
1728 while (*p
== *q
&& *p
!= 0 && *q
!= 0)
1731 /* Now go backwards until the previous directory separator. */
1732 while (p
> name
&& p
[-1] != DIR_SEPARATOR
1733 #ifdef DIR_SEPARATOR_2
1734 && p
[-1] != DIR_SEPARATOR_2
1742 /* Report an internal compiler error in a friendly manner and without
1746 fancy_abort (file
, line
, function
)
1749 const char *function
;
1751 internal_error ("Internal compiler error in %s, at %s:%d",
1752 function
, trim_filename (file
), line
);
1755 /* Setup DC for reporting a diagnostic MESSAGE (an error or a WARNING),
1756 using arguments pointed to by ARGS_PTR, issued at a location specified
1757 by FILE and LINE. */
1760 set_diagnostic_context (dc
, msgid
, args_ptr
, file
, line
, warn
)
1761 diagnostic_context
*dc
;
1768 memset (dc
, 0, sizeof (diagnostic_context
));
1769 diagnostic_message (dc
) = _(msgid
);
1770 diagnostic_argument_list (dc
) = args_ptr
;
1771 diagnostic_file_location (dc
) = file
;
1772 diagnostic_line_location (dc
) = line
;
1773 diagnostic_is_warning (dc
) = warn
;
1774 diagnostic_starter (dc
) = diagnostic_starter (global_dc
);
1775 diagnostic_finalizer (dc
) = diagnostic_finalizer (global_dc
);
1779 report_problematic_module (buffer
)
1780 output_buffer
*buffer
;
1782 struct file_stack
*p
;
1784 if (output_needs_newline (buffer
))
1786 output_add_newline (buffer
);
1787 output_needs_newline (buffer
) = 0;
1790 if (input_file_stack
&& input_file_stack
->next
!= 0
1791 && error_module_changed ())
1793 for (p
= input_file_stack
->next
; p
; p
= p
->next
)
1794 if (p
== input_file_stack
->next
)
1796 (buffer
, "In file included from %s:%d", p
->name
, p
->line
);
1799 (buffer
, ",\n from %s:%d", p
->name
, p
->line
);
1800 output_verbatim (buffer
, ":\n");
1801 record_last_error_module ();
1806 default_diagnostic_starter (buffer
, dc
)
1807 output_buffer
*buffer
;
1808 diagnostic_context
*dc
;
1810 report_error_function (diagnostic_file_location (dc
));
1811 output_set_prefix (buffer
,
1812 context_as_prefix (diagnostic_file_location (dc
),
1813 diagnostic_line_location (dc
),
1814 diagnostic_is_warning (dc
)));
1818 default_diagnostic_finalizer (buffer
, dc
)
1819 output_buffer
*buffer
;
1820 diagnostic_context
*dc
__attribute__((__unused__
));
1822 output_destroy_prefix (buffer
);