GCC Middle and Back End API Reference
diagnostics Namespace Reference

Namespaces

namespace  changes
namespace  digraphs
namespace  logical_locations
namespace  output_spec
namespace  paths
namespace  state_graphs

Data Structures

class  buffer
class  char_span
class  client_data_hooks
class  client_plugin_info
class  client_version_info
class  column_policy
class  context
struct  counters
struct  diagnostic_info
class  diagram
class  file_cache
class  file_cache_slot
struct  html_generation_options
class  html_label_writer
class  label_effects
struct  loc_map_pair
class  location_print_policy
class  option_classifier
struct  option_id
class  option_manager
class  output_file
class  per_sink_buffer
class  sarif_edge
struct  sarif_generation_options
class  sarif_graph
class  sarif_node
class  sarif_object
class  sarif_property_bag
class  sarif_serialization_format
class  sarif_serialization_format_json
class  sink
class  source_effect_info
class  source_print_policy
struct  source_printing_options
class  text_sink
class  text_sink_buffer
struct  to_html
struct  to_text

Typedefs

typedef void(* text_starter_fn) (text_sink &, const diagnostic_info *)
template<typename TextOrHtml>
using start_span_fn
typedef void(* text_finalizer_fn) (text_sink &, const diagnostic_info *, enum kind)

Enumerations

enum class  kind { last_diagnostic_kind , pop , any }
enum class  sarif_serialization_kind { json , num_values }
enum class  sarif_version { v2_1_0 , v2_2_prerelease_2024_08_08 , num_versions }

Functions

void default_text_starter (diagnostics::text_sink &, const diagnostics::diagnostic_info *)
template<typename TextOrHtml>
void default_start_span_fn (const diagnostics::location_print_policy &, TextOrHtml &text_or_html, expanded_location)
void default_text_finalizer (diagnostics::text_sink &, const diagnostics::diagnostic_info *, enum diagnostics::kind)
int num_digits (int)
char * get_cwe_url (int cwe)
const char * maybe_line_and_column (int line, int col)
const char * get_text_for_kind (enum kind kind)
const char * get_color_for_kind (enum kind kind)
static int convert_column_unit (file_cache &fc, enum diagnostics_column_unit column_unit, int tabstop, expanded_location s)
static void print_escaped_string (pretty_printer *pp, const char *text)
static void print_parseable_fixits (file_cache &fc, pretty_printer *pp, rich_location *richloc, enum diagnostics_column_unit column_unit, int tabstop)
pretty_printerget_printer (to_text &)
text_starter_fntext_starter (context *dc)
start_span_fn< to_text > & start_span (context *dc)
text_finalizer_fntext_finalizer (context *dc)
static const char * default_charset_callback (const char *)
static const char * find_end_of_line (const char *s, size_t len)
diagnostics::output_file open_html_output_file (context &dc, line_maps *line_maps, const char *base_file_name)
std::unique_ptr< sinkmake_html_sink (context &dc, const line_maps &line_maps, const html_generation_options &html_gen_opts, output_file output_file_)
void print_path_as_html (xml::printer &xp, const paths::path &path, context &dc, html_label_writer *event_label_writer, const source_print_policy &dspp)
void maybe_unwind_expanded_macro_loc (text_sink &text_output, location_t where)
void virt_loc_aware_text_finalizer (text_sink &text_output, const diagnostic_info *diagnostic)
output_file open_sarif_output_file (context &dc, line_maps *line_maps, const char *base_file_name, enum sarif_serialization_kind serialization_kind)
sinkinit_sarif_stderr (context &dc, const line_maps *line_maps, bool formatted)
sinkinit_sarif_file (context &dc, line_maps *line_maps, bool formatted, const char *base_file_name)
sinkinit_sarif_stream (context &dc, const line_maps *line_maps, bool formatted, FILE *stream)
std::unique_ptr< sinkmake_sarif_sink (context &dc, const line_maps &line_maps, std::unique_ptr< sarif_serialization_format > serialization_format, const sarif_generation_options &sarif_gen_opts, output_file output_file_)
std::unique_ptr< sarif_graphmake_sarif_graph (const digraphs::digraph &g, sarif_builder *builder, sarif_location_manager *sarif_location_mgr)
std::unique_ptr< sarif_nodemake_sarif_node (const digraphs::node &n, sarif_builder *builder, sarif_location_manager *sarif_location_mgr)
std::unique_ptr< sarif_edgemake_sarif_edge (const digraphs::edge &e, sarif_builder *builder)
void output_format_init (context &, const char *main_input_filename_, const char *base_file_name, enum diagnostics_output_format, bool json_formatting)
template<>
void default_start_span_fn< to_text > (const location_print_policy &loc_policy, to_text &out, expanded_location exploc)
template<>
void default_start_span_fn< to_html > (const location_print_policy &loc_policy, to_html &out, expanded_location exploc)
static unsigned get_bullet_point_unichar (bool unicode)
static bool use_unicode_p (const context &dc)
static unsigned get_bullet_point_unichar (context &dc)
void default_text_finalizer (text_sink &text_output, const diagnostic_info *diagnostic, enum kind)

Variables

static const char *const diagnostic_kind_text []
static const char *const diagnostic_kind_color []

Detailed Description

Forward decl.
Declarations relating to class gcc_rich_location Copyright (C) 2014-2025 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/>.
Declarations for variables relating to reading the source file. Used by parsers, lexical analyzers, and error message routines. Copyright (C) 1993-2025 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/>.
Default macros to initialize the lang_hooks data structure. Copyright (C) 2001-2025 Free Software Foundation, Inc. Contributed by Alexandre Oliva <aoliva@redhat.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/>.
The lang_hooks data structure. Copyright (C) 2001-2025 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/>.
FIXME: This file should be #include-d after tree.h (for enum tree_code).
Support for buffering diagnostics before flushing them to output sinks. Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
Additional metadata about a client for a diagnostic context. Copyright (C) 2022-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
Declare diagnostics::context and related types. Copyright (C) 2000-2025 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/>.
Various declarations for language-independent diagnostics subroutines. Copyright (C) 2000-2025 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/>.
Caching input files for use by diagnostics. Copyright (C) 2004-2025 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/>.
HTML output for diagnostics. Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
An enum used to discriminate severities of diagnostics. Copyright (C) 1998-2025 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/>.
Helper class for deferring path creation until a diagnostic is emitted. Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
Logical location support, without knowledge of "tree". Copyright (C) 2022-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
Code for unwinding macro expansions in diagnostics. Copyright (C) 1999-2025 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/>.
Code for unwinding macro expansions in diagnostics. Copyright (C) 2000-2025 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/>.
Additional metadata for a diagnostic. Copyright (C) 2019-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
Stacks of set of classifications of diagnostics. Copyright (C) 1999-2025 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/>.
Stacks of set of classifications of diagnostics. Copyright (C) 2000-2025 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/>.
Declaration of struct diagnostics::option_id. Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
RAII class for managing FILE * for diagnostic formats. Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
Support for the DSL of -fdiagnostics-add-output= and -fdiagnostics-set-output=. Copyright (C) 2024-2025 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/>.
Paths through the code associated with a diagnostic. Copyright (C) 2019-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
SARIF output for diagnostics. Copyright (C) 2023-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
Declarations for managing different output formats for diagnostics. Copyright (C) 2023-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
Classes for adding special effects when quoting source code. Copyright (C) 2024-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.
Disable warnings about quoting issues in the pp_xxx calls below that (intentionally) don't follow GCC diagnostic conventions.
Classic text-based output of diagnostics. Copyright (C) 2023-2025 Free Software Foundation, Inc. Contributed by David Malcolm <dmalcolm@redhat.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/>.

Typedef Documentation

◆ start_span_fn

template<typename TextOrHtml>
using diagnostics::start_span_fn
Initial value:
void (*) (const location_print_policy &,
TextOrHtml &text_or_html,
expanded_location)
Definition diagnostics/context.h:191

◆ text_finalizer_fn

typedef void(* diagnostics::text_finalizer_fn) (text_sink &, const diagnostic_info *, enum kind)

◆ text_starter_fn

typedef void(* diagnostics::text_starter_fn) (text_sink &, const diagnostic_info *)

Enumeration Type Documentation

◆ kind

enum class diagnostics::kind
strong
Constants used to discriminate diagnostics.
Enumerator
last_diagnostic_kind 
pop 
any 

◆ sarif_serialization_kind

Enum for choosing what format to serializing the generated SARIF into.
Enumerator
json 
num_values 

◆ sarif_version

enum class diagnostics::sarif_version
strong
Control of SARIF generation.
Enumerator
v2_1_0 
v2_2_prerelease_2024_08_08 
num_versions 

Function Documentation

◆ convert_column_unit()

int diagnostics::convert_column_unit ( file_cache & fc,
enum diagnostics_column_unit column_unit,
int tabstop,
expanded_location s )
static
Given an expanded_location, convert the column (which is in 1-based bytes) to the requested units, without converting the origin. Return -1 if the column is invalid (<= 0).

References DIAGNOSTICS_COLUMN_UNIT_BYTE, DIAGNOSTICS_COLUMN_UNIT_DISPLAY, gcc_unreachable, and location_compute_display_column().

Referenced by diagnostics::column_policy::converted_column(), and print_parseable_fixits().

◆ default_charset_callback()

const char * diagnostics::default_charset_callback ( const char * )
static
Input charset configuration.

Referenced by diagnostics::file_cache::initialize_input_context().

◆ default_start_span_fn()

template<typename TextOrHtml>
void diagnostics::default_start_span_fn ( const diagnostics::location_print_policy & ,
TextOrHtml & text_or_html,
expanded_location  )

◆ default_start_span_fn< to_html >()

template<>
void diagnostics::default_start_span_fn< to_html > ( const location_print_policy & loc_policy,
to_html & out,
expanded_location exploc )

◆ default_start_span_fn< to_text >()

◆ default_text_finalizer() [1/2]

void diagnostics::default_text_finalizer ( diagnostics::text_sink & ,
const diagnostics::diagnostic_info * ,
enum diagnostics::kind  )

◆ default_text_finalizer() [2/2]

◆ default_text_starter()

◆ find_end_of_line()

const char * diagnostics::find_end_of_line ( const char * s,
size_t len )
static
Helper function for file_cache_slot::get_next_line (), to find the end of the next line. Returns with the memchr convention, i.e. nullptr if a line terminator was not found. We need to determine line endings in the same manner that libcpp does: any of \n, \r\n, or \r is a line ending.

References end().

Referenced by diagnostics::file_cache_slot::get_next_line().

◆ get_bullet_point_unichar() [1/2]

unsigned diagnostics::get_bullet_point_unichar ( bool unicode)
static
Get the unicode code point for bullet points when showing nested diagnostics.

Referenced by diagnostics::text_sink::build_indent_prefix(), and get_bullet_point_unichar().

◆ get_bullet_point_unichar() [2/2]

unsigned diagnostics::get_bullet_point_unichar ( context & dc)
static
Get the unicode code point for bullet points when showing nested diagnostics.

References get_bullet_point_unichar(), and use_unicode_p().

◆ get_color_for_kind()

const char * diagnostics::get_color_for_kind ( enum kind kind)

◆ get_cwe_url()

char * diagnostics::get_cwe_url ( int cwe)
extern
Generate a URL string describing CWE. The caller is responsible for freeing the string.

Referenced by diagnostics::text_sink::print_any_cwe().

◆ get_printer()

◆ get_text_for_kind()

const char * diagnostics::get_text_for_kind ( enum kind kind)
Get unlocalized string describing KIND.

References diagnostic_kind_text.

Referenced by diagnostics::text_sink::build_prefix(), and fancy_abort().

◆ init_sarif_file()

sink & diagnostics::init_sarif_file ( context & dc,
line_maps * line_maps,
bool formatted,
const char * base_file_name )
extern

References base_file_name().

◆ init_sarif_stderr()

sink & diagnostics::init_sarif_stderr ( context & dc,
const line_maps * line_maps,
bool formatted )
extern

◆ init_sarif_stream()

sink & diagnostics::init_sarif_stream ( context & dc,
const line_maps * line_maps,
bool formatted,
FILE * stream )
extern

◆ make_html_sink()

std::unique_ptr< sink > diagnostics::make_html_sink ( context & dc,
const line_maps & line_maps,
const html_generation_options & html_gen_opts,
output_file output_file_ )
extern

References path.

◆ make_sarif_edge()

std::unique_ptr< sarif_edge > diagnostics::make_sarif_edge ( const digraphs::edge & e,
sarif_builder * builder )
extern

◆ make_sarif_graph()

std::unique_ptr< sarif_graph > diagnostics::make_sarif_graph ( const digraphs::digraph & g,
sarif_builder * builder,
sarif_location_manager * sarif_location_mgr )
extern

◆ make_sarif_node()

std::unique_ptr< sarif_node > diagnostics::make_sarif_node ( const digraphs::node & n,
sarif_builder * builder,
sarif_location_manager * sarif_location_mgr )
extern

◆ make_sarif_sink()

std::unique_ptr< sink > diagnostics::make_sarif_sink ( context & dc,
const line_maps & line_maps,
std::unique_ptr< sarif_serialization_format > serialization_format,
const sarif_generation_options & sarif_gen_opts,
output_file output_file_ )
extern

◆ maybe_line_and_column()

const char * diagnostics::maybe_line_and_column ( int line,
int col )
extern
Helpers for writing lang-specific starters/finalizers for text output.
Return a formatted line and column ':%line:%column'. Elided if line == 0 or col < 0. (A column of 0 may be valid due to the -fdiagnostics-column-origin option.) The result is a statically allocated buffer.

References gcc_checking_assert.

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

◆ maybe_unwind_expanded_macro_loc()

void diagnostics::maybe_unwind_expanded_macro_loc ( text_sink & text_output,
location_t where )
Unwind the different macro expansions that lead to the token which location is WHERE and emit diagnostics showing the resulting unwound macro expansion trace. Let's look at an example to see how the trace looks like. Suppose we have this piece of code, artificially annotated with the line numbers to increase legibility: $ cat -n test.c 1 #define OPERATE(OPRD1, OPRT, OPRD2) \ 2 OPRD1 OPRT OPRD2; 3 4 #define SHIFTL(A,B) \ 5 OPERATE (A,<<,B) 6 7 #define MULT(A) \ 8 SHIFTL (A,1) 9 10 void 11 g () 12 { 13 MULT (1.0);// 1.0 << 1; <-- so this is an error. 14 } Here is the diagnostic that we want the compiler to generate: test.c: In function ‘g’: test.c:5:14: error: invalid operands to binary << (have ‘double’ and ‘int’) test.c:2:9: note: in definition of macro 'OPERATE' test.c:8:3: note: in expansion of macro 'SHIFTL' test.c:13:3: note: in expansion of macro 'MULT' The part that goes from the third to the fifth line of this diagnostic (the lines containing the 'note:' string) is called the unwound macro expansion trace. That's the part generated by this function.

References diagnostics::text_sink::append_note(), expand_location_to_spelling_point(), FOR_EACH_VEC_ELT, line_table, diagnostics::loc_map_pair::map, map, and diagnostics::loc_map_pair::where.

Referenced by virt_loc_aware_text_finalizer().

◆ num_digits()

int diagnostics::num_digits ( int value)
extern
Compute the number of digits in the decimal representation of an integer.
Get the number of digits in the decimal representation of VALUE.

References gcc_assert, and diagnostics::logical_locations::value.

Referenced by dump_location_info().

◆ open_html_output_file()

diagnostics::output_file diagnostics::open_html_output_file ( context & dc,
line_maps * line_maps,
const char * base_file_name )
extern

References base_file_name().

◆ open_sarif_output_file()

output_file diagnostics::open_sarif_output_file ( context & dc,
line_maps * line_maps,
const char * base_file_name,
enum sarif_serialization_kind serialization_kind )
extern

References base_file_name().

◆ output_format_init()

void diagnostics::output_format_init ( context & ,
const char * main_input_filename_,
const char * base_file_name,
enum diagnostics_output_format,
bool json_formatting )
extern

◆ print_escaped_string()

void diagnostics::print_escaped_string ( pretty_printer * pp,
const char * text )
static
Helper function for print_parseable_fixits. Print TEXT to PP, obeying the escaping rules for -fdiagnostics-parseable-fixits.

References gcc_assert, pp_character(), pp_printf(), pp_string(), and diagnostics::logical_locations::text.

Referenced by print_parseable_fixits().

◆ print_parseable_fixits()

void diagnostics::print_parseable_fixits ( file_cache & fc,
pretty_printer * pp,
rich_location * richloc,
enum diagnostics_column_unit column_unit,
int tabstop )
static
Implementation of -fdiagnostics-parseable-fixits and GCC_EXTRA_DIAGNOSTIC_OUTPUT. Print a machine-parseable version of all fixits in RICHLOC to PP, using COLUMN_UNIT to express columns. Use TABSTOP when handling DIAGNOSTICS_COLUMN_UNIT_DISPLAY.

References convert_column_unit(), expand_location(), gcc_assert, i, pp_newline(), pp_printf(), pp_set_prefix(), pp_string(), pp_take_prefix(), and print_escaped_string().

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

◆ print_path_as_html()

void diagnostics::print_path_as_html ( xml::printer & xp,
const paths::path & path,
context & dc,
html_label_writer * event_label_writer,
const source_print_policy & dspp )
extern
Print PATH_ as HTML to XP, using DC and DSPP for settings. If non-null, use EVENT_LABEL_WRITER when writing events.

References diagnostics::source_print_policy::get_options(), diagnostics::context::get_reference_printer(), diagnostics::source_printing_options::show_event_links_p, and diagnostics::context::show_path_depths_p().

◆ start_span()

start_span_fn< to_text > & diagnostics::start_span ( context * dc)
inline
Client supplied function called between disjoint spans of source code, so that the context can print something to indicate that a new span of source code has begun.

◆ text_finalizer()

text_finalizer_fn & diagnostics::text_finalizer ( context * dc)
inline
Client supplied function called after a diagnostic message is displayed (for text-based diagnostic output).

Referenced by diagnostics::text_sink::on_report_diagnostic(), and tree_diagnostics_defaults().

◆ text_starter()

text_starter_fn & diagnostics::text_starter ( context * dc)
inline
Client supplied function to announce a diagnostic (for text-based diagnostic output).

Referenced by diagnostic_manager::diagnostic_manager(), diagnostics::text_sink::on_report_diagnostic(), and tree_diagnostics_defaults().

◆ use_unicode_p()

bool diagnostics::use_unicode_p ( const context & dc)
static
Return true if DC's theme supports unicode characters.

References diagnostics::context::get_diagram_theme().

Referenced by get_bullet_point_unichar().

◆ virt_loc_aware_text_finalizer()

void diagnostics::virt_loc_aware_text_finalizer ( text_sink & text_output,
const diagnostic_info * diagnostic )
This is a diagnostic finalizer implementation that is aware of virtual locations produced by libcpp. It has to be called by the diagnostic finalizer of front ends that uses libcpp and wish to get diagnostics involving tokens resulting from macro expansion. For a given location, if said location belongs to a token resulting from a macro expansion, this starter prints the context of the token. E.g, for multiply nested macro expansion, it unwinds the nested macro expansions and prints them in a manner that is similar to what is done for function call stacks, or template instantiation contexts.

References diagnostic_location(), and maybe_unwind_expanded_macro_loc().

Variable Documentation

◆ diagnostic_kind_color

const char* const diagnostics::diagnostic_kind_color[]
static
Initial value:
= {
#define DEFINE_DIAGNOSTIC_KIND(K, T, C)
nullptr
}

Referenced by get_color_for_kind().

◆ diagnostic_kind_text

const char* const diagnostics::diagnostic_kind_text[]
static
Initial value:
= {
#define DEFINE_DIAGNOSTIC_KIND(K, T, C)
"must-not-happen"
}

Referenced by get_text_for_kind().