OpenCores
URL https://opencores.org/ocsvn/openrisc_2011-10-31/openrisc_2011-10-31/trunk

Subversion Repositories openrisc_2011-10-31

[/] [openrisc/] [trunk/] [gnu-src/] [gcc-4.5.1/] [gcc/] [diagnostic.c] - Blame information for rev 621

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 280 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 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
#undef FLOAT /* This is for hpux. They should change hpux.  */
28
#undef FFS  /* Some systems define this in param.h.  */
29
#include "system.h"
30
#include "coretypes.h"
31
#include "tm.h"
32
#include "tree.h"
33
#include "version.h"
34
#include "tm_p.h"
35
#include "flags.h"
36
#include "input.h"
37
#include "toplev.h"
38
#include "intl.h"
39
#include "diagnostic.h"
40
#include "langhooks.h"
41
#include "langhooks-def.h"
42
#include "opts.h"
43
#include "plugin.h"
44
 
45
#define pedantic_warning_kind() (flag_pedantic_errors ? DK_ERROR : DK_WARNING)
46
#define permissive_error_kind() (flag_permissive ? DK_WARNING : DK_ERROR)
47
 
48
/* Prototypes.  */
49
static char *build_message_string (const char *, ...) ATTRIBUTE_PRINTF_1;
50
 
51
static void error_recursion (diagnostic_context *) ATTRIBUTE_NORETURN;
52
 
53
static void diagnostic_action_after_output (diagnostic_context *,
54
                                            diagnostic_info *);
55
static void real_abort (void) ATTRIBUTE_NORETURN;
56
 
57
/* A diagnostic_context surrogate for stderr.  */
58
static diagnostic_context global_diagnostic_context;
59
diagnostic_context *global_dc = &global_diagnostic_context;
60
 
61
 
62
/* Return a malloc'd string containing MSG formatted a la printf.  The
63
   caller is responsible for freeing the memory.  */
64
static char *
65
build_message_string (const char *msg, ...)
66
{
67
  char *str;
68
  va_list ap;
69
 
70
  va_start (ap, msg);
71
  vasprintf (&str, msg, ap);
72
  va_end (ap);
73
 
74
  return str;
75
}
76
 
77
/* Same as diagnostic_build_prefix, but only the source FILE is given.  */
78
char *
79
file_name_as_prefix (const char *f)
80
{
81
  return build_message_string ("%s: ", f);
82
}
83
 
84
 
85
 
86
/* Initialize the diagnostic message outputting machinery.  */
87
void
88
diagnostic_initialize (diagnostic_context *context)
89
{
90
  /* Allocate a basic pretty-printer.  Clients will replace this a
91
     much more elaborated pretty-printer if they wish.  */
92
  context->printer = XNEW (pretty_printer);
93
  pp_construct (context->printer, NULL, 0);
94
  /* By default, diagnostics are sent to stderr.  */
95
  context->printer->buffer->stream = stderr;
96
  /* By default, we emit prefixes once per message.  */
97
  context->printer->wrapping.rule = DIAGNOSTICS_SHOW_PREFIX_ONCE;
98
 
99
  memset (context->diagnostic_count, 0, sizeof context->diagnostic_count);
100
  context->issue_warnings_are_errors_message = true;
101
  context->warning_as_error_requested = false;
102
  memset (context->classify_diagnostic, DK_UNSPECIFIED,
103
          sizeof context->classify_diagnostic);
104
  context->show_option_requested = false;
105
  context->abort_on_error = false;
106
  context->internal_error = NULL;
107
  diagnostic_starter (context) = default_diagnostic_starter;
108
  diagnostic_finalizer (context) = default_diagnostic_finalizer;
109
  context->last_module = 0;
110
  context->last_function = NULL;
111
  context->lock = 0;
112
  context->inhibit_notes_p = false;
113
}
114
 
115
/* Initialize DIAGNOSTIC, where the message MSG has already been
116
   translated.  */
117
void
118
diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg,
119
                                va_list *args, location_t location,
120
                                diagnostic_t kind)
121
{
122
  diagnostic->message.err_no = errno;
123
  diagnostic->message.args_ptr = args;
124
  diagnostic->message.format_spec = msg;
125
  diagnostic->location = location;
126
  diagnostic->override_column = 0;
127
  diagnostic->kind = kind;
128
  diagnostic->option_index = 0;
129
}
130
 
131
/* Initialize DIAGNOSTIC, where the message GMSGID has not yet been
132
   translated.  */
133
void
134
diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid,
135
                     va_list *args, location_t location,
136
                     diagnostic_t kind)
137
{
138
  diagnostic_set_info_translated (diagnostic, _(gmsgid), args, location, kind);
139
}
140
 
141
/* Return a malloc'd string describing a location.  The caller is
142
   responsible for freeing the memory.  */
143
char *
144
diagnostic_build_prefix (diagnostic_info *diagnostic)
145
{
146
  static const char *const diagnostic_kind_text[] = {
147
#define DEFINE_DIAGNOSTIC_KIND(K, T) (T),
148
#include "diagnostic.def"
149
#undef DEFINE_DIAGNOSTIC_KIND
150
    "must-not-happen"
151
  };
152
  const char *text = _(diagnostic_kind_text[diagnostic->kind]);
153
  expanded_location s = expand_location (diagnostic->location);
154
  if (diagnostic->override_column)
155
    s.column = diagnostic->override_column;
156
  gcc_assert (diagnostic->kind < DK_LAST_DIAGNOSTIC_KIND);
157
 
158
  return
159
    (s.file == NULL
160
     ? build_message_string ("%s: %s", progname, text)
161
     : flag_show_column
162
     ? build_message_string ("%s:%d:%d: %s", s.file, s.line, s.column, text)
163
     : build_message_string ("%s:%d: %s", s.file, s.line, text));
164
}
165
 
166
/* Take any action which is expected to happen after the diagnostic
167
   is written out.  This function does not always return.  */
168
static void
169
diagnostic_action_after_output (diagnostic_context *context,
170
                                diagnostic_info *diagnostic)
171
{
172
  switch (diagnostic->kind)
173
    {
174
    case DK_DEBUG:
175
    case DK_NOTE:
176
    case DK_ANACHRONISM:
177
    case DK_WARNING:
178
      break;
179
 
180
    case DK_ERROR:
181
    case DK_SORRY:
182
      if (context->abort_on_error)
183
        real_abort ();
184
      if (flag_fatal_errors)
185
        {
186
          fnotice (stderr, "compilation terminated due to -Wfatal-errors.\n");
187
          exit (FATAL_EXIT_CODE);
188
        }
189
      break;
190
 
191
    case DK_ICE:
192
      if (context->abort_on_error)
193
        real_abort ();
194
 
195
      fnotice (stderr, "Please submit a full bug report,\n"
196
               "with preprocessed source if appropriate.\n"
197
               "See %s for instructions.\n", bug_report_url);
198
      exit (ICE_EXIT_CODE);
199
 
200
    case DK_FATAL:
201
      if (context->abort_on_error)
202
        real_abort ();
203
 
204
      fnotice (stderr, "compilation terminated.\n");
205
      exit (FATAL_EXIT_CODE);
206
 
207
    default:
208
      gcc_unreachable ();
209
    }
210
}
211
 
212
/* Prints out, if necessary, the name of the current function
213
   that caused an error.  Called from all error and warning functions.  */
214
void
215
diagnostic_report_current_function (diagnostic_context *context,
216
                                    diagnostic_info *diagnostic)
217
{
218
  diagnostic_report_current_module (context);
219
  lang_hooks.print_error_function (context, input_filename, diagnostic);
220
}
221
 
222
void
223
diagnostic_report_current_module (diagnostic_context *context)
224
{
225
  const struct line_map *map;
226
 
227
  if (pp_needs_newline (context->printer))
228
    {
229
      pp_newline (context->printer);
230
      pp_needs_newline (context->printer) = false;
231
    }
232
 
233
  if (input_location <= BUILTINS_LOCATION)
234
    return;
235
 
236
  map = linemap_lookup (line_table, input_location);
237
  if (map && diagnostic_last_module_changed (context, map))
238
    {
239
      diagnostic_set_last_module (context, map);
240
      if (! MAIN_FILE_P (map))
241
        {
242
          map = INCLUDED_FROM (line_table, map);
243
          if (flag_show_column)
244
            pp_verbatim (context->printer,
245
                         "In file included from %s:%d:%d",
246
                         map->to_file,
247
                         LAST_SOURCE_LINE (map), LAST_SOURCE_COLUMN (map));
248
          else
249
            pp_verbatim (context->printer,
250
                         "In file included from %s:%d",
251
                         map->to_file, LAST_SOURCE_LINE (map));
252
          while (! MAIN_FILE_P (map))
253
            {
254
              map = INCLUDED_FROM (line_table, map);
255
              pp_verbatim (context->printer,
256
                           ",\n                 from %s:%d",
257
                           map->to_file, LAST_SOURCE_LINE (map));
258
            }
259
          pp_verbatim (context->printer, ":");
260
          pp_newline (context->printer);
261
        }
262
    }
263
}
264
 
265
void
266
default_diagnostic_starter (diagnostic_context *context,
267
                            diagnostic_info *diagnostic)
268
{
269
  diagnostic_report_current_function (context, diagnostic);
270
  pp_set_prefix (context->printer, diagnostic_build_prefix (diagnostic));
271
}
272
 
273
void
274
default_diagnostic_finalizer (diagnostic_context *context,
275
                              diagnostic_info *diagnostic ATTRIBUTE_UNUSED)
276
{
277
  pp_destroy_prefix (context->printer);
278
}
279
 
280
/* Interface to specify diagnostic kind overrides.  Returns the
281
   previous setting, or DK_UNSPECIFIED if the parameters are out of
282
   range.  */
283
diagnostic_t
284
diagnostic_classify_diagnostic (diagnostic_context *context,
285
                                int option_index,
286
                                diagnostic_t new_kind)
287
{
288
  diagnostic_t old_kind;
289
 
290
  if (option_index <= 0
291
      || option_index >= N_OPTS
292
      || new_kind >= DK_LAST_DIAGNOSTIC_KIND)
293
    return DK_UNSPECIFIED;
294
 
295
  old_kind = context->classify_diagnostic[option_index];
296
  context->classify_diagnostic[option_index] = new_kind;
297
  return old_kind;
298
}
299
 
300
/* Report a diagnostic message (an error or a warning) as specified by
301
   DC.  This function is *the* subroutine in terms of which front-ends
302
   should implement their specific diagnostic handling modules.  The
303
   front-end independent format specifiers are exactly those described
304
   in the documentation of output_format.
305
   Return true if a diagnostic was printed, false otherwise.  */
306
 
307
bool
308
diagnostic_report_diagnostic (diagnostic_context *context,
309
                              diagnostic_info *diagnostic)
310
{
311
  location_t location = diagnostic->location;
312
  bool maybe_print_warnings_as_errors_message = false;
313
  const char *saved_format_spec;
314
 
315
  /* Give preference to being able to inhibit warnings, before they
316
     get reclassified to something else.  */
317
  if ((diagnostic->kind == DK_WARNING || diagnostic->kind == DK_PEDWARN)
318
      && !diagnostic_report_warnings_p (location))
319
    return false;
320
 
321
  if (diagnostic->kind == DK_PEDWARN)
322
    diagnostic->kind = pedantic_warning_kind ();
323
 
324
  if (diagnostic->kind == DK_NOTE && context->inhibit_notes_p)
325
    return false;
326
 
327
  if (context->lock > 0)
328
    {
329
      /* If we're reporting an ICE in the middle of some other error,
330
         try to flush out the previous error, then let this one
331
         through.  Don't do this more than once.  */
332
      if (diagnostic->kind == DK_ICE && context->lock == 1)
333
        pp_flush (context->printer);
334
      else
335
        error_recursion (context);
336
    }
337
 
338
  /* If the user requested that warnings be treated as errors, so be
339
     it.  Note that we do this before the next block so that
340
     individual warnings can be overridden back to warnings with
341
     -Wno-error=*.  */
342
  if (context->warning_as_error_requested
343
      && diagnostic->kind == DK_WARNING)
344
    {
345
      diagnostic->kind = DK_ERROR;
346
      maybe_print_warnings_as_errors_message = true;
347
    }
348
 
349
  if (diagnostic->option_index)
350
    {
351
      /* This tests if the user provided the appropriate -Wfoo or
352
         -Wno-foo option.  */
353
      if (! option_enabled (diagnostic->option_index))
354
        return false;
355
      /* This tests if the user provided the appropriate -Werror=foo
356
         option.  */
357
      if (context->classify_diagnostic[diagnostic->option_index] != DK_UNSPECIFIED)
358
        {
359
          diagnostic->kind = context->classify_diagnostic[diagnostic->option_index];
360
          maybe_print_warnings_as_errors_message = false;
361
        }
362
      /* This allows for future extensions, like temporarily disabling
363
         warnings for ranges of source code.  */
364
      if (diagnostic->kind == DK_IGNORED)
365
        return false;
366
    }
367
 
368
  /* If we changed the kind due to -Werror, and didn't override it, we
369
     need to print this message.  */
370
  if (context->issue_warnings_are_errors_message
371
      && maybe_print_warnings_as_errors_message)
372
    {
373
      pp_verbatim (context->printer,
374
                   "%s: warnings being treated as errors\n", progname);
375
      context->issue_warnings_are_errors_message = false;
376
    }
377
 
378
  context->lock++;
379
 
380
  if (diagnostic->kind == DK_ICE && plugins_active_p ())
381
    {
382
      fnotice (stderr, "*** WARNING *** there are active plugins, do not report"
383
               " this as a bug unless you can reproduce it without enabling"
384
               " any plugins.\n");
385
      dump_active_plugins (stderr);
386
    }
387
 
388
  if (diagnostic->kind == DK_ICE)
389
    {
390
#ifndef ENABLE_CHECKING
391
      /* When not checking, ICEs are converted to fatal errors when an
392
         error has already occurred.  This is counteracted by
393
         abort_on_error.  */
394
      if ((diagnostic_kind_count (context, DK_ERROR) > 0
395
           || diagnostic_kind_count (context, DK_SORRY) > 0)
396
          && !context->abort_on_error)
397
        {
398
          expanded_location s = expand_location (diagnostic->location);
399
          fnotice (stderr, "%s:%d: confused by earlier errors, bailing out\n",
400
                   s.file, s.line);
401
          exit (ICE_EXIT_CODE);
402
        }
403
#endif
404
      if (context->internal_error)
405
        (*context->internal_error) (diagnostic->message.format_spec,
406
                                    diagnostic->message.args_ptr);
407
    }
408
  ++diagnostic_kind_count (context, diagnostic->kind);
409
 
410
  saved_format_spec = diagnostic->message.format_spec;
411
  if (context->show_option_requested && diagnostic->option_index)
412
    diagnostic->message.format_spec
413
      = ACONCAT ((diagnostic->message.format_spec,
414
                  " [", cl_options[diagnostic->option_index].opt_text, "]", NULL));
415
 
416
  diagnostic->message.locus = &diagnostic->location;
417
  diagnostic->message.abstract_origin = &diagnostic->abstract_origin;
418
  diagnostic->abstract_origin = NULL;
419
  pp_format (context->printer, &diagnostic->message);
420
  (*diagnostic_starter (context)) (context, diagnostic);
421
  pp_output_formatted_text (context->printer);
422
  (*diagnostic_finalizer (context)) (context, diagnostic);
423
  pp_flush (context->printer);
424
  diagnostic_action_after_output (context, diagnostic);
425
  diagnostic->message.format_spec = saved_format_spec;
426
  diagnostic->abstract_origin = NULL;
427
 
428
  context->lock--;
429
 
430
  return true;
431
}
432
 
433
/* Given a partial pathname as input, return another pathname that
434
   shares no directory elements with the pathname of __FILE__.  This
435
   is used by fancy_abort() to print `Internal compiler error in expr.c'
436
   instead of `Internal compiler error in ../../GCC/gcc/expr.c'.  */
437
 
438
const char *
439
trim_filename (const char *name)
440
{
441
  static const char this_file[] = __FILE__;
442
  const char *p = name, *q = this_file;
443
 
444
  /* First skip any "../" in each filename.  This allows us to give a proper
445
     reference to a file in a subdirectory.  */
446
  while (p[0] == '.' && p[1] == '.' && IS_DIR_SEPARATOR (p[2]))
447
    p += 3;
448
 
449
  while (q[0] == '.' && q[1] == '.' && IS_DIR_SEPARATOR (q[2]))
450
    q += 3;
451
 
452
  /* Now skip any parts the two filenames have in common.  */
453
  while (*p == *q && *p != 0 && *q != 0)
454
    p++, q++;
455
 
456
  /* Now go backwards until the previous directory separator.  */
457
  while (p > name && !IS_DIR_SEPARATOR (p[-1]))
458
    p--;
459
 
460
  return p;
461
}
462
 
463
/* Standard error reporting routines in increasing order of severity.
464
   All of these take arguments like printf.  */
465
 
466
/* Text to be emitted verbatim to the error message stream; this
467
   produces no prefix and disables line-wrapping.  Use rarely.  */
468
void
469
verbatim (const char *gmsgid, ...)
470
{
471
  text_info text;
472
  va_list ap;
473
 
474
  va_start (ap, gmsgid);
475
  text.err_no = errno;
476
  text.args_ptr = &ap;
477
  text.format_spec = _(gmsgid);
478
  text.locus = NULL;
479
  text.abstract_origin = NULL;
480
  pp_format_verbatim (global_dc->printer, &text);
481
  pp_flush (global_dc->printer);
482
  va_end (ap);
483
}
484
 
485
bool
486
emit_diagnostic (diagnostic_t kind, location_t location, int opt,
487
                 const char *gmsgid, ...)
488
{
489
  diagnostic_info diagnostic;
490
  va_list ap;
491
 
492
  va_start (ap, gmsgid);
493
  if (kind == DK_PERMERROR)
494
    {
495
      diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
496
                           permissive_error_kind ());
497
      diagnostic.option_index = OPT_fpermissive;
498
    }
499
  else {
500
      diagnostic_set_info (&diagnostic, gmsgid, &ap, location, kind);
501
      if (kind == DK_WARNING || kind == DK_PEDWARN)
502
        diagnostic.option_index = opt;
503
  }
504
  va_end (ap);
505
 
506
  return report_diagnostic (&diagnostic);
507
}
508
 
509
/* An informative note at LOCATION.  Use this for additional details on an error
510
   message.  */
511
void
512
inform (location_t location, const char *gmsgid, ...)
513
{
514
  diagnostic_info diagnostic;
515
  va_list ap;
516
 
517
  va_start (ap, gmsgid);
518
  diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_NOTE);
519
  report_diagnostic (&diagnostic);
520
  va_end (ap);
521
}
522
 
523
/* An informative note at LOCATION.  Use this for additional details on an
524
   error message.  */
525
void
526
inform_n (location_t location, int n, const char *singular_gmsgid,
527
          const char *plural_gmsgid, ...)
528
{
529
  diagnostic_info diagnostic;
530
  va_list ap;
531
 
532
  va_start (ap, plural_gmsgid);
533
  diagnostic_set_info_translated (&diagnostic,
534
                                  ngettext (singular_gmsgid, plural_gmsgid, n),
535
                                  &ap, location, DK_NOTE);
536
  report_diagnostic (&diagnostic);
537
  va_end (ap);
538
}
539
 
540
/* A warning at INPUT_LOCATION.  Use this for code which is correct according
541
   to the relevant language specification but is likely to be buggy anyway.
542
   Returns true if the warning was printed, false if it was inhibited.  */
543
bool
544
warning (int opt, const char *gmsgid, ...)
545
{
546
  diagnostic_info diagnostic;
547
  va_list ap;
548
 
549
  va_start (ap, gmsgid);
550
  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_WARNING);
551
  diagnostic.option_index = opt;
552
 
553
  va_end (ap);
554
  return report_diagnostic (&diagnostic);
555
}
556
 
557
/* A warning at LOCATION.  Use this for code which is correct according to the
558
   relevant language specification but is likely to be buggy anyway.
559
   Returns true if the warning was printed, false if it was inhibited.  */
560
 
561
bool
562
warning_at (location_t location, int opt, const char *gmsgid, ...)
563
{
564
  diagnostic_info diagnostic;
565
  va_list ap;
566
 
567
  va_start (ap, gmsgid);
568
  diagnostic_set_info (&diagnostic, gmsgid, &ap, location, DK_WARNING);
569
  diagnostic.option_index = opt;
570
  va_end (ap);
571
  return report_diagnostic (&diagnostic);
572
}
573
 
574
/* A "pedantic" warning at LOCATION: issues a warning unless
575
   -pedantic-errors was given on the command line, in which case it
576
   issues an error.  Use this for diagnostics required by the relevant
577
   language standard, if you have chosen not to make them errors.
578
 
579
   Note that these diagnostics are issued independent of the setting
580
   of the -pedantic command-line switch.  To get a warning enabled
581
   only with that switch, use either "if (pedantic) pedwarn
582
   (OPT_pedantic,...)" or just "pedwarn (OPT_pedantic,..)".  To get a
583
   pedwarn independently of the -pedantic switch use "pedwarn (0,...)".
584
 
585
   Returns true if the warning was printed, false if it was inhibited.  */
586
 
587
bool
588
pedwarn (location_t location, int opt, const char *gmsgid, ...)
589
{
590
  diagnostic_info diagnostic;
591
  va_list ap;
592
 
593
  va_start (ap, gmsgid);
594
  diagnostic_set_info (&diagnostic, gmsgid, &ap, location,  DK_PEDWARN);
595
  diagnostic.option_index = opt;
596
  va_end (ap);
597
  return report_diagnostic (&diagnostic);
598
}
599
 
600
/* A "permissive" error at LOCATION: issues an error unless
601
   -fpermissive was given on the command line, in which case it issues
602
   a warning.  Use this for things that really should be errors but we
603
   want to support legacy code.
604
 
605
   Returns true if the warning was printed, false if it was inhibited.  */
606
 
607
bool
608
permerror (location_t location, const char *gmsgid, ...)
609
{
610
  diagnostic_info diagnostic;
611
  va_list ap;
612
 
613
  va_start (ap, gmsgid);
614
  diagnostic_set_info (&diagnostic, gmsgid, &ap, location,
615
                       permissive_error_kind ());
616
  diagnostic.option_index = OPT_fpermissive;
617
  va_end (ap);
618
  return report_diagnostic (&diagnostic);
619
}
620
 
621
/* A hard error: the code is definitely ill-formed, and an object file
622
   will not be produced.  */
623
void
624
error (const char *gmsgid, ...)
625
{
626
  diagnostic_info diagnostic;
627
  va_list ap;
628
 
629
  va_start (ap, gmsgid);
630
  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ERROR);
631
  report_diagnostic (&diagnostic);
632
  va_end (ap);
633
}
634
 
635
/* A hard error: the code is definitely ill-formed, and an object file
636
   will not be produced.  */
637
void
638
error_n (location_t location, int n, const char *singular_gmsgid,
639
         const char *plural_gmsgid, ...)
640
{
641
  diagnostic_info diagnostic;
642
  va_list ap;
643
 
644
  va_start (ap, plural_gmsgid);
645
  diagnostic_set_info_translated (&diagnostic,
646
                                  ngettext (singular_gmsgid, plural_gmsgid, n),
647
                                  &ap, location, DK_ERROR);
648
  report_diagnostic (&diagnostic);
649
  va_end (ap);
650
}
651
 
652
/* Same as ebove, but use location LOC instead of input_location.  */
653
void
654
error_at (location_t loc, const char *gmsgid, ...)
655
{
656
  diagnostic_info diagnostic;
657
  va_list ap;
658
 
659
  va_start (ap, gmsgid);
660
  diagnostic_set_info (&diagnostic, gmsgid, &ap, loc, DK_ERROR);
661
  report_diagnostic (&diagnostic);
662
  va_end (ap);
663
}
664
 
665
/* "Sorry, not implemented."  Use for a language feature which is
666
   required by the relevant specification but not implemented by GCC.
667
   An object file will not be produced.  */
668
void
669
sorry (const char *gmsgid, ...)
670
{
671
  diagnostic_info diagnostic;
672
  va_list ap;
673
 
674
  va_start (ap, gmsgid);
675
  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_SORRY);
676
  report_diagnostic (&diagnostic);
677
  va_end (ap);
678
}
679
 
680
/* An error which is severe enough that we make no attempt to
681
   continue.  Do not use this for internal consistency checks; that's
682
   internal_error.  Use of this function should be rare.  */
683
void
684
fatal_error (const char *gmsgid, ...)
685
{
686
  diagnostic_info diagnostic;
687
  va_list ap;
688
 
689
  va_start (ap, gmsgid);
690
  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_FATAL);
691
  report_diagnostic (&diagnostic);
692
  va_end (ap);
693
 
694
  gcc_unreachable ();
695
}
696
 
697
/* An internal consistency check has failed.  We make no attempt to
698
   continue.  Note that unless there is debugging value to be had from
699
   a more specific message, or some other good reason, you should use
700
   abort () instead of calling this function directly.  */
701
void
702
internal_error (const char *gmsgid, ...)
703
{
704
  diagnostic_info diagnostic;
705
  va_list ap;
706
 
707
  va_start (ap, gmsgid);
708
  diagnostic_set_info (&diagnostic, gmsgid, &ap, input_location, DK_ICE);
709
  report_diagnostic (&diagnostic);
710
  va_end (ap);
711
 
712
  gcc_unreachable ();
713
}
714
 
715
/* Special case error functions.  Most are implemented in terms of the
716
   above, or should be.  */
717
 
718
/* Print a diagnostic MSGID on FILE.  This is just fprintf, except it
719
   runs its second argument through gettext.  */
720
void
721
fnotice (FILE *file, const char *cmsgid, ...)
722
{
723
  va_list ap;
724
 
725
  va_start (ap, cmsgid);
726
  vfprintf (file, _(cmsgid), ap);
727
  va_end (ap);
728
}
729
 
730
/* Inform the user that an error occurred while trying to report some
731
   other error.  This indicates catastrophic internal inconsistencies,
732
   so give up now.  But do try to flush out the previous error.
733
   This mustn't use internal_error, that will cause infinite recursion.  */
734
 
735
static void
736
error_recursion (diagnostic_context *context)
737
{
738
  diagnostic_info diagnostic;
739
 
740
  if (context->lock < 3)
741
    pp_flush (context->printer);
742
 
743
  fnotice (stderr,
744
           "Internal compiler error: Error reporting routines re-entered.\n");
745
 
746
  /* Call diagnostic_action_after_output to get the "please submit a bug
747
     report" message.  It only looks at the kind field of diagnostic_info.  */
748
  diagnostic.kind = DK_ICE;
749
  diagnostic_action_after_output (context, &diagnostic);
750
 
751
  /* Do not use gcc_unreachable here; that goes through internal_error
752
     and therefore would cause infinite recursion.  */
753
  real_abort ();
754
}
755
 
756
/* Report an internal compiler error in a friendly manner.  This is
757
   the function that gets called upon use of abort() in the source
758
   code generally, thanks to a special macro.  */
759
 
760
void
761
fancy_abort (const char *file, int line, const char *function)
762
{
763
  internal_error ("in %s, at %s:%d", function, trim_filename (file), line);
764
}
765
 
766
/* Really call the system 'abort'.  This has to go right at the end of
767
   this file, so that there are no functions after it that call abort
768
   and get the system abort instead of our macro.  */
769
#undef abort
770
static void
771
real_abort (void)
772
{
773
  abort ();
774
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.