GCC Middle and Back End API Reference
|
#include "config.h"
#include "system.h"
#include "coretypes.h"
#include "version.h"
#include "demangle.h"
#include "input.h"
#include "intl.h"
#include "backtrace.h"
#include "diagnostic.h"
#include "diagnostic-color.h"
#include <new>
#include "diagnostic.def"
Macros | |
#define | pedantic_warning_kind(DC) ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING) |
#define | permissive_error_kind(DC) ((DC)->permissive ? DK_WARNING : DK_ERROR) |
#define | permissive_error_option(DC) ((DC)->opt_permissive) |
#define | DEFINE_DIAGNOSTIC_KIND(K, T, C) (T), |
#define | DEFINE_DIAGNOSTIC_KIND(K, T, C) (C), |
Variables | |
static const char *const | bt_stop [] |
#define DEFINE_DIAGNOSTIC_KIND | ( | K, | |
T, | |||
C | |||
) | (C), |
#define pedantic_warning_kind | ( | DC | ) | ((DC)->pedantic_errors ? DK_ERROR : DK_WARNING) |
Language-independent diagnostic subroutines for the GNU Compiler Collection Copyright (C) 1999-2013 Free Software Foundation, Inc. Contributed by Gabriel Dos Reis gdr@c odes ource ry.c om
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/. This file implements the language independent aspect of diagnostic message module.
Referenced by diagnostic_pop_diagnostics().
#define permissive_error_kind | ( | DC | ) | ((DC)->permissive ? DK_WARNING : DK_ERROR) |
Referenced by verbatim().
#define permissive_error_option | ( | DC | ) | ((DC)->opt_permissive) |
Referenced by verbatim().
|
static |
If LINE is longer than MAX_WIDTH, and COLUMN is not smaller than MAX_WIDTH by some margin, then adjust the start of the line such that the COLUMN is smaller than MAX_WIDTH minus the margin. The margin is either 10 characters or the difference between the column and the length of the line, whatever is smaller.
References buffer, BUILTINS_LOCATION, expand_location_to_spelling_point(), diagnostic_context::last_location, diagnostic_info::location, location_get_source_line(), NULL, and diagnostic_context::show_caret.
|
static |
A callback function passed to the backtrace_full function.
If we don't have any useful information, don't print anything.
Skip functions in diagnostic.c.
Print up to 20 functions. We could make this a –param, but since this is only for debugging just use a constant for now.
Returning a non-zero value stops the backtrace.
Returning a non-zero value stops the backtrace.
References NULL.
Referenced by diagnostic_action_after_output().
|
static |
A callback function passed to the backtrace_full function. This is called if backtrace_full has an error.
This means that no debug info was available. Just quietly skip printing backtrace info.
References diagnostic_finish(), FATAL_EXIT_CODE, and fnotice().
Referenced by diagnostic_action_after_output().
|
static |
Prototypes. Return a malloc'd string containing MSG formatted a la printf. The caller is responsible for freeing the memory.
void default_diagnostic_finalizer | ( | diagnostic_context * | context, |
diagnostic_info * | diagnostic | ||
) |
void default_diagnostic_starter | ( | diagnostic_context * | context, |
diagnostic_info * | diagnostic | ||
) |
|
static |
Take any action which is expected to happen after the diagnostic is written out. This function does not always return.
References diagnostic_context::abort_on_error, bt_callback(), bt_err_callback(), bug_report_url, count, fnotice(), ICE_EXIT_CODE, NULL, and real_abort().
void diagnostic_append_note | ( | diagnostic_context * | context, |
location_t | location, | ||
const char * | gmsgid, | ||
... | |||
) |
Add a note with text GMSGID and with LOCATION to the diagnostic CONTEXT.
References diagnostic_set_info(), and report_diagnostic.
char* diagnostic_build_prefix | ( | diagnostic_context * | context, |
const diagnostic_info * | diagnostic | ||
) |
Return a malloc'd string describing a location. The caller is responsible for freeing the memory.
Copyright (C) 2001-2013 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/.
DK_UNSPECIFIED must be first so it has a value of zero. We never assign this kind to an actual diagnostic, we only use this in variables that can hold a kind, to mean they have yet to have a kind specified. I.e. they're uninitialized. Within the diagnostic machinery, this kind also means "don't change the existing kind", meaning "no change is specified".
If a diagnostic is set to DK_IGNORED, it won't get reported at all. This is used by the diagnostic machinery when it wants to disable a diagnostic without disabling the option which causes it.
The remainder are real diagnostic types.
These two would be re-classified as DK_WARNING or DK_ERROR, so the prefix does not matter.
This one is just for counting DK_WARNING promoted to DK_ERROR due to -Werror and -Werror=warning.
Copyright (C) 2001-2013 Free Software Foundation, Inc.
This file is part of GCC.
GCC is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
GCC is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with GCC; see the file COPYING3. If not see http://www.gnu.org/licenses/.
DK_UNSPECIFIED must be first so it has a value of zero. We never assign this kind to an actual diagnostic, we only use this in variables that can hold a kind, to mean they have yet to have a kind specified. I.e. they're uninitialized. Within the diagnostic machinery, this kind also means "don't change the existing kind", meaning "no change is specified".
If a diagnostic is set to DK_IGNORED, it won't get reported at all. This is used by the diagnostic machinery when it wants to disable a diagnostic without disabling the option which causes it.
The remainder are real diagnostic types.
These two would be re-classified as DK_WARNING or DK_ERROR, so the prefix does not matter.
This one is just for counting DK_WARNING promoted to DK_ERROR due to -Werror and -Werror=warning.
References colorize_start(), colorize_stop(), diagnostic_info::kind, and pp_show_color.
Referenced by default_tree_diagnostic_starter(), and trim_filename().
diagnostic_t diagnostic_classify_diagnostic | ( | diagnostic_context * | context, |
int | option_index, | ||
diagnostic_t | new_kind, | ||
location_t | where | ||
) |
Interface to specify diagnostic kind overrides. Returns the previous setting, or DK_UNSPECIFIED if the parameters are out of range. If OPTION_INDEX is zero, the new setting is for all the diagnostics.
Handle pragmas separately, since we need to keep track of where the pragmas were.
void diagnostic_finish | ( | ) |
Do any cleaning up required after the last diagnostic is emitted.
Some of the errors may actually have been warnings.
-Werror was given.
At least one -Werror= was given.
Referenced by bt_err_callback().
void diagnostic_initialize | ( | ) |
Initialize the diagnostic message outputting machinery.
Allocate a basic pretty-printer. Clients will replace this a much more elaborated pretty-printer if they wish.
Referenced by main().
void diagnostic_pop_diagnostics | ( | ) |
Restore the topmost classification set off the stack. If the stack is empty, revert to the state based on command line parameters.
References diagnostic_info::kind, and pedantic_warning_kind.
void diagnostic_push_diagnostics | ( | ) |
Save all diagnostic classifications in a stack.
References diagnostic_info::kind, and diagnostic_info::location.
void diagnostic_report_current_module | ( | ) |
References line_table, pp_verbatim(), and diagnostic_context::printer.
Referenced by diagnostic_report_current_function().
bool diagnostic_report_diagnostic | ( | diagnostic_context * | context, |
diagnostic_info * | diagnostic | ||
) |
Report a diagnostic message (an error or a warning) as specified by DC. This function is the subroutine in terms of which front-ends should implement their specific diagnostic handling modules. The front-end independent format specifiers are exactly those described in the documentation of output_format. Return true if a diagnostic was printed, false otherwise.
Give preference to being able to inhibit warnings, before they get reclassified to something else.
We do this to avoid giving the message for -pedantic-errors.
If we're reporting an ICE in the middle of some other error, try to flush out the previous error, then let this one through. Don't do this more than once.
If the user requested that warnings be treated as errors, so be it. Note that we do this before the next block so that individual warnings can be overridden back to warnings with -Wno-error=*.
This tests if the user provided the appropriate -Wfoo or -Wno-foo option.
This tests for #pragma diagnostic changes.
FIXME: Stupid search. Optimize later.
The option 0 is for all the diagnostics.
This tests if the user provided the appropriate -Werror=foo option.
This allows for future extensions, like temporarily disabling warnings for ranges of source code.
When not checking, ICEs are converted to fatal errors when an error has already occurred. This is counteracted by abort_on_error.
References diagnostic_info::kind.
void diagnostic_set_caret_max_width | ( | ) |
Set caret_max_width to value.
One minus to account for the leading empty space.
void diagnostic_set_info | ( | diagnostic_info * | diagnostic, |
const char * | gmsgid, | ||
va_list * | args, | ||
location_t | location, | ||
diagnostic_t | kind | ||
) |
Initialize DIAGNOSTIC, where the message GMSGID has not yet been translated.
Referenced by diagnostic_append_note(), emit_diagnostic(), inform_n(), permerror(), trim_filename(), and verbatim().
void diagnostic_set_info_translated | ( | diagnostic_info * | diagnostic, |
const char * | msg, | ||
va_list * | args, | ||
location_t | location, | ||
diagnostic_t | kind | ||
) |
Initialize DIAGNOSTIC, where the message MSG has already been translated.
References _.
void diagnostic_show_locus | ( | diagnostic_context * | context, |
const diagnostic_info * | diagnostic | ||
) |
Print the physical source line corresponding to the location of this diagnostics, and a caret indicating the precise column.
pp_printf does not implement %*c.
Referenced by trim_filename().
bool emit_diagnostic | ( | diagnostic_t | kind, |
location_t | location, | ||
int | opt, | ||
const char * | gmsgid, | ||
... | |||
) |
References diagnostic_set_info(), input_location, diagnostic_info::option_index, and report_diagnostic.
void error | ( | ) |
A hard error: the code is definitely ill-formed, and an object file will not be produced.
void error_at | ( | ) |
Same as ebove, but use location LOC instead of input_location.
void error_n | ( | location_t | location, |
int | n, | ||
const char * | singular_gmsgid, | ||
const char * | plural_gmsgid, | ||
... | |||
) |
A hard error: the code is definitely ill-formed, and an object file will not be produced.
|
static |
Inform the user that an error occurred while trying to report some other error. This indicates catastrophic internal inconsistencies, so give up now. But do try to flush out the previous error. This mustn't use internal_error, that will cause infinite recursion.
Call diagnostic_action_after_output to get the "please submit a bug report" message. It only looks at the kind field of diagnostic_info.
Do not use gcc_unreachable here; that goes through internal_error and therefore would cause infinite recursion.
void fancy_abort | ( | ) |
Report an internal compiler error in a friendly manner. This is the function that gets called upon use of abort() in the source code generally, thanks to a special macro.
void fatal_error | ( | ) |
An error which is severe enough that we make no attempt to continue. Do not use this for internal consistency checks; that's internal_error. Use of this function should be rare.
char* file_name_as_prefix | ( | ) |
Same as diagnostic_build_prefix, but only the source FILE is given.
References NULL.
Referenced by lhd_initialize_diagnostics().
void fnotice | ( | ) |
Special case error functions. Most are implemented in terms of the above, or should be. Print a diagnostic MSGID on FILE. This is just fprintf, except it runs its second argument through gettext.
Referenced by bt_err_callback(), diagnostic_action_after_output(), load_specs(), and name_sort().
|
static |
Return the value of the getenv("COLUMNS") as an integer. If the value is not set to a positive integer, then return INT_MAX.
void inform | ( | ) |
An informative note at LOCATION. Use this for additional details on an error message.
void inform_n | ( | location_t | location, |
int | n, | ||
const char * | singular_gmsgid, | ||
const char * | plural_gmsgid, | ||
... | |||
) |
An informative note at LOCATION. Use this for additional details on an error message.
References diagnostic_set_info(), diagnostic_info::option_index, and report_diagnostic.
void internal_error | ( | ) |
An internal consistency check has failed. We make no attempt to continue. Note that unless there is debugging value to be had from a more specific message, or some other good reason, you should use abort () instead of calling this function directly.
References abort.
bool pedwarn | ( | ) |
A "pedantic" warning at LOCATION: issues a warning unless -pedantic-errors was given on the command line, in which case it issues an error. Use this for diagnostics required by the relevant language standard, if you have chosen not to make them errors.
Note that these diagnostics are issued independent of the setting of the -Wpedantic command-line switch. To get a warning enabled only with that switch, use either "if (pedantic) pedwarn (OPT_Wpedantic,...)" or just "pedwarn (OPT_Wpedantic,..)". To get a pedwarn independently of the -Wpedantic switch use "pedwarn (0,...)".
Returns true if the warning was printed, false if it was inhibited.
bool permerror | ( | ) |
A "permissive" error at LOCATION: issues an error unless -fpermissive was given on the command line, in which case it issues a warning. Use this for things that really should be errors but we want to support legacy code.
Returns true if the warning was printed, false if it was inhibited.
References diagnostic_set_info(), input_location, and report_diagnostic.
|
static |
Really call the system 'abort'. This has to go right at the end of this file, so that there are no functions after it that call abort and get the system abort instead of our macro.
Referenced by diagnostic_action_after_output().
bool seen_error | ( | void | ) |
Return true if an error or a "sorry" has been seen. Various processing is disabled after errors.
Referenced by canonicalize_component_ref(), gimplify_omp_workshare(), and lto_streamer_init().
void sorry | ( | ) |
"Sorry, not implemented." Use for a language feature which is required by the relevant specification but not implemented by GCC. An object file will not be produced.
const char* trim_filename | ( | ) |
Given a partial pathname as input, return another pathname that shares no directory elements with the pathname of FILE. This is used by fancy_abort() to print `Internal compiler error in expr.c' instead of `Internal compiler error in ../../GCC/gcc/expr.c'.
First skip any "../" in each filename. This allows us to give a proper reference to a file in a subdirectory.
Now skip any parts the two filenames have in common.
Now go backwards until the previous directory separator.
References diagnostic_build_prefix(), diagnostic_set_info(), diagnostic_show_locus(), diagnostic_context::inhibit_notes_p, diagnostic_info::message, pp_destroy_prefix(), pp_format(), pp_get_prefix(), pp_newline(), pp_output_formatted_text(), pp_set_prefix(), and diagnostic_context::printer.
void verbatim | ( | ) |
Standard error reporting routines in increasing order of severity. All of these take arguments like printf. Text to be emitted verbatim to the error message stream; this produces no prefix and disables line-wrapping. Use rarely.
References diagnostic_set_info(), global_dc, diagnostic_info::option_index, permissive_error_kind, and permissive_error_option.
bool warning | ( | ) |
A warning at INPUT_LOCATION. Use this for code which is correct according to the relevant language specification but is likely to be buggy anyway. Returns true if the warning was printed, false if it was inhibited.
bool warning_at | ( | ) |
A warning at LOCATION. Use this for code which is correct according to the relevant language specification but is likely to be buggy anyway. Returns true if the warning was printed, false if it was inhibited.
|
static |
Functions at which to stop the backtrace print. It's not particularly helpful to print the callers of these functions.