GCC Middle and Back End API Reference
diagnostic.c File Reference

Functions

static char * build_message_string (const char *,...)
char * file_name_as_prefix ()
static int getenv_columns ()
void diagnostic_set_caret_max_width ()
void diagnostic_initialize ()
void diagnostic_finish ()
void diagnostic_set_info_translated (diagnostic_info *diagnostic, const char *msg, va_list *args, location_t location, diagnostic_t kind)
void diagnostic_set_info (diagnostic_info *diagnostic, const char *gmsgid, va_list *args, location_t location, diagnostic_t kind)
char * diagnostic_build_prefix (diagnostic_context *context, const diagnostic_info *diagnostic)
static const char * adjust_line ()
void diagnostic_show_locus (diagnostic_context *context, const diagnostic_info *diagnostic)
static int bt_callback (void *data, uintptr_t pc, const char *filename, int lineno, const char *function)
static void bt_err_callback ()
static void diagnostic_action_after_output (diagnostic_context *context, diagnostic_info *diagnostic)
void diagnostic_report_current_module ()
void default_diagnostic_starter (diagnostic_context *context, diagnostic_info *diagnostic)
void default_diagnostic_finalizer (diagnostic_context *context, diagnostic_info *diagnostic)
diagnostic_t diagnostic_classify_diagnostic (diagnostic_context *context, int option_index, diagnostic_t new_kind, location_t where)
void diagnostic_push_diagnostics ()
void diagnostic_pop_diagnostics ()
bool diagnostic_report_diagnostic (diagnostic_context *context, diagnostic_info *diagnostic)
const char * trim_filename ()
void verbatim ()
void diagnostic_append_note (diagnostic_context *context, location_t location, const char *gmsgid,...)
bool emit_diagnostic (diagnostic_t kind, location_t location, int opt, const char *gmsgid,...)
void inform ()
void inform_n (location_t location, int n, const char *singular_gmsgid, const char *plural_gmsgid,...)
bool warning ()
bool warning_at ()
bool pedwarn ()
bool permerror ()
void error ()
void error_n (location_t location, int n, const char *singular_gmsgid, const char *plural_gmsgid,...)
void error_at ()
void sorry ()
bool seen_error ()
void fatal_error ()
void internal_error ()
void fnotice ()
static void error_recursion ()
void fancy_abort ()
static void real_abort ()

Variables

static const char *const bt_stop []

Function Documentation

static const char* adjust_line ( )
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, expand_location_to_spelling_point(), diagnostic_context::last_location, diagnostic_info::location, location_get_source_line(), and diagnostic_context::show_caret.

static int bt_callback ( void *  data,
uintptr_t  pc,
const char *  filename,
int  lineno,
const char *  function 
)
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 free(), len, and strlen().

Referenced by diagnostic_action_after_output().

static void bt_err_callback ( )
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(), and fnotice().

Referenced by diagnostic_action_after_output().

static char* build_message_string ( const char *  ,
  ... 
)
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 
)
static void diagnostic_action_after_output ( 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(), 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().

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.  

References colorize_start(), colorize_stop(), and diagnostic_info::kind.

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.

void diagnostic_push_diagnostics ( )
   Save all diagnostic classifications in a stack.  

References diagnostic_info::kind, and diagnostic_info::location.

void diagnostic_report_current_module ( )
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.  
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,
  ... 
)
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 void error_recursion ( )
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 getenv().

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.  
static int getenv_columns ( )
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(), and diagnostic_info::option_index.

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(), and input_location.

static void real_abort ( )
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, and diagnostic_info::option_index.

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.  

Variable Documentation

const char* const bt_stop[]
static
Initial value:
{
"main",
"toplev_main",
"execute_one_pass",
"compile_file",
}
   Functions at which to stop the backtrace print.  It's not
   particularly helpful to print the callers of these functions.