GCC Middle and Back End API Reference
diagnostic.h File Reference
#include "rich-location.h"
#include "pretty-print.h"
#include "diagnostic-core.h"
#include "diagnostics/diagnostic-info.h"
#include "diagnostics/context.h"
Include dependency graph for diagnostic.h:

Go to the source code of this file.

Namespaces

namespace  diagnostics

Macros

#define diagnostic_context_auxiliary_data(DC)
#define diagnostic_info_auxiliary_data(DI)
#define errorcount   global_dc->diagnostic_count (diagnostics::kind::error)
#define warningcount   global_dc->diagnostic_count (diagnostics::kind::warning)
#define werrorcount   global_dc->diagnostic_count (diagnostics::kind::werror)
#define sorrycount   global_dc->diagnostic_count (diagnostics::kind::sorry)
#define diagnostic_report_warnings_p(DC, LOC)

Functions

void diagnostic_set_option_id (diagnostics::diagnostic_info *info, diagnostics::option_id opt_id)
void diagnostic_initialize (diagnostics::context *context, int n_opts)
void diagnostic_color_init (diagnostics::context *context, int value=-1)
void diagnostic_urls_init (diagnostics::context *context, int value=-1)
void diagnostic_finish (diagnostics::context *context)
void diagnostic_show_locus (diagnostics::context *context, const diagnostics::source_printing_options &opts, rich_location *richloc, enum diagnostics::kind diagnostic_kind, pretty_printer *pp, diagnostics::source_effect_info *effect_info=nullptr)
void diagnostic_show_locus_as_html (diagnostics::context *context, const diagnostics::source_printing_options &opts, rich_location *richloc, enum diagnostics::kind diagnostic_kind, xml::printer &xp, diagnostics::source_effect_info *effect_info=nullptr, diagnostics::html_label_writer *label_writer=nullptr)
void diagnostic_initialize_input_context (diagnostics::context *context, diagnostic_input_charset_callback ccb, bool should_skip_bom)
diagnostics::kind diagnostic_classify_diagnostic (diagnostics::context *context, diagnostics::option_id opt_id, enum diagnostics::kind kind, location_t where)
void diagnostic_push_diagnostics (diagnostics::context *context, location_t where)
void diagnostic_pop_diagnostics (diagnostics::context *context, location_t where)
bool diagnostic_report_diagnostic (diagnostics::context *context, diagnostics::diagnostic_info *diagnostic)
void diagnostic_set_info (diagnostics::diagnostic_info *, const char *, va_list *, rich_location *, enum diagnostics::kind) ATTRIBUTE_GCC_DIAG(2
void void diagnostic_set_info_translated (diagnostics::diagnostic_info *, const char *, va_list *, rich_location *, enum diagnostics::kind) ATTRIBUTE_GCC_DIAG(2
void diagnostics::default_text_starter (diagnostics::text_sink &, const diagnostics::diagnostic_info *)
template<typename TextOrHtml>
void diagnostics::default_start_span_fn (const diagnostics::location_print_policy &, TextOrHtml &text_or_html, expanded_location)
void diagnostics::default_text_finalizer (diagnostics::text_sink &, const diagnostics::diagnostic_info *, enum diagnostics::kind)
int get_terminal_width (void)
location_t diagnostic_location (const diagnostics::diagnostic_info *diagnostic, int which=0)
unsigned int diagnostic_num_locations (const diagnostics::diagnostic_info *diagnostic)
expanded_location diagnostic_expand_location (const diagnostics::diagnostic_info *diagnostic, int which=0)
bool diagnostic_same_line (const diagnostics::context *context, expanded_location s1, expanded_location s2)
char * build_message_string (const char *,...) ATTRIBUTE_PRINTF_1
bool warning_enabled_at (location_t loc, diagnostics::option_id opt_id)
bool option_unspecified_p (diagnostics::option_id opt_id)
int diagnostics::num_digits (int)

Variables

diagnostics::contextglobal_dc
const int CARET_LINE_MARGIN = 10

Macro Definition Documentation

◆ diagnostic_context_auxiliary_data

#define diagnostic_context_auxiliary_data ( DC)
Value:
(DC)->m_client_aux_data
Various declarations for language-independent diagnostics subroutines.
   Copyright (C) 2000-2025 Free Software Foundation, Inc.
   Contributed by Gabriel Dos Reis <gdr@codesourcery.com>

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/>.   
Extension hooks for client.   

◆ diagnostic_info_auxiliary_data

#define diagnostic_info_auxiliary_data ( DI)
Value:
(DI)->m_x_data

◆ diagnostic_report_warnings_p

#define diagnostic_report_warnings_p ( DC,
LOC )
Value:
(!(DC)->m_inhibit_warnings \
&& !(in_system_header_at (LOC) && !(DC)->m_warn_system_headers))
int in_system_header_at(location_t loc)
Definition input.h:115
Returns nonzero if warnings should be emitted.   

Referenced by diagnostics::context::warning_enabled_at().

◆ errorcount

#define errorcount   global_dc->diagnostic_count (diagnostics::kind::error)
The number of errors that have been issued so far.  Ideally, these
would take a diagnostics::context as an argument.   

Referenced by _fatal_insn(), driver::do_spec_on_infiles(), gimplify_bind_expr(), toplev::main(), driver::maybe_run_linker(), and seen_error().

◆ sorrycount

#define sorrycount   global_dc->diagnostic_count (diagnostics::kind::sorry)
Similarly, but for sorrys.   

Referenced by seen_error().

◆ warningcount

#define warningcount   global_dc->diagnostic_count (diagnostics::kind::warning)
Similarly, but for warnings.   

Referenced by toplev::main().

◆ werrorcount

#define werrorcount   global_dc->diagnostic_count (diagnostics::kind::werror)
Similarly, but for warnings promoted to errors.   

Referenced by toplev::main().

Function Documentation

◆ build_message_string()

char * build_message_string ( const char * msg,
... )
extern
Pure text formatting support functions.   
Return a malloc'd string containing MSG formatted a la printf.  The
caller is responsible for freeing the memory.   

References ap, and msg.

Referenced by diagnostics::text_sink::build_prefix(), diagnostics::text_sink::file_name_as_prefix(), and diagnostics::column_policy::get_location_text().

◆ diagnostic_classify_diagnostic()

diagnostics::kind diagnostic_classify_diagnostic ( diagnostics::context * context,
diagnostics::option_id opt_id,
enum diagnostics::kind kind,
location_t where )
inline
Force diagnostics controlled by OPTIDX to be kind KIND.   

References diagnostics::context::classify_diagnostic().

Referenced by control_warning_option(), process_options(), and set_option().

◆ diagnostic_color_init()

◆ diagnostic_expand_location()

expanded_location diagnostic_expand_location ( const diagnostics::diagnostic_info * diagnostic,
int which = 0 )
inline
Expand the location of this diagnostic. Use this function for
consistency.  Parameter WHICH specifies which location. By default,
expand the first one.   

Referenced by diagnostics::text_sink::build_prefix(), diagnostics::html_builder::make_element_for_diagnostic(), and diagnostics::text_sink::on_report_diagnostic().

◆ diagnostic_finish()

◆ diagnostic_initialize()

◆ diagnostic_initialize_input_context()

void diagnostic_initialize_input_context ( diagnostics::context * context,
diagnostic_input_charset_callback ccb,
bool should_skip_bom )
inline
Because we read source files a second time after the frontend did it the
first time, we need to know how the frontend handled things like character
set conversion and UTF-8 BOM stripping, in order to make everything
consistent.  This function needs to be called by each frontend that requires
non-default behavior, to inform the diagnostics infrastructure how input is
to be processed.  The default behavior is to do no conversion and not to
strip a UTF-8 BOM.

The callback should return the input charset to be used to convert the given
file's contents to UTF-8, or it should return NULL if no conversion is needed
for this file.  SHOULD_SKIP_BOM only applies in case no conversion was
performed, and if true, it will cause a UTF-8 BOM to be skipped at the
beginning of the file.  (In case a conversion was performed, the BOM is
rather skipped as part of the conversion process.)   

References diagnostics::context::initialize_input_context().

◆ diagnostic_location()

location_t diagnostic_location ( const diagnostics::diagnostic_info * diagnostic,
int which = 0 )
inline

◆ diagnostic_num_locations()

unsigned int diagnostic_num_locations ( const diagnostics::diagnostic_info * diagnostic)
inline
Return the number of locations to be printed in DIAGNOSTIC.   

◆ diagnostic_pop_diagnostics()

void diagnostic_pop_diagnostics ( diagnostics::context * context,
location_t where )
inline

◆ diagnostic_push_diagnostics()

void diagnostic_push_diagnostics ( diagnostics::context * context,
location_t where )
inline

◆ diagnostic_report_diagnostic()

bool diagnostic_report_diagnostic ( diagnostics::context * context,
diagnostics::diagnostic_info * diagnostic )
inline
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.   

References diagnostics::context::begin_group(), diagnostics::context::end_group(), and diagnostics::context::report_diagnostic().

Referenced by diagnostic_for_asm(), diagnostic_manager::emit_va(), and format_string_diagnostic_t::emit_warning_n_va().

◆ diagnostic_same_line()

bool diagnostic_same_line ( const diagnostics::context * context,
expanded_location s1,
expanded_location s2 )
inline
Return true if the two locations can be represented within the same
caret line.  This is used to build a prefix and also to determine
whether to print one or two caret lines.   

References CARET_LINE_MARGIN, diagnostics::context::get_source_printing_options(), and diagnostics::source_printing_options::max_width.

◆ diagnostic_set_info()

◆ diagnostic_set_info_translated()

void void diagnostic_set_info_translated ( diagnostics::diagnostic_info * ,
const char * ,
va_list * ,
rich_location * ,
enum diagnostics::kind  )
extern

◆ diagnostic_set_option_id()

void diagnostic_set_option_id ( diagnostics::diagnostic_info * info,
diagnostics::option_id opt_id )
inline
Override the option index to be used for reporting a
diagnostic.   

References diagnostics::diagnostic_info::m_option_id.

◆ diagnostic_show_locus()

void diagnostic_show_locus ( diagnostics::context * context,
const diagnostics::source_printing_options & opts,
rich_location * richloc,
enum diagnostics::kind diagnostic_kind,
pretty_printer * pp,
diagnostics::source_effect_info * effect_info = nullptr )
inline

◆ diagnostic_show_locus_as_html()

void diagnostic_show_locus_as_html ( diagnostics::context * context,
const diagnostics::source_printing_options & opts,
rich_location * richloc,
enum diagnostics::kind diagnostic_kind,
xml::printer & xp,
diagnostics::source_effect_info * effect_info = nullptr,
diagnostics::html_label_writer * label_writer = nullptr )
inline

◆ diagnostic_urls_init()

◆ get_terminal_width()

int get_terminal_width ( void )
Return the value of the getenv("COLUMNS") as an integer. If the
value is not set to a positive integer, use ioctl to get the
terminal width. If it fails, return INT_MAX.   

References INT_MAX.

Referenced by print_specific_help(), and diagnostics::context::set_caret_max_width().

◆ option_unspecified_p()

bool option_unspecified_p ( diagnostics::option_id opt_id)
inline

References global_dc.

Referenced by process_options().

◆ warning_enabled_at()

bool warning_enabled_at ( location_t loc,
diagnostics::option_id opt_id )
inline

References global_dc, and warning_enabled_at().

Referenced by warning_enabled_at().

Variable Documentation

◆ CARET_LINE_MARGIN

const int CARET_LINE_MARGIN = 10
This is somehow the right-side margin of a caret line, that is, we
print at least these many characters after the position pointed at
by the caret.   

Referenced by diagnostic_same_line().

◆ global_dc

diagnostics::context* global_dc
extern
This diagnostics::context is used by front-ends that directly output
diagnostic messages without going through `error', `warning',
and similar functions.   

Referenced by gcc_rich_location::add_fixit_insert_formatted(), announce_function(), attr_access::array_as_string(), asm_show_source(), auto_diagnostic_group::auto_diagnostic_group(), auto_diagnostic_nesting_level::auto_diagnostic_nesting_level(), auto_override_urlifier::auto_override_urlifier(), diagnostic_for_asm(), do_self_spec(), driver_handle_option(), text_art::dump_to_file(), emit_diagnostic(), emit_diagnostic(), emit_diagnostic_valist(), emit_diagnostic_valist_meta(), format_string_diagnostic_t::emit_warning_n_va(), error(), error_at(), error_at(), error_meta(), error_n(), escaped_string::escape(), fancy_abort(), fatal_error(), driver::finalize(), fnotice(), general_init(), driver::global_initializations(), inform(), inform(), inform_n(), init_asm_output(), init_options_once(), internal_error(), internal_error_function(), internal_error_no_backtrace(), lang_handle_option(), main(), main(), main(), toplev::main(), lazy_diagnostic_context_path::make_inner_path(), option_unspecified_p(), pedwarn(), pedwarn(), permerror(), permerror(), permerror_opt(), permerror_opt(), print_lto_docs_link(), process_command(), process_options(), run_gcc(), sorry(), sorry_at(), target_handle_option(), tree_dump_pretty_printer::tree_dump_pretty_printer(), verbatim(), warning(), warning_at(), warning_at(), warning_enabled_at(), warning_meta(), warning_n(), warning_n(), auto_diagnostic_group::~auto_diagnostic_group(), auto_diagnostic_nesting_level::~auto_diagnostic_nesting_level(), and auto_override_urlifier::~auto_override_urlifier().