comparison gcc/diagnostic.c @ 63:b7f97abdc517 gcc-4.6-20100522

update gcc from gcc-4.5.0 to gcc-4.6
author ryoma <e075725@ie.u-ryukyu.ac.jp>
date Mon, 24 May 2010 12:47:05 +0900
parents 77e2b8dfacca
children f6334be47118
comparison
equal deleted inserted replaced
56:3c8a44c06a95 63:b7f97abdc517
1 /* Language-independent diagnostic subroutines for the GNU Compiler Collection 1 /* Language-independent diagnostic subroutines for the GNU Compiler Collection
2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2 Copyright (C) 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008,
3 2009 Free Software Foundation, Inc. 3 2009, 2010 Free Software Foundation, Inc.
4 Contributed by Gabriel Dos Reis <gdr@codesourcery.com> 4 Contributed by Gabriel Dos Reis <gdr@codesourcery.com>
5 5
6 This file is part of GCC. 6 This file is part of GCC.
7 7
8 GCC is free software; you can redistribute it and/or modify it under 8 GCC is free software; you can redistribute it and/or modify it under
22 22
23 /* This file implements the language independent aspect of diagnostic 23 /* This file implements the language independent aspect of diagnostic
24 message module. */ 24 message module. */
25 25
26 #include "config.h" 26 #include "config.h"
27 #undef FLOAT /* This is for hpux. They should change hpux. */
28 #undef FFS /* Some systems define this in param.h. */
29 #include "system.h" 27 #include "system.h"
30 #include "coretypes.h" 28 #include "coretypes.h"
31 #include "tm.h"
32 #include "tree.h"
33 #include "version.h" 29 #include "version.h"
34 #include "tm_p.h"
35 #include "flags.h" 30 #include "flags.h"
36 #include "input.h" 31 #include "input.h"
37 #include "toplev.h" 32 #include "toplev.h"
38 #include "intl.h" 33 #include "intl.h"
39 #include "diagnostic.h" 34 #include "diagnostic.h"
40 #include "langhooks.h"
41 #include "langhooks-def.h"
42 #include "opts.h" 35 #include "opts.h"
43 #include "plugin.h" 36 #include "plugin.h"
44 37
45 #define pedantic_warning_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING) 38 #define pedantic_warning_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
46 #define permissive_error_kind() (flag_permissive ? DK_WARNING : DK_ERROR) 39 #define permissive_error_kind() (flag_permissive ? DK_WARNING : DK_ERROR)
95 context->printer->buffer->stream = stderr; 88 context->printer->buffer->stream = stderr;
96 /* By default, we emit prefixes once per message. */ 89 /* By default, we emit prefixes once per message. */
97 context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE; 90 context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
98 91
99 memset (context->diagnostic_count, 0, sizeof context->diagnostic_count); 92 memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
100 context->issue_warnings_are_errors_message = true; 93 context->some_warnings_are_errors = false;
101 context->warning_as_error_requested = false; 94 context->warning_as_error_requested = false;
102 memset (context->classify_diagnostic, DK_UNSPECIFIED, 95 memset (context->classify_diagnostic, DK_UNSPECIFIED,
103 sizeof context->classify_diagnostic); 96 sizeof context->classify_diagnostic);
104 context->show_option_requested = false; 97 context->show_option_requested = false;
105 context->abort_on_error = false; 98 context->abort_on_error = false;
106 context->internal_error = NULL; 99 context->internal_error = NULL;
107 diagnostic_starter (context) = default_diagnostic_starter; 100 diagnostic_starter (context) = default_diagnostic_starter;
108 diagnostic_finalizer (context) = default_diagnostic_finalizer; 101 diagnostic_finalizer (context) = default_diagnostic_finalizer;
109 context->last_module = 0; 102 context->last_module = 0;
110 context->last_function = NULL; 103 context->x_data = NULL;
111 context->lock = 0; 104 context->lock = 0;
105 context->inhibit_notes_p = false;
106 }
107
108 /* Do any cleaning up required after the last diagnostic is emitted. */
109
110 void
111 diagnostic_finish (diagnostic_context *context)
112 {
113 /* Some of the errors may actually have been warnings. */
114 if (context->some_warnings_are_errors)
115 {
116 /* -Werror was given. */
117 if (context->warning_as_error_requested)
118 pp_verbatim (context->printer,
119 _("%s: all warnings being treated as errors\n"),
120 progname);
121 /* At least one -Werror= was given. */
122 else
123 pp_verbatim (context->printer,
124 _("%s: some warnings being treated as errors\n"),
125 progname);
126 pp_flush (context->printer);
127 }
112 } 128 }
113 129
114 /* Initialize DIAGNOSTIC, where the message MSG has already been 130 /* Initialize DIAGNOSTIC, where the message MSG has already been
115 translated. */ 131 translated. */
116 void 132 void
181 if (context->abort_on_error) 197 if (context->abort_on_error)
182 real_abort (); 198 real_abort ();
183 if (flag_fatal_errors) 199 if (flag_fatal_errors)
184 { 200 {
185 fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n"); 201 fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
202 diagnostic_finish (context);
186 exit (FATAL_EXIT_CODE); 203 exit (FATAL_EXIT_CODE);
187 } 204 }
188 break; 205 break;
189 206
190 case DK_ICE: 207 case DK_ICE:
197 exit (ICE_EXIT_CODE); 214 exit (ICE_EXIT_CODE);
198 215
199 case DK_FATAL: 216 case DK_FATAL:
200 if (context->abort_on_error) 217 if (context->abort_on_error)
201 real_abort (); 218 real_abort ();
202 219 diagnostic_finish (context);
203 fnotice (stderr, "compilation terminated.\n"); 220 fnotice (stderr, "compilation terminated.\n");
204 exit (FATAL_EXIT_CODE); 221 exit (FATAL_EXIT_CODE);
205 222
206 default: 223 default:
207 gcc_unreachable (); 224 gcc_unreachable ();
208 } 225 }
209 }
210
211 /* Prints out, if necessary, the name of the current function
212 that caused an error. Called from all error and warning functions. */
213 void
214 diagnostic_report_current_function (diagnostic_context *context,
215 diagnostic_info *diagnostic)
216 {
217 diagnostic_report_current_module (context);
218 lang_hooks.print_error_function (context, input_filename, diagnostic);
219 } 226 }
220 227
221 void 228 void
222 diagnostic_report_current_module (diagnostic_context *context) 229 diagnostic_report_current_module (diagnostic_context *context)
223 { 230 {
263 270
264 void 271 void
265 default_diagnostic_starter (diagnostic_context *context, 272 default_diagnostic_starter (diagnostic_context *context,
266 diagnostic_info *diagnostic) 273 diagnostic_info *diagnostic)
267 { 274 {
268 diagnostic_report_current_function (context, diagnostic); 275 diagnostic_report_current_module (context);
269 pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic)); 276 pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
270 } 277 }
271 278
272 void 279 void
273 default_diagnostic_finalizer (diagnostic_context *context, 280 default_diagnostic_finalizer (diagnostic_context *context,
306 bool 313 bool
307 diagnostic_report_diagnostic (diagnostic_context *context, 314 diagnostic_report_diagnostic (diagnostic_context *context,
308 diagnostic_info *diagnostic) 315 diagnostic_info *diagnostic)
309 { 316 {
310 location_t location = diagnostic->location; 317 location_t location = diagnostic->location;
311 bool maybe_print_warnings_as_errors_message = false; 318 diagnostic_t orig_diag_kind = diagnostic->kind;
312 const char *saved_format_spec; 319 const char *saved_format_spec;
313 320
314 /* Give preference to being able to inhibit warnings, before they 321 /* Give preference to being able to inhibit warnings, before they
315 get reclassified to something else. */ 322 get reclassified to something else. */
316 if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN) 323 if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN)
317 && !diagnostic_report_warnings_p (location)) 324 && !diagnostic_report_warnings_p (location))
318 return false; 325 return false;
319 326
320 if (diagnostic->kind == DK_NOTE && flag_compare_debug) 327 if (diagnostic->kind == DK_PEDWARN)
328 {
329 diagnostic->kind = pedantic_warning_kind ();
330 /* We do this to avoid giving the message for -pedantic-errors. */
331 orig_diag_kind = diagnostic->kind;
332 }
333
334 if (diagnostic->kind == DK_NOTE && context->inhibit_notes_p)
321 return false; 335 return false;
322
323 if (diagnostic->kind == DK_PEDWARN)
324 diagnostic->kind = pedantic_warning_kind ();
325 336
326 if (context->lock > 0) 337 if (context->lock > 0)
327 { 338 {
328 /* If we're reporting an ICE in the middle of some other error, 339 /* If we're reporting an ICE in the middle of some other error,
329 try to flush out the previous error, then let this one 340 try to flush out the previous error, then let this one
340 -Wno-error=*. */ 351 -Wno-error=*. */
341 if (context->warning_as_error_requested 352 if (context->warning_as_error_requested
342 && diagnostic->kind == DK_WARNING) 353 && diagnostic->kind == DK_WARNING)
343 { 354 {
344 diagnostic->kind = DK_ERROR; 355 diagnostic->kind = DK_ERROR;
345 maybe_print_warnings_as_errors_message = true;
346 } 356 }
347 357
348 if (diagnostic->option_index) 358 if (diagnostic->option_index)
349 { 359 {
350 /* This tests if the user provided the appropriate -Wfoo or 360 /* This tests if the user provided the appropriate -Wfoo or
354 /* This tests if the user provided the appropriate -Werror=foo 364 /* This tests if the user provided the appropriate -Werror=foo
355 option. */ 365 option. */
356 if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED) 366 if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
357 { 367 {
358 diagnostic->kind = context->classify_diagnostic[diagnostic->option_index]; 368 diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
359 maybe_print_warnings_as_errors_message = false;
360 } 369 }
361 /* This allows for future extensions, like temporarily disabling 370 /* This allows for future extensions, like temporarily disabling
362 warnings for ranges of source code. */ 371 warnings for ranges of source code. */
363 if (diagnostic->kind == DK_IGNORED) 372 if (diagnostic->kind == DK_IGNORED)
364 return false; 373 return false;
365 } 374 }
366 375
367 /* If we changed the kind due to -Werror, and didn't override it, we 376 if (orig_diag_kind == DK_WARNING && diagnostic->kind == DK_ERROR)
368 need to print this message. */ 377 context->some_warnings_are_errors = true;
369 if (context->issue_warnings_are_errors_message
370 && maybe_print_warnings_as_errors_message)
371 {
372 pp_verbatim (context->printer,
373 "%s: warnings being treated as errors\n", progname);
374 context->issue_warnings_are_errors_message = false;
375 }
376 378
377 context->lock++; 379 context->lock++;
378 380
379 if (diagnostic->kind == DK_ICE && plugins_active_p ()) 381 if (diagnostic->kind == DK_ICE && plugins_active_p ())
380 { 382 {
405 diagnostic->message.args_ptr); 407 diagnostic->message.args_ptr);
406 } 408 }
407 ++diagnostic_kind_count (context, diagnostic->kind); 409 ++diagnostic_kind_count (context, diagnostic->kind);
408 410
409 saved_format_spec = diagnostic->message.format_spec; 411 saved_format_spec = diagnostic->message.format_spec;
410 if (context->show_option_requested && diagnostic->option_index) 412 if (context->show_option_requested)
411 diagnostic->message.format_spec 413 {
412 = ACONCAT ((diagnostic->message.format_spec, 414 const char * option_text = NULL;
413 " [", cl_options[diagnostic->option_index].opt_text, "]", NULL)); 415
414 416 if (diagnostic->option_index)
417 {
418 /* A warning classified as an error. */
419 if ((orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN)
420 && diagnostic->kind == DK_ERROR)
421 option_text
422 = ACONCAT ((cl_options[OPT_Werror_].opt_text,
423 /* Skip over "-W". */
424 cl_options[diagnostic->option_index].opt_text + 2,
425 NULL));
426 /* A warning with option. */
427 else
428 option_text = cl_options[diagnostic->option_index].opt_text;
429 }
430 /* A warning without option classified as an error. */
431 else if (orig_diag_kind == DK_WARNING || orig_diag_kind == DK_PEDWARN
432 || diagnostic->kind == DK_WARNING)
433 {
434 if (context->warning_as_error_requested)
435 option_text = cl_options[OPT_Werror].opt_text;
436 else
437 option_text = _("enabled by default");
438 }
439
440 if (option_text)
441 diagnostic->message.format_spec
442 = ACONCAT ((diagnostic->message.format_spec,
443 " ",
444 "[", option_text, "]",
445 NULL));
446 }
415 diagnostic->message.locus = &diagnostic->location; 447 diagnostic->message.locus = &diagnostic->location;
416 diagnostic->message.abstract_origin = &diagnostic->abstract_origin; 448 diagnostic->message.x_data = &diagnostic->x_data;
417 diagnostic->abstract_origin = NULL; 449 diagnostic->x_data = NULL;
418 pp_format (context->printer, &diagnostic->message); 450 pp_format (context->printer, &diagnostic->message);
419 (*diagnostic_starter (context)) (context, diagnostic); 451 (*diagnostic_starter (context)) (context, diagnostic);
420 pp_output_formatted_text (context->printer); 452 pp_output_formatted_text (context->printer);
421 (*diagnostic_finalizer (context)) (context, diagnostic); 453 (*diagnostic_finalizer (context)) (context, diagnostic);
422 pp_flush (context->printer); 454 pp_flush (context->printer);
423 diagnostic_action_after_output (context, diagnostic); 455 diagnostic_action_after_output (context, diagnostic);
424 diagnostic->message.format_spec = saved_format_spec; 456 diagnostic->message.format_spec = saved_format_spec;
425 diagnostic->abstract_origin = NULL; 457 diagnostic->x_data = NULL;
426 458
427 context->lock--; 459 context->lock--;
428 460
429 return true; 461 return true;
430 } 462 }
473 va_start (ap, gmsgid); 505 va_start (ap, gmsgid);
474 text.err_no = errno; 506 text.err_no = errno;
475 text.args_ptr = &ap; 507 text.args_ptr = &ap;
476 text.format_spec = _(gmsgid); 508 text.format_spec = _(gmsgid);
477 text.locus = NULL; 509 text.locus = NULL;
478 text.abstract_origin = NULL; 510 text.x_data = NULL;
479 pp_format_verbatim (global_dc->printer, &text); 511 pp_format_verbatim (global_dc->printer, &text);
480 pp_flush (global_dc->printer); 512 pp_flush (global_dc->printer);
481 va_end (ap); 513 va_end (ap);
482 } 514 }
483 515
517 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE); 549 diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE);
518 report_diagnostic (&diagnostic); 550 report_diagnostic (&diagnostic);
519 va_end (ap); 551 va_end (ap);
520 } 552 }
521 553
554 /* An informative note at LOCATION. Use this for additional details on an
555 error message. */
556 void
557 inform_n (location_t location, int n, const char *singular_gmsgid,
558 const char *plural_gmsgid, ...)
559 {
560 diagnostic_info diagnostic;
561 va_list ap;
562
563 va_start (ap, plural_gmsgid);
564 diagnostic_set_info_translated (&diagnostic,
565 ngettext (singular_gmsgid, plural_gmsgid, n),
566 &ap, location, DK_NOTE);
567 report_diagnostic (&diagnostic);
568 va_end (ap);
569 }
570
522 /* A warning at INPUT_LOCATION. Use this for code which is correct according 571 /* A warning at INPUT_LOCATION. Use this for code which is correct according
523 to the relevant language specification but is likely to be buggy anyway. 572 to the relevant language specification but is likely to be buggy anyway.
524 Returns true if the warning was printed, false if it was inhibited. */ 573 Returns true if the warning was printed, false if it was inhibited. */
525 bool 574 bool
526 warning (int opt, const char *gmsgid, ...) 575 warning (int opt, const char *gmsgid, ...)
608 diagnostic_info diagnostic; 657 diagnostic_info diagnostic;
609 va_list ap; 658 va_list ap;
610 659
611 va_start (ap, gmsgid); 660 va_start (ap, gmsgid);
612 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR); 661 diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR);
662 report_diagnostic (&diagnostic);
663 va_end (ap);
664 }
665
666 /* A hard error: the code is definitely ill-formed, and an object file
667 will not be produced. */
668 void
669 error_n (location_t location, int n, const char *singular_gmsgid,
670 const char *plural_gmsgid, ...)
671 {
672 diagnostic_info diagnostic;
673 va_list ap;
674
675 va_start (ap, plural_gmsgid);
676 diagnostic_set_info_translated (&diagnostic,
677 ngettext (singular_gmsgid, plural_gmsgid, n),
678 &ap, location, DK_ERROR);
613 report_diagnostic (&diagnostic); 679 report_diagnostic (&diagnostic);
614 va_end (ap); 680 va_end (ap);
615 } 681 }
616 682
617 /* Same as ebove, but use location LOC instead of input_location. */ 683 /* Same as ebove, but use location LOC instead of input_location. */