Skip to content

Commit

Permalink
Merge commit '8fc4e6c397e1ce64bec6f9fed148950821cc79e7' into HEAD
Browse files Browse the repository at this point in the history
Accordingly also adjust #2086 "break rust 💥" code, to avoid:

    [...]/source-gcc/gcc/rust/resolve/rust-ast-resolve-expr.cc: In member function ‘virtual void Rust::Resolver::ResolveExpr::visit(Rust::AST::IdentifierExpr&)’:
    [...]/source-gcc/gcc/rust/resolve/rust-ast-resolve-expr.cc:164:42: error: invalid conversion from ‘void (*)(diagnostic_context*, diagnostic_info*, diagnostic_t)’ to ‘diagnostic_finalizer_fn’ {aka ‘void (*)(diagnostic_context*, con
iagnostic_info*, diagnostic_t)’} [-fpermissive]
      164 |       diagnostic_finalizer (global_dc) = funny_ice_finalizer;
          |                                          ^~~~~~~~~~~~~~~~~~~
          |                                          |
          |                                          void (*)(diagnostic_context*, diagnostic_info*, diagnostic_t)
  • Loading branch information
tschwinge committed Mar 19, 2024
2 parents d374f52 + 8fc4e6c commit 136c428
Show file tree
Hide file tree
Showing 22 changed files with 92 additions and 85 deletions.
2 changes: 1 addition & 1 deletion gcc/c-family/c-opts.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ c_common_option_lang_mask (void)
/* Diagnostic finalizer for C/C++/Objective-C/Objective-C++. */
static void
c_diagnostic_finalizer (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info *diagnostic,
diagnostic_t)
{
char *saved_prefix = pp_take_prefix (context->printer);
Expand Down
2 changes: 1 addition & 1 deletion gcc/cp/cp-tree.h
Original file line number Diff line number Diff line change
Expand Up @@ -8083,7 +8083,7 @@ extern void cxx_print_type (FILE *, tree, int);
extern void cxx_print_identifier (FILE *, tree, int);
extern void cxx_print_error_function (diagnostic_context *,
const char *,
struct diagnostic_info *);
const diagnostic_info *);

/* in typeck.cc */
/* Says how we should behave when comparing two arrays one of which
Expand Down
12 changes: 7 additions & 5 deletions gcc/cp/error.cc
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,10 @@ static void print_instantiation_partial_context (diagnostic_context *,
struct tinst_level *,
location_t);
static void maybe_print_constraint_context (diagnostic_context *);
static void cp_diagnostic_starter (diagnostic_context *, diagnostic_info *);
static void cp_print_error_function (diagnostic_context *, diagnostic_info *);
static void cp_diagnostic_starter (diagnostic_context *,
const diagnostic_info *);
static void cp_print_error_function (diagnostic_context *,
const diagnostic_info *);

static bool cp_printer (pretty_printer *, text_info *, const char *,
int, bool, bool, bool, bool *, const char **);
Expand Down Expand Up @@ -3530,7 +3532,7 @@ eh_spec_to_string (tree p, int /*v*/)
/* Langhook for print_error_function. */
void
cxx_print_error_function (diagnostic_context *context, const char *file,
diagnostic_info *diagnostic)
const diagnostic_info *diagnostic)
{
char *prefix;
if (file)
Expand All @@ -3544,7 +3546,7 @@ cxx_print_error_function (diagnostic_context *context, const char *file,

static void
cp_diagnostic_starter (diagnostic_context *context,
diagnostic_info *diagnostic)
const diagnostic_info *diagnostic)
{
diagnostic_report_current_module (context, diagnostic_location (diagnostic));
cp_print_error_function (context, diagnostic);
Expand All @@ -3559,7 +3561,7 @@ cp_diagnostic_starter (diagnostic_context *context,
a diagnostic message. Called from cp_diagnostic_starter. */
static void
cp_print_error_function (diagnostic_context *context,
diagnostic_info *diagnostic)
const diagnostic_info *diagnostic)
{
/* If we are in an instantiation context, current_function_decl is likely
to be wrong, so just rely on print_instantiation_full_context. */
Expand Down
20 changes: 10 additions & 10 deletions gcc/diagnostic-format-json.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ class json_output_format : public diagnostic_output_format
m_cur_children_array = nullptr;
}
void
on_begin_diagnostic (diagnostic_info *) final override
on_begin_diagnostic (const diagnostic_info &) final override
{
/* No-op. */
}
void
on_end_diagnostic (diagnostic_info *diagnostic,
on_end_diagnostic (const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind) final override;
void on_diagram (const diagnostic_diagram &) final override
{
Expand Down Expand Up @@ -188,7 +188,7 @@ json_from_metadata (const diagnostic_metadata *metadata)
within current diagnostic group. */

void
json_output_format::on_end_diagnostic (diagnostic_info *diagnostic,
json_output_format::on_end_diagnostic (const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind)
{
json::object *diag_obj = new json::object ();
Expand All @@ -202,7 +202,7 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic,
"must-not-happen"
};
/* Lose the trailing ": ". */
const char *kind_text = diagnostic_kind_text[diagnostic->kind];
const char *kind_text = diagnostic_kind_text[diagnostic.kind];
size_t len = strlen (kind_text);
gcc_assert (len > 2);
gcc_assert (kind_text[len - 2] == ':');
Expand All @@ -217,15 +217,15 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic,
diag_obj->set_string ("message", pp_formatted_text (m_context.printer));
pp_clear_output_area (m_context.printer);

if (char *option_text = m_context.make_option_name (diagnostic->option_index,
if (char *option_text = m_context.make_option_name (diagnostic.option_index,
orig_diag_kind,
diagnostic->kind))
diagnostic.kind))
{
diag_obj->set_string ("option", option_text);
free (option_text);
}

if (char *option_url = m_context.make_option_url (diagnostic->option_index))
if (char *option_url = m_context.make_option_url (diagnostic.option_index))
{
diag_obj->set_string ("option_url", option_url);
free (option_url);
Expand All @@ -249,7 +249,7 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic,
diag_obj->set_integer ("column-origin", m_context.m_column_origin);
}

const rich_location *richloc = diagnostic->richloc;
const rich_location *richloc = diagnostic.richloc;

json::array *loc_array = new json::array ();
diag_obj->set ("locations", loc_array);
Expand Down Expand Up @@ -280,9 +280,9 @@ json_output_format::on_end_diagnostic (diagnostic_info *diagnostic,
TODO: inlining information
TODO: macro expansion information. */

if (diagnostic->metadata)
if (diagnostic.metadata)
{
json::object *metadata_obj = json_from_metadata (diagnostic->metadata);
json::object *metadata_obj = json_from_metadata (diagnostic.metadata);
diag_obj->set ("metadata", metadata_obj);
}

Expand Down
57 changes: 29 additions & 28 deletions gcc/diagnostic-format-sarif.cc
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class sarif_invocation : public sarif_object
{}

void add_notification_for_ice (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
sarif_builder *builder);
void prepare_to_flush (diagnostic_context *context);

Expand All @@ -67,7 +67,7 @@ class sarif_result : public sarif_object

void
on_nested_diagnostic (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind,
sarif_builder *builder);
void on_diagram (diagnostic_context *context,
Expand All @@ -90,7 +90,7 @@ class sarif_ice_notification : public sarif_object
{
public:
sarif_ice_notification (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
sarif_builder *builder);
};

Expand Down Expand Up @@ -159,15 +159,16 @@ class sarif_builder
public:
sarif_builder (diagnostic_context *context);

void end_diagnostic (diagnostic_context *context, diagnostic_info *diagnostic,
void end_diagnostic (diagnostic_context *context,
const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind);
void emit_diagram (diagnostic_context *context,
const diagnostic_diagram &diagram);
void end_group ();

void flush_to_file (FILE *outf);

json::array *make_locations_arr (diagnostic_info *diagnostic);
json::array *make_locations_arr (const diagnostic_info &diagnostic);
json::object *make_location_object (const rich_location &rich_loc,
const logical_location *logical_loc);
json::object *make_message_object (const char *msg) const;
Expand All @@ -177,7 +178,7 @@ class sarif_builder

private:
sarif_result *make_result_object (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind);
void set_any_logical_locs_arr (json::object *location_obj,
const logical_location *logical_loc);
Expand Down Expand Up @@ -208,7 +209,7 @@ class sarif_builder
json::object *make_tool_component_reference_object_for_cwe () const;
json::object *
make_reporting_descriptor_object_for_warning (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind,
const char *option_text);
json::object *make_reporting_descriptor_object_for_cwe_id (int cwe_id) const;
Expand Down Expand Up @@ -275,7 +276,7 @@ sarif_object::get_or_create_properties ()

void
sarif_invocation::add_notification_for_ice (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
sarif_builder *builder)
{
m_success = false;
Expand Down Expand Up @@ -310,15 +311,15 @@ sarif_invocation::prepare_to_flush (diagnostic_context *context)

void
sarif_result::on_nested_diagnostic (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
diagnostic_t /*orig_diag_kind*/,
sarif_builder *builder)
{
/* We don't yet generate meaningful logical locations for notes;
sometimes these will related to current_function_decl, but
often they won't. */
json::object *location_obj
= builder->make_location_object (*diagnostic->richloc, NULL);
= builder->make_location_object (*diagnostic.richloc, NULL);
json::object *message_obj
= builder->make_message_object (pp_formatted_text (context->printer));
pp_clear_output_area (context->printer);
Expand Down Expand Up @@ -366,7 +367,7 @@ sarif_result::add_related_location (json::object *location_obj)
DIAGNOSTIC is an internal compiler error. */

sarif_ice_notification::sarif_ice_notification (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
sarif_builder *builder)
{
/* "locations" property (SARIF v2.1.0 section 3.58.4). */
Expand Down Expand Up @@ -416,10 +417,10 @@ sarif_builder::sarif_builder (diagnostic_context *context)

void
sarif_builder::end_diagnostic (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind)
{
if (diagnostic->kind == DK_ICE || diagnostic->kind == DK_ICE_NOBT)
if (diagnostic.kind == DK_ICE || diagnostic.kind == DK_ICE_NOBT)
{
m_invocation_obj->add_notification_for_ice (context, diagnostic, this);
return;
Expand Down Expand Up @@ -528,16 +529,16 @@ make_rule_id_for_diagnostic_kind (diagnostic_t diag_kind)

sarif_result *
sarif_builder::make_result_object (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind)
{
sarif_result *result_obj = new sarif_result ();

/* "ruleId" property (SARIF v2.1.0 section 3.27.5). */
/* Ideally we'd have an option_name for these. */
if (char *option_text
= context->make_option_name (diagnostic->option_index,
orig_diag_kind, diagnostic->kind))
= context->make_option_name (diagnostic.option_index,
orig_diag_kind, diagnostic.kind))
{
/* Lazily create reportingDescriptor objects for and add to m_rules_arr.
Set ruleId referencing them. */
Expand Down Expand Up @@ -569,10 +570,10 @@ sarif_builder::make_result_object (diagnostic_context *context,
free (rule_id);
}

if (diagnostic->metadata)
if (diagnostic.metadata)
{
/* "taxa" property (SARIF v2.1.0 section 3.27.8). */
if (int cwe_id = diagnostic->metadata->get_cwe ())
if (int cwe_id = diagnostic.metadata->get_cwe ())
{
json::array *taxa_arr = new json::array ();
json::object *cwe_id_obj
Expand All @@ -581,11 +582,11 @@ sarif_builder::make_result_object (diagnostic_context *context,
result_obj->set ("taxa", taxa_arr);
}

diagnostic->metadata->maybe_add_sarif_properties (*result_obj);
diagnostic.metadata->maybe_add_sarif_properties (*result_obj);
}

/* "level" property (SARIF v2.1.0 section 3.27.10). */
if (const char *sarif_level = maybe_get_sarif_level (diagnostic->kind))
if (const char *sarif_level = maybe_get_sarif_level (diagnostic.kind))
result_obj->set_string ("level", sarif_level);

/* "message" property (SARIF v2.1.0 section 3.27.11). */
Expand All @@ -599,7 +600,7 @@ sarif_builder::make_result_object (diagnostic_context *context,
result_obj->set ("locations", locations_arr);

/* "codeFlows" property (SARIF v2.1.0 section 3.27.18). */
if (const diagnostic_path *path = diagnostic->richloc->get_path ())
if (const diagnostic_path *path = diagnostic.richloc->get_path ())
{
json::array *code_flows_arr = new json::array ();
json::object *code_flow_obj = make_code_flow_object (*path);
Expand All @@ -612,7 +613,7 @@ sarif_builder::make_result_object (diagnostic_context *context,
group. */

/* "fixes" property (SARIF v2.1.0 section 3.27.30). */
const rich_location *richloc = diagnostic->richloc;
const rich_location *richloc = diagnostic.richloc;
if (richloc->get_num_fixit_hints ())
{
json::array *fix_arr = new json::array ();
Expand All @@ -630,7 +631,7 @@ sarif_builder::make_result_object (diagnostic_context *context,
json::object *
sarif_builder::
make_reporting_descriptor_object_for_warning (diagnostic_context *context,
diagnostic_info *diagnostic,
const diagnostic_info &diagnostic,
diagnostic_t /*orig_diag_kind*/,
const char *option_text)
{
Expand All @@ -643,7 +644,7 @@ make_reporting_descriptor_object_for_warning (diagnostic_context *context,
it seems redundant compared to "id". */

/* "helpUri" property (SARIF v2.1.0 section 3.49.12). */
if (char *option_url = context->make_option_url (diagnostic->option_index))
if (char *option_url = context->make_option_url (diagnostic.option_index))
{
reporting_desc->set_string ("helpUri", option_url);
free (option_url);
Expand Down Expand Up @@ -725,15 +726,15 @@ make_tool_component_reference_object_for_cwe () const
- a "notification" object (SARIF v2.1.0 section 3.58.4). */

json::array *
sarif_builder::make_locations_arr (diagnostic_info *diagnostic)
sarif_builder::make_locations_arr (const diagnostic_info &diagnostic)
{
json::array *locations_arr = new json::array ();
const logical_location *logical_loc = NULL;
if (auto client_data_hooks = m_context->get_client_data_hooks ())
logical_loc = client_data_hooks->get_current_logical_location ();

json::object *location_obj
= make_location_object (*diagnostic->richloc, logical_loc);
= make_location_object (*diagnostic.richloc, logical_loc);
locations_arr->append (location_obj);
return locations_arr;
}
Expand Down Expand Up @@ -1704,12 +1705,12 @@ class sarif_output_format : public diagnostic_output_format
m_builder.end_group ();
}
void
on_begin_diagnostic (diagnostic_info *) final override
on_begin_diagnostic (const diagnostic_info &) final override
{
/* No-op, */
}
void
on_end_diagnostic (diagnostic_info *diagnostic,
on_end_diagnostic (const diagnostic_info &diagnostic,
diagnostic_t orig_diag_kind) final override
{
m_builder.end_diagnostic (&m_context, diagnostic, orig_diag_kind);
Expand Down
Loading

0 comments on commit 136c428

Please sign in to comment.