1 |
684 |
jeremybenn |
/* Language-independent diagnostic subroutines for the GNU Compiler Collection
|
2 |
|
|
Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
|
3 |
|
|
2009, 2010, 2011, 2012 Free Software Foundation, Inc.
|
4 |
|
|
Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
|
5 |
|
|
|
6 |
|
|
This file is part of GCC.
|
7 |
|
|
|
8 |
|
|
GCC is free software; you can redistribute it and/or modify it under
|
9 |
|
|
the terms of the GNU General Public License as published by the Free
|
10 |
|
|
Software Foundation; either version 3, or (at your option) any later
|
11 |
|
|
version.
|
12 |
|
|
|
13 |
|
|
GCC is distributed in the hope that it will be useful, but WITHOUT ANY
|
14 |
|
|
WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
15 |
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
16 |
|
|
for more details.
|
17 |
|
|
|
18 |
|
|
You should have received a copy of the GNU General Public License
|
19 |
|
|
along with GCC; see the file COPYING3. If not see
|
20 |
|
|
<http://www.gnu.org/licenses/>. */
|
21 |
|
|
|
22 |
|
|
|
23 |
|
|
/* This file implements the language independent aspect of diagnostic
|
24 |
|
|
message module. */
|
25 |
|
|
|
26 |
|
|
#include "config.h"
|
27 |
|
|
#include "system.h"
|
28 |
|
|
#include "coretypes.h"
|
29 |
|
|
#include "version.h"
|
30 |
|
|
#include "input.h"
|
31 |
|
|
#include "intl.h"
|
32 |
|
|
#include "diagnostic.h"
|
33 |
|
|
|
34 |
|
|
#define pedantic_warning_kind(DC) \
|
35 |
|
|
((DC)->pedantic_errors ? DK_ERROR : DK_WARNING)
|
36 |
|
|
#define permissive_error_kind(DC) ((DC)->permissive ? DK_WARNING : DK_ERROR)
|
37 |
|
|
#define permissive_error_option(DC) ((DC)->opt_permissive)
|
38 |
|
|
|
39 |
|
|
/* Prototypes. */
|
40 |
|
|
static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
|
41 |
|
|
|
42 |
|
|
static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
|
43 |
|
|
|
44 |
|
|
static void diagnostic_action_after_output (diagnostic_context *,
|
45 |
|
|
diagnostic_info *);
|
46 |
|
|
static void real_abort (void) ATTRIBUTE_NORETURN;
|
47 |
|
|
|
48 |
|
|
/* Name of program invoked, sans directories. */
|
49 |
|
|
|
50 |
|
|
const char *progname;
|
51 |
|
|
|
52 |
|
|
/* A diagnostic_context surrogate for stderr. */
|
53 |
|
|
static diagnostic_context global_diagnostic_context;
|
54 |
|
|
diagnostic_context *global_dc = &global_diagnostic_context;
|
55 |
|
|
|
56 |
|
|
|
57 |
|
|
/* Return a malloc'd string containing MSG formatted a la printf. The
|
58 |
|
|
caller is responsible for freeing the memory. */
|
59 |
|
|
static char *
|
60 |
|
|
build_message_string (const char *msg, ...)
|
61 |
|
|
{
|
62 |
|
|
char *str;
|
63 |
|
|
va_list ap;
|
64 |
|
|
|
65 |
|
|
va_start (ap, msg);
|
66 |
|
|
vasprintf (&str, msg, ap);
|
67 |
|
|
va_end (ap);
|
68 |
|
|
|
69 |
|
|
return str;
|
70 |
|
|
}
|
71 |
|
|
|
72 |
|
|
/* Same as diagnostic_build_prefix, but only the source FILE is given. */
|
73 |
|
|
char *
|
74 |
|
|
file_name_as_prefix (const char *f)
|
75 |
|
|
{
|
76 |
|
|
return build_message_string ("%s: ", f);
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
|
|
/* Initialize the diagnostic message outputting machinery. */
|
82 |
|
|
void
|
83 |
|
|
diagnostic_initialize (diagnostic_context *context, int n_opts)
|
84 |
|
|
{
|
85 |
|
|
int i;
|
86 |
|
|
|
87 |
|
|
/* Allocate a basic pretty-printer. Clients will replace this a
|
88 |
|
|
much more elaborated pretty-printer if they wish. */
|
89 |
|
|
context->printer = XNEW (pretty_printer);
|
90 |
|
|
pp_construct (context->printer, NULL, 0);
|
91 |
|
|
/* By default, diagnostics are sent to stderr. */
|
92 |
|
|
context->printer->buffer->stream = stderr;
|
93 |
|
|
/* By default, we emit prefixes once per message. */
|
94 |
|
|
context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
|
95 |
|
|
|
96 |
|
|
memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
|
97 |
|
|
context->some_warnings_are_errors = false;
|
98 |
|
|
context->warning_as_error_requested = false;
|
99 |
|
|
context->n_opts = n_opts;
|
100 |
|
|
context->classify_diagnostic = XNEWVEC (diagnostic_t, n_opts);
|
101 |
|
|
for (i = 0; i < n_opts; i++)
|
102 |
|
|
context->classify_diagnostic[i] = DK_UNSPECIFIED;
|
103 |
|
|
context->show_option_requested = false;
|
104 |
|
|
context->abort_on_error = false;
|
105 |
|
|
context->show_column = false;
|
106 |
|
|
context->pedantic_errors = false;
|
107 |
|
|
context->permissive = false;
|
108 |
|
|
context->opt_permissive = 0;
|
109 |
|
|
context->fatal_errors = false;
|
110 |
|
|
context->dc_inhibit_warnings = false;
|
111 |
|
|
context->dc_warn_system_headers = false;
|
112 |
|
|
context->max_errors = 0;
|
113 |
|
|
context->internal_error = NULL;
|
114 |
|
|
diagnostic_starter (context) = default_diagnostic_starter;
|
115 |
|
|
diagnostic_finalizer (context) = default_diagnostic_finalizer;
|
116 |
|
|
context->option_enabled = NULL;
|
117 |
|
|
context->option_state = NULL;
|
118 |
|
|
context->option_name = NULL;
|
119 |
|
|
context->last_module = 0;
|
120 |
|
|
context->x_data = NULL;
|
121 |
|
|
context->lock = 0;
|
122 |
|
|
context->inhibit_notes_p = false;
|
123 |
|
|
}
|
124 |
|
|
|
125 |
|
|
/* Do any cleaning up required after the last diagnostic is emitted. */
|
126 |
|
|
|
127 |
|
|
void
|
128 |
|
|
diagnostic_finish (diagnostic_context *context)
|
129 |
|
|
{
|
130 |
|
|
/* Some of the errors may actually have been warnings. */
|
131 |
|
|
if (context->some_warnings_are_errors)
|
132 |
|
|
{
|
133 |
|
|
/* -Werror was given. */
|
134 |
|
|
if (context->warning_as_error_requested)
|
135 |
|
|
pp_verbatim (context->printer,
|
136 |
|
|
_("%s: all warnings being treated as errors"),
|
137 |
|
|
progname);
|
138 |
|
|
/* At least one -Werror= was given. */
|
139 |
|
|
else
|
140 |
|
|
pp_verbatim (context->printer,
|
141 |
|
|
_("%s: some warnings being treated as errors"),
|
142 |
|
|
progname);
|
143 |
|
|
pp_flush (context->printer);
|
144 |
|
|
}
|
145 |
|
|
}
|
146 |
|
|
|
147 |
|
|
/* Initialize DIAGNOSTIC, where the message MSG has already been
|
148 |
|
|
translated. */
|
149 |
|
|
void
|
150 |
|
|
diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
|
151 |
|
|
va_list *args, location_t location,
|
152 |
|
|
diagnostic_t kind)
|
153 |
|
|
{
|
154 |
|
|
diagnostic->message.err_no = errno;
|
155 |
|
|
diagnostic->message.args_ptr = args;
|
156 |
|
|
diagnostic->message.format_spec = msg;
|
157 |
|
|
diagnostic->location = location;
|
158 |
|
|
diagnostic->override_column = 0;
|
159 |
|
|
diagnostic->kind = kind;
|
160 |
|
|
diagnostic->option_index = 0;
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
/* Initialize DIAGNOSTIC, where the message GMSGID has not yet been
|
164 |
|
|
translated. */
|
165 |
|
|
void
|
166 |
|
|
diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid,
|
167 |
|
|
va_list *args, location_t location,
|
168 |
|
|
diagnostic_t kind)
|
169 |
|
|
{
|
170 |
|
|
diagnostic_set_info_translated (diagnostic, _(gmsgid), args, location, kind);
|
171 |
|
|
}
|
172 |
|
|
|
173 |
|
|
/* Return a malloc'd string describing a location. The caller is
|
174 |
|
|
responsible for freeing the memory. */
|
175 |
|
|
char *
|
176 |
|
|
diagnostic_build_prefix (diagnostic_context *context,
|
177 |
|
|
diagnostic_info *diagnostic)
|
178 |
|
|
{
|
179 |
|
|
static const char *const diagnostic_kind_text[] = {
|
180 |
|
|
#define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
|
181 |
|
|
#include "diagnostic.def"
|
182 |
|
|
#undef DEFINE_DIAGNOSTIC_KIND
|
183 |
|
|
"must-not-happen"
|
184 |
|
|
};
|
185 |
|
|
const char *text = _(diagnostic_kind_text[diagnostic->kind]);
|
186 |
|
|
expanded_location s = expand_location (diagnostic->location);
|
187 |
|
|
if (diagnostic->override_column)
|
188 |
|
|
s.column = diagnostic->override_column;
|
189 |
|
|
gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
|
190 |
|
|
|
191 |
|
|
return
|
192 |
|
|
(s.file == NULL
|
193 |
|
|
? build_message_string ("%s: %s", progname, text)
|
194 |
|
|
: context->show_column
|
195 |
|
|
? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text)
|
196 |
|
|
: build_message_string ("%s:%d: %s", s.file, s.line, text));
|
197 |
|
|
}
|
198 |
|
|
|
199 |
|
|
/* Take any action which is expected to happen after the diagnostic
|
200 |
|
|
is written out. This function does not always return. */
|
201 |
|
|
static void
|
202 |
|
|
diagnostic_action_after_output (diagnostic_context *context,
|
203 |
|
|
diagnostic_info *diagnostic)
|
204 |
|
|
{
|
205 |
|
|
switch (diagnostic->kind)
|
206 |
|
|
{
|
207 |
|
|
case DK_DEBUG:
|
208 |
|
|
case DK_NOTE:
|
209 |
|
|
case DK_ANACHRONISM:
|
210 |
|
|
case DK_WARNING:
|
211 |
|
|
break;
|
212 |
|
|
|
213 |
|
|
case DK_ERROR:
|
214 |
|
|
case DK_SORRY:
|
215 |
|
|
if (context->abort_on_error)
|
216 |
|
|
real_abort ();
|
217 |
|
|
if (context->fatal_errors)
|
218 |
|
|
{
|
219 |
|
|
fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
|
220 |
|
|
diagnostic_finish (context);
|
221 |
|
|
exit (FATAL_EXIT_CODE);
|
222 |
|
|
}
|
223 |
|
|
if (context->max_errors != 0
|
224 |
|
|
&& ((unsigned) (diagnostic_kind_count (context, DK_ERROR)
|
225 |
|
|
+ diagnostic_kind_count (context, DK_SORRY))
|
226 |
|
|
>= context->max_errors))
|
227 |
|
|
{
|
228 |
|
|
fnotice (stderr,
|
229 |
|
|
"compilation terminated due to -fmax-errors=%u.\n",
|
230 |
|
|
context->max_errors);
|
231 |
|
|
diagnostic_finish (context);
|
232 |
|
|
exit (FATAL_EXIT_CODE);
|
233 |
|
|
}
|
234 |
|
|
break;
|
235 |
|
|
|
236 |
|
|
case DK_ICE:
|
237 |
|
|
if (context->abort_on_error)
|
238 |
|
|
real_abort ();
|
239 |
|
|
|
240 |
|
|
fnotice (stderr, "Please submit a full bug report,\n"
|
241 |
|
|
"with preprocessed source if appropriate.\n"
|
242 |
|
|
"See %s for instructions.\n", bug_report_url);
|
243 |
|
|
exit (ICE_EXIT_CODE);
|
244 |
|
|
|
245 |
|
|
case DK_FATAL:
|
246 |
|
|
if (context->abort_on_error)
|
247 |
|
|
real_abort ();
|
248 |
|
|
diagnostic_finish (context);
|
249 |
|
|
fnotice (stderr, "compilation terminated.\n");
|
250 |
|
|
exit (FATAL_EXIT_CODE);
|
251 |
|
|
|
252 |
|
|
default:
|
253 |
|
|
gcc_unreachable ();
|
254 |
|
|
}
|
255 |
|
|
}
|
256 |
|
|
|
257 |
|
|
void
|
258 |
|
|
diagnostic_report_current_module (diagnostic_context *context, location_t where)
|
259 |
|
|
{
|
260 |
|
|
const struct line_map *map = NULL;
|
261 |
|
|
|
262 |
|
|
if (pp_needs_newline (context->printer))
|
263 |
|
|
{
|
264 |
|
|
pp_newline (context->printer);
|
265 |
|
|
pp_needs_newline (context->printer) = false;
|
266 |
|
|
}
|
267 |
|
|
|
268 |
|
|
if (where <= BUILTINS_LOCATION)
|
269 |
|
|
return;
|
270 |
|
|
|
271 |
|
|
linemap_resolve_location (line_table, where,
|
272 |
|
|
LRK_MACRO_DEFINITION_LOCATION,
|
273 |
|
|
&map);
|
274 |
|
|
|
275 |
|
|
if (map && diagnostic_last_module_changed (context, map))
|
276 |
|
|
{
|
277 |
|
|
diagnostic_set_last_module (context, map);
|
278 |
|
|
if (! MAIN_FILE_P (map))
|
279 |
|
|
{
|
280 |
|
|
map = INCLUDED_FROM (line_table, map);
|
281 |
|
|
if (context->show_column)
|
282 |
|
|
pp_verbatim (context->printer,
|
283 |
|
|
"In file included from %s:%d:%d",
|
284 |
|
|
LINEMAP_FILE (map),
|
285 |
|
|
LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
|
286 |
|
|
else
|
287 |
|
|
pp_verbatim (context->printer,
|
288 |
|
|
"In file included from %s:%d",
|
289 |
|
|
LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
|
290 |
|
|
while (! MAIN_FILE_P (map))
|
291 |
|
|
{
|
292 |
|
|
map = INCLUDED_FROM (line_table, map);
|
293 |
|
|
pp_verbatim (context->printer,
|
294 |
|
|
",\n from %s:%d",
|
295 |
|
|
LINEMAP_FILE (map), LAST_SOURCE_LINE (map));
|
296 |
|
|
}
|
297 |
|
|
pp_verbatim (context->printer, ":");
|
298 |
|
|
pp_newline (context->printer);
|
299 |
|
|
}
|
300 |
|
|
}
|
301 |
|
|
}
|
302 |
|
|
|
303 |
|
|
void
|
304 |
|
|
default_diagnostic_starter (diagnostic_context *context,
|
305 |
|
|
diagnostic_info *diagnostic)
|
306 |
|
|
{
|
307 |
|
|
diagnostic_report_current_module (context, diagnostic->location);
|
308 |
|
|
pp_set_prefix (context->printer, diagnostic_build_prefix (context,
|
309 |
|
|
diagnostic));
|
310 |
|
|
}
|
311 |
|
|
|
312 |
|
|
void
|
313 |
|
|
default_diagnostic_finalizer (diagnostic_context *context,
|
314 |
|
|
diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
|
315 |
|
|
{
|
316 |
|
|
pp_destroy_prefix (context->printer);
|
317 |
|
|
}
|
318 |
|
|
|
319 |
|
|
/* Interface to specify diagnostic kind overrides. Returns the
|
320 |
|
|
previous setting, or DK_UNSPECIFIED if the parameters are out of
|
321 |
|
|
range. */
|
322 |
|
|
diagnostic_t
|
323 |
|
|
diagnostic_classify_diagnostic (diagnostic_context *context,
|
324 |
|
|
int option_index,
|
325 |
|
|
diagnostic_t new_kind,
|
326 |
|
|
location_t where)
|
327 |
|
|
{
|
328 |
|
|
diagnostic_t old_kind;
|
329 |
|
|
|
330 |
|
|
if (option_index <= 0
|
331 |
|
|
|| option_index >= context->n_opts
|
332 |
|
|
|| new_kind >= DK_LAST_DIAGNOSTIC_KIND)
|
333 |
|
|
return DK_UNSPECIFIED;
|
334 |
|
|
|
335 |
|
|
old_kind = context->classify_diagnostic[option_index];
|
336 |
|
|
|
337 |
|
|
/* Handle pragmas separately, since we need to keep track of *where*
|
338 |
|
|
the pragmas were. */
|
339 |
|
|
if (where != UNKNOWN_LOCATION)
|
340 |
|
|
{
|
341 |
|
|
int i;
|
342 |
|
|
|
343 |
|
|
for (i = context->n_classification_history - 1; i >= 0; i --)
|
344 |
|
|
if (context->classification_history[i].option == option_index)
|
345 |
|
|
{
|
346 |
|
|
old_kind = context->classification_history[i].kind;
|
347 |
|
|
break;
|
348 |
|
|
}
|
349 |
|
|
|
350 |
|
|
i = context->n_classification_history;
|
351 |
|
|
context->classification_history =
|
352 |
|
|
(diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
|
353 |
|
|
* sizeof (diagnostic_classification_change_t));
|
354 |
|
|
context->classification_history[i].location = where;
|
355 |
|
|
context->classification_history[i].option = option_index;
|
356 |
|
|
context->classification_history[i].kind = new_kind;
|
357 |
|
|
context->n_classification_history ++;
|
358 |
|
|
}
|
359 |
|
|
else
|
360 |
|
|
context->classify_diagnostic[option_index] = new_kind;
|
361 |
|
|
|
362 |
|
|
return old_kind;
|
363 |
|
|
}
|
364 |
|
|
|
365 |
|
|
/* Save all diagnostic classifications in a stack. */
|
366 |
|
|
void
|
367 |
|
|
diagnostic_push_diagnostics (diagnostic_context *context, location_t where ATTRIBUTE_UNUSED)
|
368 |
|
|
{
|
369 |
|
|
context->push_list = (int *) xrealloc (context->push_list, (context->n_push + 1) * sizeof (int));
|
370 |
|
|
context->push_list[context->n_push ++] = context->n_classification_history;
|
371 |
|
|
}
|
372 |
|
|
|
373 |
|
|
/* Restore the topmost classification set off the stack. If the stack
|
374 |
|
|
is empty, revert to the state based on command line parameters. */
|
375 |
|
|
void
|
376 |
|
|
diagnostic_pop_diagnostics (diagnostic_context *context, location_t where)
|
377 |
|
|
{
|
378 |
|
|
int jump_to;
|
379 |
|
|
int i;
|
380 |
|
|
|
381 |
|
|
if (context->n_push)
|
382 |
|
|
jump_to = context->push_list [-- context->n_push];
|
383 |
|
|
else
|
384 |
|
|
jump_to = 0;
|
385 |
|
|
|
386 |
|
|
i = context->n_classification_history;
|
387 |
|
|
context->classification_history =
|
388 |
|
|
(diagnostic_classification_change_t *) xrealloc (context->classification_history, (i + 1)
|
389 |
|
|
* sizeof (diagnostic_classification_change_t));
|
390 |
|
|
context->classification_history[i].location = where;
|
391 |
|
|
context->classification_history[i].option = jump_to;
|
392 |
|
|
context->classification_history[i].kind = DK_POP;
|
393 |
|
|
context->n_classification_history ++;
|
394 |
|
|
}
|
395 |
|
|
|
396 |
|
|
/* Report a diagnostic message (an error or a warning) as specified by
|
397 |
|
|
DC. This function is *the* subroutine in terms of which front-ends
|
398 |
|
|
should implement their specific diagnostic handling modules. The
|
399 |
|
|
front-end independent format specifiers are exactly those described
|
400 |
|
|
in the documentation of output_format.
|
401 |
|
|
Return true if a diagnostic was printed, false otherwise. */
|
402 |
|
|
|
403 |
|
|
bool
|
404 |
|
|
diagnostic_report_diagnostic (diagnostic_context *context,
|
405 |
|
|
diagnostic_info *diagnostic)
|
406 |
|
|
{
|
407 |
|
|
location_t location = diagnostic->location;
|
408 |
|
|
diagnostic_t orig_diag_kind = diagnostic->kind;
|
409 |
|
|
const char *saved_format_spec;
|
410 |
|
|
|
411 |
|
|
/* Give preference to being able to inhibit warnings, before they
|
412 |
|
|
get reclassified to something else. */
|
413 |
|
|
if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN)
|
414 |
|
|
&& !diagnostic_report_warnings_p (context, location))
|
415 |
|
|
return false;
|
416 |
|
|
|
417 |
|
|
if (diagnostic->kind == DK_PEDWARN)
|
418 |
|
|
{
|
419 |
|
|
diagnostic->kind = pedantic_warning_kind (context);
|
420 |
|
|
/* We do this to avoid giving the message for -pedantic-errors. */
|
421 |
|
|
orig_diag_kind = diagnostic->kind;
|
422 |
|
|
}
|
423 |
|
|
|
424 |
|
|
if (diagnostic->kind == DK_NOTE && context->inhibit_notes_p)
|
425 |
|
|
return false;
|
426 |
|
|
|
427 |
|
|
if (context->lock > 0)
|
428 |
|
|
{
|
429 |
|
|
/* If we're reporting an ICE in the middle of some other error,
|
430 |
|
|
try to flush out the previous error, then let this one
|
431 |
|
|
through. Don't do this more than once. */
|
432 |
|
|
if (diagnostic->kind == DK_ICE && context->lock == 1)
|
433 |
|
|
pp_flush (context->printer);
|
434 |
|
|
else
|
435 |
|
|
error_recursion (context);
|
436 |
|
|
}
|
437 |
|
|
|
438 |
|
|
/* If the user requested that warnings be treated as errors, so be
|
439 |
|
|
it. Note that we do this before the next block so that
|
440 |
|
|
individual warnings can be overridden back to warnings with
|
441 |
|
|
-Wno-error=*. */
|
442 |
|
|
if (context->warning_as_error_requested
|
443 |
|
|
&& diagnostic->kind == DK_WARNING)
|
444 |
|
|
{
|
445 |
|
|
diagnostic->kind = DK_ERROR;
|
446 |
|
|
}
|
447 |
|
|
|
448 |
|
|
if (diagnostic->option_index)
|
449 |
|
|
{
|
450 |
|
|
diagnostic_t diag_class = DK_UNSPECIFIED;
|
451 |
|
|
|
452 |
|
|
/* This tests if the user provided the appropriate -Wfoo or
|
453 |
|
|
-Wno-foo option. */
|
454 |
|
|
if (! context->option_enabled (diagnostic->option_index,
|
455 |
|
|
context->option_state))
|
456 |
|
|
return false;
|
457 |
|
|
|
458 |
|
|
/* This tests for #pragma diagnostic changes. */
|
459 |
|
|
if (context->n_classification_history > 0)
|
460 |
|
|
{
|
461 |
|
|
int i;
|
462 |
|
|
/* FIXME: Stupid search. Optimize later. */
|
463 |
|
|
for (i = context->n_classification_history - 1; i >= 0; i --)
|
464 |
|
|
{
|
465 |
|
|
if (linemap_location_before_p
|
466 |
|
|
(line_table,
|
467 |
|
|
context->classification_history[i].location,
|
468 |
|
|
location))
|
469 |
|
|
{
|
470 |
|
|
if (context->classification_history[i].kind == (int) DK_POP)
|
471 |
|
|
{
|
472 |
|
|
i = context->classification_history[i].option;
|
473 |
|
|
continue;
|
474 |
|
|
}
|
475 |
|
|
if (context->classification_history[i].option == diagnostic->option_index)
|
476 |
|
|
{
|
477 |
|
|
diag_class = context->classification_history[i].kind;
|
478 |
|
|
if (diag_class != DK_UNSPECIFIED)
|
479 |
|
|
diagnostic->kind = diag_class;
|
480 |
|
|
break;
|
481 |
|
|
}
|
482 |
|
|
}
|
483 |
|
|
}
|
484 |
|
|
}
|
485 |
|
|
/* This tests if the user provided the appropriate -Werror=foo
|
486 |
|
|
option. */
|
487 |
|
|
if (diag_class == DK_UNSPECIFIED
|
488 |
|
|
&& context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
|
489 |
|
|
{
|
490 |
|
|
diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
|
491 |
|
|
}
|
492 |
|
|
/* This allows for future extensions, like temporarily disabling
|
493 |
|
|
warnings for ranges of source code. */
|
494 |
|
|
if (diagnostic->kind == DK_IGNORED)
|
495 |
|
|
return false;
|
496 |
|
|
}
|
497 |
|
|
|
498 |
|
|
if (orig_diag_kind == DK_WARNING && diagnostic->kind == DK_ERROR)
|
499 |
|
|
context->some_warnings_are_errors = true;
|
500 |
|
|
|
501 |
|
|
context->lock++;
|
502 |
|
|
|
503 |
|
|
if (diagnostic->kind == DK_ICE)
|
504 |
|
|
{
|
505 |
|
|
#ifndef ENABLE_CHECKING
|
506 |
|
|
/* When not checking, ICEs are converted to fatal errors when an
|
507 |
|
|
error has already occurred. This is counteracted by
|
508 |
|
|
abort_on_error. */
|
509 |
|
|
if ((diagnostic_kind_count (context, DK_ERROR) > 0
|
510 |
|
|
|| diagnostic_kind_count (context, DK_SORRY) > 0)
|
511 |
|
|
&& !context->abort_on_error)
|
512 |
|
|
{
|
513 |
|
|
expanded_location s = expand_location (diagnostic->location);
|
514 |
|
|
fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
|
515 |
|
|
s.file, s.line);
|
516 |
|
|
exit (ICE_EXIT_CODE);
|
517 |
|
|
}
|
518 |
|
|
#endif
|
519 |
|
|
if (context->internal_error)
|
520 |
|
|
(*context->internal_error) (context,
|
521 |
|
|
diagnostic->message.format_spec,
|
522 |
|
|
diagnostic->message.args_ptr);
|
523 |
|
|
}
|
524 |
|
|
++diagnostic_kind_count (context, diagnostic->kind);
|
525 |
|
|
|
526 |
|
|
saved_format_spec = diagnostic->message.format_spec;
|
527 |
|
|
if (context->show_option_requested)
|
528 |
|
|
{
|
529 |
|
|
char *option_text;
|
530 |
|
|
|
531 |
|
|
option_text = context->option_name (context, diagnostic->option_index,
|
532 |
|
|
orig_diag_kind, diagnostic->kind);
|
533 |
|
|
|
534 |
|
|
if (option_text)
|
535 |
|
|
{
|
536 |
|
|
diagnostic->message.format_spec
|
537 |
|
|
= ACONCAT ((diagnostic->message.format_spec,
|
538 |
|
|
" ",
|
539 |
|
|
"[", option_text, "]",
|
540 |
|
|
NULL));
|
541 |
|
|
free (option_text);
|
542 |
|
|
}
|
543 |
|
|
}
|
544 |
|
|
diagnostic->message.locus = &diagnostic->location;
|
545 |
|
|
diagnostic->message.x_data = &diagnostic->x_data;
|
546 |
|
|
diagnostic->x_data = NULL;
|
547 |
|
|
pp_format (context->printer, &diagnostic->message);
|
548 |
|
|
(*diagnostic_starter (context)) (context, diagnostic);
|
549 |
|
|
pp_output_formatted_text (context->printer);
|
550 |
|
|
(*diagnostic_finalizer (context)) (context, diagnostic);
|
551 |
|
|
pp_flush (context->printer);
|
552 |
|
|
diagnostic_action_after_output (context, diagnostic);
|
553 |
|
|
diagnostic->message.format_spec = saved_format_spec;
|
554 |
|
|
diagnostic->x_data = NULL;
|
555 |
|
|
|
556 |
|
|
context->lock--;
|
557 |
|
|
|
558 |
|
|
return true;
|
559 |
|
|
}
|
560 |
|
|
|
561 |
|
|
/* Given a partial pathname as input, return another pathname that
|
562 |
|
|
shares no directory elements with the pathname of __FILE__. This
|
563 |
|
|
is used by fancy_abort() to print `Internal compiler error in expr.c'
|
564 |
|
|
instead of `Internal compiler error in ../../GCC/gcc/expr.c'. */
|
565 |
|
|
|
566 |
|
|
const char *
|
567 |
|
|
trim_filename (const char *name)
|
568 |
|
|
{
|
569 |
|
|
static const char this_file[] = __FILE__;
|
570 |
|
|
const char *p = name, *q = this_file;
|
571 |
|
|
|
572 |
|
|
/* First skip any "../" in each filename. This allows us to give a proper
|
573 |
|
|
reference to a file in a subdirectory. */
|
574 |
|
|
while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2]))
|
575 |
|
|
p += 3;
|
576 |
|
|
|
577 |
|
|
while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2]))
|
578 |
|
|
q += 3;
|
579 |
|
|
|
580 |
|
|
/* Now skip any parts the two filenames have in common. */
|
581 |
|
|
while (*p == *q && *p != 0 && *q != 0)
|
582 |
|
|
p++, q++;
|
583 |
|
|
|
584 |
|
|
/* Now go backwards until the previous directory separator. */
|
585 |
|
|
while (p > name && !IS_DIR_SEPARATOR (p[-1]))
|
586 |
|
|
p--;
|
587 |
|
|
|
588 |
|
|
return p;
|
589 |
|
|
}
|
590 |
|
|
|
591 |
|
|
/* Standard error reporting routines in increasing order of severity.
|
592 |
|
|
All of these take arguments like printf. */
|
593 |
|
|
|
594 |
|
|
/* Text to be emitted verbatim to the error message stream; this
|
595 |
|
|
produces no prefix and disables line-wrapping. Use rarely. */
|
596 |
|
|
void
|
597 |
|
|
verbatim (const char *gmsgid, ...)
|
598 |
|
|
{
|
599 |
|
|
text_info text;
|
600 |
|
|
va_list ap;
|
601 |
|
|
|
602 |
|
|
va_start (ap, gmsgid);
|
603 |
|
|
text.err_no = errno;
|
604 |
|
|
text.args_ptr = ≈
|
605 |
|
|
text.format_spec = _(gmsgid);
|
606 |
|
|
text.locus = NULL;
|
607 |
|
|
text.x_data = NULL;
|
608 |
|
|
pp_format_verbatim (global_dc->printer, &text);
|
609 |
|
|
pp_flush (global_dc->printer);
|
610 |
|
|
va_end (ap);
|
611 |
|
|
}
|
612 |
|
|
|
613 |
|
|
bool
|
614 |
|
|
emit_diagnostic (diagnostic_t kind, location_t location, int opt,
|
615 |
|
|
const char *gmsgid, ...)
|
616 |
|
|
{
|
617 |
|
|
diagnostic_info diagnostic;
|
618 |
|
|
va_list ap;
|
619 |
|
|
|
620 |
|
|
va_start (ap, gmsgid);
|
621 |
|
|
if (kind == DK_PERMERROR)
|
622 |
|
|
{
|
623 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
|
624 |
|
|
permissive_error_kind (global_dc));
|
625 |
|
|
diagnostic.option_index = permissive_error_option (global_dc);
|
626 |
|
|
}
|
627 |
|
|
else {
|
628 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, location, kind);
|
629 |
|
|
if (kind == DK_WARNING || kind == DK_PEDWARN)
|
630 |
|
|
diagnostic.option_index = opt;
|
631 |
|
|
}
|
632 |
|
|
va_end (ap);
|
633 |
|
|
|
634 |
|
|
return report_diagnostic (&diagnostic);
|
635 |
|
|
}
|
636 |
|
|
|
637 |
|
|
/* An informative note at LOCATION. Use this for additional details on an error
|
638 |
|
|
message. */
|
639 |
|
|
void
|
640 |
|
|
inform (location_t location, const char *gmsgid, ...)
|
641 |
|
|
{
|
642 |
|
|
diagnostic_info diagnostic;
|
643 |
|
|
va_list ap;
|
644 |
|
|
|
645 |
|
|
va_start (ap, gmsgid);
|
646 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE);
|
647 |
|
|
report_diagnostic (&diagnostic);
|
648 |
|
|
va_end (ap);
|
649 |
|
|
}
|
650 |
|
|
|
651 |
|
|
/* An informative note at LOCATION. Use this for additional details on an
|
652 |
|
|
error message. */
|
653 |
|
|
void
|
654 |
|
|
inform_n (location_t location, int n, const char *singular_gmsgid,
|
655 |
|
|
const char *plural_gmsgid, ...)
|
656 |
|
|
{
|
657 |
|
|
diagnostic_info diagnostic;
|
658 |
|
|
va_list ap;
|
659 |
|
|
|
660 |
|
|
va_start (ap, plural_gmsgid);
|
661 |
|
|
diagnostic_set_info_translated (&diagnostic,
|
662 |
|
|
ngettext (singular_gmsgid, plural_gmsgid, n),
|
663 |
|
|
&ap, location, DK_NOTE);
|
664 |
|
|
report_diagnostic (&diagnostic);
|
665 |
|
|
va_end (ap);
|
666 |
|
|
}
|
667 |
|
|
|
668 |
|
|
/* A warning at INPUT_LOCATION. Use this for code which is correct according
|
669 |
|
|
to the relevant language specification but is likely to be buggy anyway.
|
670 |
|
|
Returns true if the warning was printed, false if it was inhibited. */
|
671 |
|
|
bool
|
672 |
|
|
warning (int opt, const char *gmsgid, ...)
|
673 |
|
|
{
|
674 |
|
|
diagnostic_info diagnostic;
|
675 |
|
|
va_list ap;
|
676 |
|
|
|
677 |
|
|
va_start (ap, gmsgid);
|
678 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING);
|
679 |
|
|
diagnostic.option_index = opt;
|
680 |
|
|
|
681 |
|
|
va_end (ap);
|
682 |
|
|
return report_diagnostic (&diagnostic);
|
683 |
|
|
}
|
684 |
|
|
|
685 |
|
|
/* A warning at LOCATION. Use this for code which is correct according to the
|
686 |
|
|
relevant language specification but is likely to be buggy anyway.
|
687 |
|
|
Returns true if the warning was printed, false if it was inhibited. */
|
688 |
|
|
|
689 |
|
|
bool
|
690 |
|
|
warning_at (location_t location, int opt, const char *gmsgid, ...)
|
691 |
|
|
{
|
692 |
|
|
diagnostic_info diagnostic;
|
693 |
|
|
va_list ap;
|
694 |
|
|
|
695 |
|
|
va_start (ap, gmsgid);
|
696 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING);
|
697 |
|
|
diagnostic.option_index = opt;
|
698 |
|
|
va_end (ap);
|
699 |
|
|
return report_diagnostic (&diagnostic);
|
700 |
|
|
}
|
701 |
|
|
|
702 |
|
|
/* A "pedantic" warning at LOCATION: issues a warning unless
|
703 |
|
|
-pedantic-errors was given on the command line, in which case it
|
704 |
|
|
issues an error. Use this for diagnostics required by the relevant
|
705 |
|
|
language standard, if you have chosen not to make them errors.
|
706 |
|
|
|
707 |
|
|
Note that these diagnostics are issued independent of the setting
|
708 |
|
|
of the -pedantic command-line switch. To get a warning enabled
|
709 |
|
|
only with that switch, use either "if (pedantic) pedwarn
|
710 |
|
|
(OPT_pedantic,...)" or just "pedwarn (OPT_pedantic,..)". To get a
|
711 |
|
|
pedwarn independently of the -pedantic switch use "pedwarn (0,...)".
|
712 |
|
|
|
713 |
|
|
Returns true if the warning was printed, false if it was inhibited. */
|
714 |
|
|
|
715 |
|
|
bool
|
716 |
|
|
pedwarn (location_t location, int opt, const char *gmsgid, ...)
|
717 |
|
|
{
|
718 |
|
|
diagnostic_info diagnostic;
|
719 |
|
|
va_list ap;
|
720 |
|
|
|
721 |
|
|
va_start (ap, gmsgid);
|
722 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_PEDWARN);
|
723 |
|
|
diagnostic.option_index = opt;
|
724 |
|
|
va_end (ap);
|
725 |
|
|
return report_diagnostic (&diagnostic);
|
726 |
|
|
}
|
727 |
|
|
|
728 |
|
|
/* A "permissive" error at LOCATION: issues an error unless
|
729 |
|
|
-fpermissive was given on the command line, in which case it issues
|
730 |
|
|
a warning. Use this for things that really should be errors but we
|
731 |
|
|
want to support legacy code.
|
732 |
|
|
|
733 |
|
|
Returns true if the warning was printed, false if it was inhibited. */
|
734 |
|
|
|
735 |
|
|
bool
|
736 |
|
|
permerror (location_t location, const char *gmsgid, ...)
|
737 |
|
|
{
|
738 |
|
|
diagnostic_info diagnostic;
|
739 |
|
|
va_list ap;
|
740 |
|
|
|
741 |
|
|
va_start (ap, gmsgid);
|
742 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
|
743 |
|
|
permissive_error_kind (global_dc));
|
744 |
|
|
diagnostic.option_index = permissive_error_option (global_dc);
|
745 |
|
|
va_end (ap);
|
746 |
|
|
return report_diagnostic (&diagnostic);
|
747 |
|
|
}
|
748 |
|
|
|
749 |
|
|
/* A hard error: the code is definitely ill-formed, and an object file
|
750 |
|
|
will not be produced. */
|
751 |
|
|
void
|
752 |
|
|
error (const char *gmsgid, ...)
|
753 |
|
|
{
|
754 |
|
|
diagnostic_info diagnostic;
|
755 |
|
|
va_list ap;
|
756 |
|
|
|
757 |
|
|
va_start (ap, gmsgid);
|
758 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR);
|
759 |
|
|
report_diagnostic (&diagnostic);
|
760 |
|
|
va_end (ap);
|
761 |
|
|
}
|
762 |
|
|
|
763 |
|
|
/* A hard error: the code is definitely ill-formed, and an object file
|
764 |
|
|
will not be produced. */
|
765 |
|
|
void
|
766 |
|
|
error_n (location_t location, int n, const char *singular_gmsgid,
|
767 |
|
|
const char *plural_gmsgid, ...)
|
768 |
|
|
{
|
769 |
|
|
diagnostic_info diagnostic;
|
770 |
|
|
va_list ap;
|
771 |
|
|
|
772 |
|
|
va_start (ap, plural_gmsgid);
|
773 |
|
|
diagnostic_set_info_translated (&diagnostic,
|
774 |
|
|
ngettext (singular_gmsgid, plural_gmsgid, n),
|
775 |
|
|
&ap, location, DK_ERROR);
|
776 |
|
|
report_diagnostic (&diagnostic);
|
777 |
|
|
va_end (ap);
|
778 |
|
|
}
|
779 |
|
|
|
780 |
|
|
/* Same as ebove, but use location LOC instead of input_location. */
|
781 |
|
|
void
|
782 |
|
|
error_at (location_t loc, const char *gmsgid, ...)
|
783 |
|
|
{
|
784 |
|
|
diagnostic_info diagnostic;
|
785 |
|
|
va_list ap;
|
786 |
|
|
|
787 |
|
|
va_start (ap, gmsgid);
|
788 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, loc, DK_ERROR);
|
789 |
|
|
report_diagnostic (&diagnostic);
|
790 |
|
|
va_end (ap);
|
791 |
|
|
}
|
792 |
|
|
|
793 |
|
|
/* "Sorry, not implemented." Use for a language feature which is
|
794 |
|
|
required by the relevant specification but not implemented by GCC.
|
795 |
|
|
An object file will not be produced. */
|
796 |
|
|
void
|
797 |
|
|
sorry (const char *gmsgid, ...)
|
798 |
|
|
{
|
799 |
|
|
diagnostic_info diagnostic;
|
800 |
|
|
va_list ap;
|
801 |
|
|
|
802 |
|
|
va_start (ap, gmsgid);
|
803 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_SORRY);
|
804 |
|
|
report_diagnostic (&diagnostic);
|
805 |
|
|
va_end (ap);
|
806 |
|
|
}
|
807 |
|
|
|
808 |
|
|
/* Return true if an error or a "sorry" has been seen. Various
|
809 |
|
|
processing is disabled after errors. */
|
810 |
|
|
bool
|
811 |
|
|
seen_error (void)
|
812 |
|
|
{
|
813 |
|
|
return errorcount || sorrycount;
|
814 |
|
|
}
|
815 |
|
|
|
816 |
|
|
/* An error which is severe enough that we make no attempt to
|
817 |
|
|
continue. Do not use this for internal consistency checks; that's
|
818 |
|
|
internal_error. Use of this function should be rare. */
|
819 |
|
|
void
|
820 |
|
|
fatal_error (const char *gmsgid, ...)
|
821 |
|
|
{
|
822 |
|
|
diagnostic_info diagnostic;
|
823 |
|
|
va_list ap;
|
824 |
|
|
|
825 |
|
|
va_start (ap, gmsgid);
|
826 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_FATAL);
|
827 |
|
|
report_diagnostic (&diagnostic);
|
828 |
|
|
va_end (ap);
|
829 |
|
|
|
830 |
|
|
gcc_unreachable ();
|
831 |
|
|
}
|
832 |
|
|
|
833 |
|
|
/* An internal consistency check has failed. We make no attempt to
|
834 |
|
|
continue. Note that unless there is debugging value to be had from
|
835 |
|
|
a more specific message, or some other good reason, you should use
|
836 |
|
|
abort () instead of calling this function directly. */
|
837 |
|
|
void
|
838 |
|
|
internal_error (const char *gmsgid, ...)
|
839 |
|
|
{
|
840 |
|
|
diagnostic_info diagnostic;
|
841 |
|
|
va_list ap;
|
842 |
|
|
|
843 |
|
|
va_start (ap, gmsgid);
|
844 |
|
|
diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ICE);
|
845 |
|
|
report_diagnostic (&diagnostic);
|
846 |
|
|
va_end (ap);
|
847 |
|
|
|
848 |
|
|
gcc_unreachable ();
|
849 |
|
|
}
|
850 |
|
|
|
851 |
|
|
/* Special case error functions. Most are implemented in terms of the
|
852 |
|
|
above, or should be. */
|
853 |
|
|
|
854 |
|
|
/* Print a diagnostic MSGID on FILE. This is just fprintf, except it
|
855 |
|
|
runs its second argument through gettext. */
|
856 |
|
|
void
|
857 |
|
|
fnotice (FILE *file, const char *cmsgid, ...)
|
858 |
|
|
{
|
859 |
|
|
va_list ap;
|
860 |
|
|
|
861 |
|
|
va_start (ap, cmsgid);
|
862 |
|
|
vfprintf (file, _(cmsgid), ap);
|
863 |
|
|
va_end (ap);
|
864 |
|
|
}
|
865 |
|
|
|
866 |
|
|
/* Inform the user that an error occurred while trying to report some
|
867 |
|
|
other error. This indicates catastrophic internal inconsistencies,
|
868 |
|
|
so give up now. But do try to flush out the previous error.
|
869 |
|
|
This mustn't use internal_error, that will cause infinite recursion. */
|
870 |
|
|
|
871 |
|
|
static void
|
872 |
|
|
error_recursion (diagnostic_context *context)
|
873 |
|
|
{
|
874 |
|
|
diagnostic_info diagnostic;
|
875 |
|
|
|
876 |
|
|
if (context->lock < 3)
|
877 |
|
|
pp_flush (context->printer);
|
878 |
|
|
|
879 |
|
|
fnotice (stderr,
|
880 |
|
|
"Internal compiler error: Error reporting routines re-entered.\n");
|
881 |
|
|
|
882 |
|
|
/* Call diagnostic_action_after_output to get the "please submit a bug
|
883 |
|
|
report" message. It only looks at the kind field of diagnostic_info. */
|
884 |
|
|
diagnostic.kind = DK_ICE;
|
885 |
|
|
diagnostic_action_after_output (context, &diagnostic);
|
886 |
|
|
|
887 |
|
|
/* Do not use gcc_unreachable here; that goes through internal_error
|
888 |
|
|
and therefore would cause infinite recursion. */
|
889 |
|
|
real_abort ();
|
890 |
|
|
}
|
891 |
|
|
|
892 |
|
|
/* Report an internal compiler error in a friendly manner. This is
|
893 |
|
|
the function that gets called upon use of abort() in the source
|
894 |
|
|
code generally, thanks to a special macro. */
|
895 |
|
|
|
896 |
|
|
void
|
897 |
|
|
fancy_abort (const char *file, int line, const char *function)
|
898 |
|
|
{
|
899 |
|
|
internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
|
900 |
|
|
}
|
901 |
|
|
|
902 |
|
|
/* Really call the system 'abort'. This has to go right at the end of
|
903 |
|
|
this file, so that there are no functions after it that call abort
|
904 |
|
|
and get the system abort instead of our macro. */
|
905 |
|
|
#undef abort
|
906 |
|
|
static void
|
907 |
|
|
real_abort (void)
|
908 |
|
|
{
|
909 |
|
|
abort ();
|
910 |
|
|
}
|