diff options
Diffstat (limited to 'gcc/testsuite/gcc.dg/plugin')
24 files changed, 526 insertions, 94 deletions
diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc b/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc index 1fe5b5c..01ab766 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_cpython_plugin.cc @@ -23,8 +23,8 @@ #include "target.h" #include "fold-const.h" #include "tree-pretty-print.h" -#include "diagnostic-color.h" -#include "diagnostic-metadata.h" +#include "diagnostics/color.h" +#include "diagnostics/metadata.h" #include "tristate.h" #include "bitmap.h" #include "selftest.h" diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.cc b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.cc index fa2f2fa..c101c45 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_gil_plugin.cc @@ -16,7 +16,7 @@ #include "gimple.h" #include "gimple-iterator.h" #include "gimple-walk.h" -#include "diagnostic-event-id.h" +#include "diagnostics/event-id.h" #include "analyzer/common.h" #include "analyzer/analyzer-logging.h" #include "json.h" @@ -120,20 +120,22 @@ public: return false; } - diagnostic_event::meaning + diagnostics::paths::event::meaning get_meaning_for_state_change (const evdesc::state_change &change) const final override { + using event = diagnostics::paths::event; + if (change.is_global_p ()) { if (change.m_new_state == m_sm.m_released_gil) - return diagnostic_event::meaning (diagnostic_event::verb::release, - diagnostic_event::noun::lock); + return event::meaning (event::verb::release, + event::noun::lock); else if (change.m_new_state == m_sm.get_start_state ()) - return diagnostic_event::meaning (diagnostic_event::verb::acquire, - diagnostic_event::noun::lock); + return event::meaning (event::verb::acquire, + event::noun::lock); } - return diagnostic_event::meaning (); + return event::meaning (); } protected: gil_diagnostic (const gil_state_machine &sm) : m_sm (sm) diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.cc b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.cc index 18e054b..fc282a7 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_kernel_plugin.cc @@ -23,8 +23,8 @@ #include "target.h" #include "fold-const.h" #include "tree-pretty-print.h" -#include "diagnostic-color.h" -#include "diagnostic-metadata.h" +#include "diagnostics/color.h" +#include "diagnostics/metadata.h" #include "tristate.h" #include "bitmap.h" #include "selftest.h" diff --git a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.cc b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.cc index 5a6e075..44fcf37 100644 --- a/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/analyzer_known_fns_plugin.cc @@ -23,8 +23,8 @@ #include "target.h" #include "fold-const.h" #include "tree-pretty-print.h" -#include "diagnostic-color.h" -#include "diagnostic-metadata.h" +#include "diagnostics/color.h" +#include "diagnostics/metadata.h" #include "tristate.h" #include "bitmap.h" #include "selftest.h" diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.c new file mode 100644 index 0000000..2256a63 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.c @@ -0,0 +1,13 @@ +/* { dg-do compile } */ +/* { dg-options "-fdiagnostics-add-output=experimental-html:javascript=no" } */ + +extern void here (void); + +void test_graphs (void) +{ + here (); /* { dg-error "this is a placeholder error, with graphs" } */ +} + +/* Use a Python script to verify various properties about the generated + HTML file: + { dg-final { run-html-pytest diagnostic-test-graphs-html.c "diagnostic-test-graphs-html.py" } } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.py new file mode 100644 index 0000000..11e5fd1 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-html.py @@ -0,0 +1,48 @@ +# Verify that metadata works in HTML output. + +from htmltest import * + +import pytest + +@pytest.fixture(scope='function', autouse=True) +def html_tree(): + return html_tree_from_env() + +def test_result_graph(html_tree): + root = html_tree.getroot () + assert root.tag == make_tag('html') + + body = root.find('xhtml:body', ns) + assert body is not None + + diag_list = body.find('xhtml:div', ns) + assert diag_list is not None + assert diag_list.attrib['class'] == 'gcc-diagnostic-list' + + diag = diag_list.find('xhtml:div', ns) + assert diag is not None + + message = diag.find("./xhtml:div[@class='gcc-message']", ns) + assert message.attrib['id'] == 'gcc-diag-0-message' + + assert message[0].tag == make_tag('strong') + assert message[0].tail == ' this is a placeholder error, with graphs ' + + graph = diag.find("./xhtml:div[@class='gcc-directed-graph']", ns) + assert graph is not None + + header = graph.find("./xhtml:h2", ns) + assert header.text == 'foo' + +def test_run_graph(html_tree): + root = html_tree.getroot () + assert root.tag == make_tag('html') + + body = root.find('xhtml:body', ns) + assert body is not None + + graph = body.find("./xhtml:div[@class='gcc-directed-graph']", ns) + assert graph is not None + + header = graph.find("./xhtml:h2", ns) + assert header.text == 'Optimization Passes' diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c new file mode 100644 index 0000000..4170f51 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.c @@ -0,0 +1,16 @@ +/* { dg-do compile } */ +/* { dg-options "-fdiagnostics-add-output=sarif" } */ + +extern void here (void); + +void test_graphs (void) +{ + here (); /* { dg-error "this is a placeholder error, with graphs" } */ +} + +/* Verify that some JSON was written to a file with the expected name. */ +/* { dg-final { verify-sarif-file } } */ + +/* Use a Python script to verify various properties about the generated + .sarif file: + { dg-final { run-sarif-pytest diagnostic-test-graphs-sarif.c "diagnostic-test-graphs-sarif.py" } } */ diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py new file mode 100644 index 0000000..4bb7535 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs-sarif.py @@ -0,0 +1,55 @@ +from sarif import * + +import pytest + +@pytest.fixture(scope='function', autouse=True) +def sarif(): + return sarif_from_env() + +def test_basics(sarif): + schema = sarif['$schema'] + assert schema == "https://docs.oasis-open.org/sarif/sarif/v2.1.0/errata01/os/schemas/sarif-schema-2.1.0.json" + + version = sarif['version'] + assert version == "2.1.0" + +def test_result_graph(sarif): + runs = sarif['runs'] + run = runs[0] + results = run['results'] + + assert len(results) == 1 + + result = results[0] + assert result['level'] == 'error' + assert result['message']['text'] == "this is a placeholder error, with graphs" + + assert len(result['graphs']) == 2 + + assert result['graphs'][0]['description']['text'] == 'foo' + + assert len(result['graphs'][0]['nodes']) == 2 + assert result['graphs'][0]['nodes'][0]['id'] == 'a' + assert result['graphs'][0]['nodes'][1]['id'] == 'b' + assert result['graphs'][0]['nodes'][1]['properties']['/placeholder-prefix/color'] == 'red' + assert len(result['graphs'][0]['nodes'][1]['children']) == 1 + assert result['graphs'][0]['nodes'][1]['children'][0]['id'] == 'c' + assert result['graphs'][0]['nodes'][1]['children'][0]['label']['text'] == 'I am a node label' + + assert len(result['graphs'][0]['edges']) == 1 + result['graphs'][0]['edges'][0]['id'] == 'my-edge' + assert result['graphs'][0]['edges'][0]['label']['text'] == 'I am an edge label' + assert result['graphs'][0]['edges'][0]['sourceNodeId'] == 'a' + assert result['graphs'][0]['edges'][0]['targetNodeId'] == 'c' + + assert result['graphs'][1]['description']['text'] == 'bar' + +def test_run_graph(sarif): + runs = sarif['runs'] + run = runs[0] + + assert len(run['graphs']) == 1 + + assert run['graphs'][0]['description']['text'] == 'Optimization Passes' + assert run['graphs'][0]['nodes'][0]['id'] == 'all_lowering_passes' + assert run['graphs'][0]['edges'][0]['id'] == 'edge0' diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs.c new file mode 100644 index 0000000..7973954 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-graphs.c @@ -0,0 +1,8 @@ +/* { dg-do compile } */ + +extern void here (void); + +void test_graphs (void) +{ + here (); /* { dg-error "this is a placeholder error, with graphs" } */ +} diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py index aca1b6c..eaca35a 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-show-locus.py @@ -1,4 +1,4 @@ -# Verify that diagnostic-show-locus.cc works with HTML output. +# Verify that diagnostics/source-printing.cc works with HTML output. from htmltest import * diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc index 4ade232..48f8325 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_group_plugin.cc @@ -27,7 +27,7 @@ #include "plugin-version.h" #include "c-family/c-common.h" #include "diagnostic.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" #include "context.h" int plugin_is_GPL_compatible; @@ -165,8 +165,8 @@ pass_test_groups::execute (function *fun) expected output. */ void -test_diagnostic_text_starter (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic) +test_diagnostic_text_starter (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diagnostic) { pp_set_prefix (text_output.get_printer (), xstrdup ("PREFIX: ")); } @@ -175,22 +175,22 @@ test_diagnostic_text_starter (diagnostic_text_output_format &text_output, expected output. */ void -test_diagnostic_start_span_fn (const diagnostic_location_print_policy &, - to_text &sink, +test_diagnostic_start_span_fn (const diagnostics::location_print_policy &, + diagnostics::to_text &sink, expanded_location) { - pretty_printer *pp = get_printer (sink); + pretty_printer *pp = diagnostics::get_printer (sink); pp_string (pp, "START_SPAN_FN: "); pp_newline (pp); } -/* Custom output format subclass. */ +/* Custom text_sink subclass. */ -class test_output_format : public diagnostic_text_output_format +class custom_test_sink : public diagnostics::text_sink { public: - test_output_format (diagnostic_context &context) - : diagnostic_text_output_format (context) + custom_test_sink (diagnostics::context &context) + : diagnostics::text_sink (context) {} void on_begin_group () final override @@ -228,10 +228,9 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - diagnostic_text_starter (global_dc) = test_diagnostic_text_starter; - diagnostic_start_span (global_dc) = test_diagnostic_start_span_fn; - global_dc->set_output_format - (::std::make_unique<test_output_format> (*global_dc)); + diagnostics::text_starter (global_dc) = test_diagnostic_text_starter; + diagnostics::start_span (global_dc) = test_diagnostic_start_span_fn; + global_dc->set_sink (::std::make_unique<custom_test_sink> (*global_dc)); pass_info.pass = new pass_test_groups (g); pass_info.reference_pass_name = "*warn_function_noreturn"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.cc index 44b94da..7e34a42 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_show_trees.cc @@ -115,7 +115,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->m_source_printing.max_width = 80; + global_dc->get_source_printing_options ().max_width = 80; register_callback (plugin_name, PLUGIN_PRE_GENERICIZE, diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_graphs.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_graphs.cc new file mode 100644 index 0000000..7398a29 --- /dev/null +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_graphs.cc @@ -0,0 +1,283 @@ +/* This plugin exercises diagnostic graphs. + We emit an error with a pair of digraphs associated with it, + and a global digraph showing the optimization passes. */ + +#define INCLUDE_MAP +#define INCLUDE_STRING +#define INCLUDE_VECTOR +#include "gcc-plugin.h" +#include "config.h" +#include "system.h" +#include "coretypes.h" +#include "tm.h" +#include "tree.h" +#include "stringpool.h" +#include "toplev.h" +#include "basic-block.h" +#include "hash-table.h" +#include "vec.h" +#include "ggc.h" +#include "basic-block.h" +#include "tree-ssa-alias.h" +#include "internal-fn.h" +#include "gimple.h" +#include "gimple-iterator.h" +#include "gimple-fold.h" +#include "tree-eh.h" +#include "gimple-expr.h" +#include "is-a.h" +#include "tree.h" +#include "tree-pass.h" +#include "intl.h" +#include "plugin-version.h" +#include "diagnostic.h" +#include "context.h" +#include "gcc-rich-location.h" +#include "diagnostics/metadata.h" +#include "diagnostics/digraphs.h" +#include "pass_manager.h" + + +int plugin_is_GPL_compatible; + +const pass_data pass_data_test_graph_emission = +{ + GIMPLE_PASS, /* type */ + "test_graph_emission", /* name */ + OPTGROUP_NONE, /* optinfo_flags */ + TV_NONE, /* tv_id */ + PROP_ssa, /* properties_required */ + 0, /* properties_provided */ + 0, /* properties_destroyed */ + 0, /* todo_flags_start */ + 0, /* todo_flags_finish */ +}; + +class pass_test_graph_emission : public gimple_opt_pass +{ +public: + pass_test_graph_emission(gcc::context *ctxt) + : gimple_opt_pass(pass_data_test_graph_emission, ctxt) + {} + + /* opt_pass methods: */ + bool gate (function *) { return true; } + virtual unsigned int execute (function *); + +}; // class pass_test_graph_emission + +/* Determine if STMT is a call with NUM_ARGS arguments to a function + named FUNCNAME. + If so, return STMT as a gcall *. Otherwise return NULL. */ + +static gcall * +check_for_named_call (gimple *stmt, + const char *funcname, unsigned int num_args) +{ + gcc_assert (funcname); + + gcall *call = dyn_cast <gcall *> (stmt); + if (!call) + return NULL; + + tree fndecl = gimple_call_fndecl (call); + if (!fndecl) + return NULL; + + if (strcmp (IDENTIFIER_POINTER (DECL_NAME (fndecl)), funcname)) + return NULL; + + if (gimple_call_num_args (call) != num_args) + { + error_at (stmt->location, "expected number of args: %i (got %i)", + num_args, gimple_call_num_args (call)); + return NULL; + } + + return call; +} + +class lazy_passes_graph : public lazily_created<diagnostics::digraphs::digraph> +{ +public: + lazy_passes_graph (const ::gcc::pass_manager &pass_manager_) + : m_pass_manager (pass_manager_) + { + } + +private: + std::unique_ptr<diagnostics::digraphs::digraph> + create_object () const final override + { + auto g = std::make_unique<diagnostics::digraphs::digraph> (); + g->set_description ("Optimization Passes"); + +#define DEF_PASS_LIST(NAME) \ + add_top_level_pass_list (*g, #NAME, m_pass_manager.NAME); + + GCC_PASS_LISTS + +#undef DEF_PASS_LIST + + return g; + } + + void + add_top_level_pass_list (diagnostics::digraphs::digraph &g, + const char *pass_list_name, + const opt_pass *p) const + { + gcc_assert (p); + auto n = std::make_unique<diagnostics::digraphs::node> (g, pass_list_name); + n->set_label (pass_list_name); + add_child_pass (g, *n, *p); + g.add_node (std::move (n)); + } + + diagnostics::digraphs::node & + add_child_pass (diagnostics::digraphs::digraph &g, + diagnostics::digraphs::node &parent_node, + const opt_pass &p) const + { + std::string node_label; + std::string node_id; + if (p.static_pass_number > 0 ) + { + node_label = std::to_string (p.static_pass_number) + "_" + p.name; + node_id = node_label; + } + else + { + node_label = std::string (p.name); + pretty_printer pp; + pp_printf (&pp, "%s_%p", p.name, &p); + node_id = pp_formatted_text (&pp); + } + auto n + = std::make_unique<diagnostics::digraphs::node> (g, + std::move (node_id)); + n->set_label (node_label.c_str ()); + diagnostics::digraphs::node &result = *n; + parent_node.add_child (std::move (n)); + + // TODO: add attrs for things like type, properties_*, etc + + if (p.sub) + { + auto &other_node = add_child_pass (g, parent_node, *p.sub); + g.add_edge (nullptr, result, other_node, "sub"); + } + + if (p.next) + { + auto &other_node = add_child_pass (g, parent_node, *p.next); + g.add_edge (nullptr, result, other_node, "next"); + } + + return result; + } + + const ::gcc::pass_manager &m_pass_manager; +}; + +static void +report_diag_with_graphs (location_t loc) +{ + class my_lazy_digraphs : public diagnostics::metadata::lazy_digraphs + { + public: + using diagnostic_graph = diagnostics::digraphs::digraph; + using diagnostic_node = diagnostics::digraphs::node; + using diagnostic_edge = diagnostics::digraphs::edge; + + std::unique_ptr<std::vector<std::unique_ptr<diagnostic_graph>>> + create_object () const final override + { + auto graphs + = std::make_unique<std::vector<std::unique_ptr<diagnostic_graph>>> (); + + graphs->push_back (make_test_graph ("foo")); + graphs->push_back (make_test_graph ("bar")); + + return graphs; + } + + private: + std::unique_ptr<diagnostic_graph> + make_test_graph (const char *desc) const + { + auto g = std::make_unique<diagnostic_graph> (); + g->set_description (desc); + auto a = std::make_unique<diagnostic_node> (*g, "a"); + auto b = std::make_unique<diagnostic_node> (*g, "b"); +#define KEY_PREFIX "/placeholder-prefix/" + b->set_attr (KEY_PREFIX, "color", "red"); +#undef KEY_PREFIX + auto c = std::make_unique<diagnostic_node> (*g, "c"); + c->set_label ("I am a node label"); + + auto e = std::make_unique<diagnostic_edge> (*g, "my-edge", *a, *c); + e->set_label ("I am an edge label"); + g->add_edge (std::move (e)); + + g->add_node (std::move (a)); + + b->add_child (std::move (c)); + g->add_node (std::move (b)); + + return g; + } + }; + + gcc_rich_location rich_loc (loc); + diagnostics::metadata meta; + my_lazy_digraphs ldg; + meta.set_lazy_digraphs (&ldg); + error_meta (&rich_loc, meta, + "this is a placeholder error, with graphs"); +} + +/* Exercise diagnostic graph emission. */ + +unsigned int +pass_test_graph_emission::execute (function *fun) +{ + gimple_stmt_iterator gsi; + basic_block bb; + + FOR_EACH_BB_FN (bb, fun) + for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi)) + { + gimple *stmt = gsi_stmt (gsi); + + if (gcall *call = check_for_named_call (stmt, "here", 0)) + report_diag_with_graphs (gimple_location (call)); + } + + return 0; +} + +int +plugin_init (struct plugin_name_args *plugin_info, + struct plugin_gcc_version *version) +{ + struct register_pass_info pass_info; + const char *plugin_name = plugin_info->base_name; + int argc = plugin_info->argc; + struct plugin_argument *argv = plugin_info->argv; + + if (!plugin_default_version_check (version, &gcc_version)) + return 1; + + pass_info.pass = new pass_test_graph_emission (g); + pass_info.reference_pass_name = "ssa"; + pass_info.ref_pass_instance_number = 1; + pass_info.pos_op = PASS_POS_INSERT_AFTER; + register_callback (plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, + &pass_info); + + gcc_assert (::g->get_passes ()); + global_dc->report_global_digraph (lazy_passes_graph (*::g->get_passes ())); + + return 0; +} diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.cc index 7edce1f..d38538d 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_inlining.cc @@ -169,7 +169,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->m_source_printing.max_width = 80; + global_dc->get_source_printing_options ().max_width = 80; pass_info.pass = new pass_test_inlining (g); pass_info.reference_pass_name = "*warn_function_noreturn"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_metadata.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_metadata.cc index b86a8b3..f172258 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_metadata.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_metadata.cc @@ -1,5 +1,6 @@ -/* This plugin exercises diagnostic_metadata. */ +/* This plugin exercises diagnostics::metadata. */ +#define INCLUDE_VECTOR #include "gcc-plugin.h" #include "config.h" #include "system.h" @@ -28,7 +29,7 @@ #include "diagnostic.h" #include "context.h" #include "gcc-rich-location.h" -#include "diagnostic-metadata.h" +#include "diagnostics/metadata.h" int plugin_is_GPL_compatible; @@ -89,7 +90,7 @@ check_for_named_call (gimple *stmt, return call; } -/* Exercise diagnostic_metadata. */ +/* Exercise diagnostics::metadata. */ unsigned int pass_test_metadata::execute (function *fun) @@ -106,13 +107,13 @@ pass_test_metadata::execute (function *fun) if (gcall *call = check_for_named_call (stmt, "gets", 1)) { gcc_rich_location richloc (gimple_location (call)); - diagnostic_metadata m; + diagnostics::metadata m; /* CWE-242: Use of Inherently Dangerous Function. */ m.add_cwe (242); - /* Example of a diagnostic_metadata::rule. */ - diagnostic_metadata::precanned_rule + /* Example of a diagnostics::metadata::rule. */ + diagnostics::metadata::precanned_rule test_rule ("STR34-C", "https://example.com/"); m.add_rule (test_rule); diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc index a7963fa..875f4a8 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_paths.cc @@ -6,6 +6,7 @@ specific tests within the compiler's IR. We can't use any real diagnostics for this, so we have to fake it, hence this plugin. */ +#define INCLUDE_VECTOR #include "gcc-plugin.h" #include "config.h" #include "system.h" @@ -32,8 +33,7 @@ #include "intl.h" #include "plugin-version.h" #include "diagnostic.h" -#include "diagnostic-path.h" -#include "diagnostic-metadata.h" +#include "diagnostics/metadata.h" #include "context.h" #include "print-tree.h" #include "gcc-rich-location.h" @@ -223,7 +223,7 @@ class test_diagnostic_path : public simple_diagnostic_path diagnostic_event_id_t add_event_2 (event_location_t evloc, int stack_depth, const char *desc, - diagnostic_thread_id_t thread_id = 0) + diagnostics::paths::thread_id_t thread_id = 0) { gcc_assert (evloc.m_fun); return add_thread_event (thread_id, evloc.m_loc, evloc.m_fun->decl, @@ -232,7 +232,7 @@ class test_diagnostic_path : public simple_diagnostic_path diagnostic_event_id_t add_event_2_with_event_id (event_location_t evloc, int stack_depth, const char *fmt, - diagnostic_thread_id_t thread_id, + diagnostics::paths::thread_id_t thread_id, diagnostic_event_id_t event_id) { gcc_assert (evloc.m_fun); @@ -242,7 +242,7 @@ class test_diagnostic_path : public simple_diagnostic_path } void add_entry (event_location_t evloc, int stack_depth, const char *funcname, - diagnostic_thread_id_t thread_id = 0) + diagnostics::paths::thread_id_t thread_id = 0) { gcc_assert (evloc.m_fun); add_thread_event (thread_id, evloc.m_loc, evloc.m_fun->decl, stack_depth, @@ -363,7 +363,7 @@ example_2 () richloc.set_path (&path); - diagnostic_metadata m; + diagnostics::metadata m; m.add_cwe (415); /* CWE-415: Double Free. */ warning_meta (&richloc, m, 0, @@ -441,7 +441,7 @@ example_3 () richloc.set_path (&path); - diagnostic_metadata m; + diagnostics::metadata m; /* CWE-479: Signal Handler Use of a Non-reentrant Function. */ m.add_cwe (479); @@ -502,8 +502,8 @@ example_4 () gcc_rich_location richloc (call_to_acquire_lock_a_in_bar.m_loc); test_diagnostic_path path (global_dc->get_reference_printer ()); - diagnostic_thread_id_t thread_1 = path.add_thread ("Thread 1"); - diagnostic_thread_id_t thread_2 = path.add_thread ("Thread 2"); + diagnostics::paths::thread_id_t thread_1 = path.add_thread ("Thread 1"); + diagnostics::paths::thread_id_t thread_2 = path.add_thread ("Thread 2"); path.add_entry (entry_to_foo, 0, "foo", thread_1); diagnostic_event_id_t event_a_acquired = path.add_event_2 (call_to_acquire_lock_a_in_foo, 1, @@ -524,7 +524,7 @@ example_4 () thread_2, event_a_acquired); richloc.set_path (&path); - diagnostic_metadata m; + diagnostics::metadata m; warning_meta (&richloc, m, 0, "deadlock due to inconsistent lock acquisition order"); } @@ -559,7 +559,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->m_source_printing.max_width = 80; + global_dc->get_source_printing_options ().max_width = 80; pass_info.pass = make_pass_test_show_path (g); pass_info.reference_pass_name = "whole-program"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc index cd3834b..92839cd 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.cc @@ -62,7 +62,8 @@ #include "print-tree.h" #include "gcc-rich-location.h" #include "text-range-label.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" +#include "diagnostics/file-cache.h" int plugin_is_GPL_compatible; @@ -125,14 +126,14 @@ static bool force_show_locus_color = false; /* We want to verify the colorized output of diagnostic_show_locus, but turning on colorization for everything confuses "dg-warning" etc. Hence we special-case it within this plugin by using this modified - version of default_diagnostic_text_finalizer, which, if "color" is + version of diagnostics::default_text_finalizer, which, if "color" is passed in as a plugin argument turns on colorization, but just for diagnostic_show_locus. */ static void -custom_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic, - diagnostic_t) +custom_diagnostic_text_finalizer (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diag, + enum diagnostics::kind) { pretty_printer *const pp = text_output.get_printer (); bool old_show_color = pp_show_color (pp); @@ -143,7 +144,7 @@ custom_diagnostic_text_finalizer (diagnostic_text_output_format &text_output, pp_newline (pp); diagnostic_show_locus (&text_output.get_context (), text_output.get_source_printing_options (), - diagnostic->richloc, diagnostic->kind, pp); + diag->m_richloc, diag->m_kind, pp); pp_show_color (pp) = old_show_color; pp_set_prefix (pp, saved_prefix); pp_flush (pp); @@ -176,11 +177,11 @@ test_show_locus (function *fun) location_t fnstart = fun->function_start_locus; int fnstart_line = LOCATION_LINE (fnstart); - diagnostic_text_finalizer (global_dc) = custom_diagnostic_text_finalizer; + diagnostics::text_finalizer (global_dc) = custom_diagnostic_text_finalizer; /* Hardcode the "terminal width", to verify the behavior of very wide lines. */ - global_dc->m_source_printing.max_width = 71; + global_dc->get_source_printing_options ().max_width = 71; if (0 == strcmp (fnname, "test_simple")) { @@ -251,7 +252,7 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_very_wide_line")) { const int line = fnstart_line + 2; - global_dc->m_source_printing.show_ruler_p = true; + global_dc->get_source_printing_options ().show_ruler_p = true; text_range_label label0 ("label 0"); text_range_label label1 ("label 1"); rich_location richloc (line_table, @@ -263,7 +264,7 @@ test_show_locus (function *fun) &label1); richloc.add_fixit_replace ("bar * foo"); warning_at (&richloc, 0, "test"); - global_dc->m_source_printing.show_ruler_p = false; + global_dc->get_source_printing_options ().show_ruler_p = false; } /* Likewise, but with a secondary location that's immediately before @@ -271,7 +272,7 @@ test_show_locus (function *fun) if (0 == strcmp (fnname, "test_very_wide_line_2")) { const int line = fnstart_line + 2; - global_dc->m_source_printing.show_ruler_p = true; + global_dc->get_source_printing_options ().show_ruler_p = true; text_range_label label0 ("label 0"); text_range_label label1 ("label 1"); rich_location richloc (line_table, @@ -283,7 +284,7 @@ test_show_locus (function *fun) richloc.add_range (get_loc (line, 34), SHOW_RANGE_WITHOUT_CARET, &label1); warning_at (&richloc, 0, "test"); - global_dc->m_source_printing.show_ruler_p = false; + global_dc->get_source_printing_options ().show_ruler_p = false; } /* Example of multiple carets. */ @@ -294,11 +295,11 @@ test_show_locus (function *fun) location_t caret_b = get_loc (line, 11); rich_location richloc (line_table, caret_a); add_range (&richloc, caret_b, caret_b, SHOW_RANGE_WITH_CARET); - global_dc->m_source_printing.caret_chars[0] = 'A'; - global_dc->m_source_printing.caret_chars[1] = 'B'; + global_dc->get_source_printing_options ().caret_chars[0] = 'A'; + global_dc->get_source_printing_options ().caret_chars[1] = 'B'; warning_at (&richloc, 0, "test"); - global_dc->m_source_printing.caret_chars[0] = '^'; - global_dc->m_source_printing.caret_chars[1] = '^'; + global_dc->get_source_printing_options ().caret_chars[0] = '^'; + global_dc->get_source_printing_options ().caret_chars[1] = '^'; } /* Tests of rendering fixit hints. */ @@ -412,11 +413,11 @@ test_show_locus (function *fun) location_t caret_b = get_loc (line - 1, 19); rich_location richloc (line_table, caret_a); richloc.add_range (caret_b, SHOW_RANGE_WITH_CARET); - global_dc->m_source_printing.caret_chars[0] = '1'; - global_dc->m_source_printing.caret_chars[1] = '2'; + global_dc->get_source_printing_options ().caret_chars[0] = '1'; + global_dc->get_source_printing_options ().caret_chars[1] = '2'; warning_at (&richloc, 0, "test"); - global_dc->m_source_printing.caret_chars[0] = '^'; - global_dc->m_source_printing.caret_chars[1] = '^'; + global_dc->get_source_printing_options ().caret_chars[0] = '^'; + global_dc->get_source_printing_options ().caret_chars[1] = '^'; } /* Example of using the "%q+D" format code, which as well as printing @@ -443,8 +444,8 @@ test_show_locus (function *fun) rich_location richloc (line_table, loc); for (int line = start_line; line <= finish_line; line++) { - file_cache &fc = global_dc->get_file_cache (); - char_span content = fc.get_source_line (file, line); + diagnostics::file_cache &fc = global_dc->get_file_cache (); + diagnostics::char_span content = fc.get_source_line (file, line); gcc_assert (content); /* Split line up into words. */ for (int idx = 0; idx < content.length (); idx++) @@ -464,7 +465,8 @@ test_show_locus (function *fun) richloc.add_range (word, SHOW_RANGE_WITH_CARET, &label); /* Add a fixit, converting to upper case. */ - char_span word_span = content.subspan (start_idx, idx - start_idx); + diagnostics::char_span word_span + = content.subspan (start_idx, idx - start_idx); char *copy = word_span.xstrdup (); for (char *ch = copy; *ch; ch++) *ch = TOUPPER (*ch); diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc index 1b5fad2..b64d60f 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_string_literals.cc @@ -208,7 +208,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->m_source_printing.max_width = 80; + global_dc->get_source_printing_options ().max_width = 80; pass_info.pass = new pass_test_string_literals (g); pass_info.reference_pass_name = "ssa"; diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.cc index e28d697..ce2f1d3 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_text_art.cc @@ -9,7 +9,7 @@ #include "coretypes.h" #include "plugin-version.h" #include "diagnostic.h" -#include "diagnostic-diagram.h" +#include "diagnostics/diagram.h" #include "text-art/canvas.h" #include "text-art/table.h" @@ -22,7 +22,7 @@ using namespace text_art; static void emit_canvas (const canvas &c, const char *alt_text) { - diagnostic_diagram diagram (c, alt_text); + diagnostics::diagram diagram (c, alt_text); global_dc->emit_diagram (diagram); } diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc index fbdb2f8..bbd0faa 100644 --- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc +++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_tree_expression_range.cc @@ -89,7 +89,7 @@ plugin_init (struct plugin_name_args *plugin_info, if (!plugin_default_version_check (version, &gcc_version)) return 1; - global_dc->m_source_printing.max_width = 130; + global_dc->get_source_printing_options ().max_width = 130; register_callback (plugin_name, PLUGIN_PRE_GENERICIZE, diff --git a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc index 7b9b8d4..67722d4 100644 --- a/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/expensive_selftests_plugin.cc @@ -6,9 +6,9 @@ #include "system.h" #include "coretypes.h" #include "diagnostic.h" -#include "edit-context.h" +#include "diagnostics/changes.h" #include "selftest.h" -#include "selftest-diagnostic.h" +#include "diagnostics/selftest-context.h" int plugin_is_GPL_compatible; @@ -47,14 +47,15 @@ static void test_richloc (rich_location *richloc) { /* Run the diagnostic and fix-it printing code. */ - test_diagnostic_context dc; - diagnostic_show_locus (&dc, dc.m_source_printing, - richloc, DK_ERROR, dc.get_reference_printer ()); + diagnostics::selftest::test_context dc; + diagnostic_show_locus (&dc, dc.get_source_printing_options (), + richloc, diagnostics::kind::error, + dc.get_reference_printer ()); /* Generate a diff. */ - edit_context ec (global_dc->get_file_cache ()); - ec.add_fixits (richloc); - char *diff = ec.generate_diff (true); + diagnostics::changes::change_set edit (global_dc->get_file_cache ()); + edit.add_fixits (richloc); + char *diff = edit.generate_diff (true); free (diff); } diff --git a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc index f770d35..00ad870 100644 --- a/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc +++ b/gcc/testsuite/gcc.dg/plugin/location_overflow_plugin.cc @@ -7,7 +7,7 @@ #include "coretypes.h" #include "spellcheck.h" #include "diagnostic.h" -#include "diagnostic-format-text.h" +#include "diagnostics/text-sink.h" int plugin_is_GPL_compatible; @@ -39,12 +39,12 @@ on_pragma_registration (void */*gcc_data*/, void */*user_data*/) /* We add some extra testing during diagnostics by chaining up to the text finalizer. */ -static diagnostic_text_finalizer_fn original_text_finalizer = NULL; +static diagnostics::text_finalizer_fn original_text_finalizer = NULL; static void -verify_unpacked_ranges (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic, - diagnostic_t orig_diag_kind) +verify_unpacked_ranges (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diagnostic, + enum diagnostics::kind orig_diag_kind) { /* Verify that the locations are ad-hoc, not packed. */ location_t loc = diagnostic_location (diagnostic); @@ -56,9 +56,9 @@ verify_unpacked_ranges (diagnostic_text_output_format &text_output, } static void -verify_no_columns (diagnostic_text_output_format &text_output, - const diagnostic_info *diagnostic, - diagnostic_t orig_diag_kind) +verify_no_columns (diagnostics::text_sink &text_output, + const diagnostics::diagnostic_info *diagnostic, + enum diagnostics::kind orig_diag_kind) { /* Verify that the locations have no columns. */ location_t loc = diagnostic_location (diagnostic); @@ -104,15 +104,15 @@ plugin_init (struct plugin_name_args *plugin_info, NULL); /* void *user_data */ /* Hack in additional testing, based on the exact value supplied. */ - original_text_finalizer = diagnostic_text_finalizer (global_dc); + original_text_finalizer = diagnostics::text_finalizer (global_dc); switch (base_location) { case LINE_MAP_MAX_LOCATION_WITH_PACKED_RANGES + 1: - diagnostic_text_finalizer (global_dc) = verify_unpacked_ranges; + diagnostics::text_finalizer (global_dc) = verify_unpacked_ranges; break; case LINE_MAP_MAX_LOCATION_WITH_COLS + 1: - diagnostic_text_finalizer (global_dc) = verify_no_columns; + diagnostics::text_finalizer (global_dc) = verify_no_columns; break; default: diff --git a/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c b/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c index d51d15c..6f65f4a 100644 --- a/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c +++ b/gcc/testsuite/gcc.dg/plugin/must-tail-call-2.c @@ -55,5 +55,5 @@ volatile fn_ptr_t fn_ptr; void test_5 (void) { - fn_ptr (); /* { dg-error "cannot tail-call: " } */ + fn_ptr (); } diff --git a/gcc/testsuite/gcc.dg/plugin/plugin.exp b/gcc/testsuite/gcc.dg/plugin/plugin.exp index d1d7f5d..ce25c0a 100644 --- a/gcc/testsuite/gcc.dg/plugin/plugin.exp +++ b/gcc/testsuite/gcc.dg/plugin/plugin.exp @@ -107,6 +107,10 @@ set plugin_test_list [list \ diagnostic-test-metadata.c \ diagnostic-test-metadata-html.c \ diagnostic-test-metadata-sarif.c } \ + { diagnostic_plugin_test_graphs.cc + diagnostic-test-graphs.c \ + diagnostic-test-graphs-html.c \ + diagnostic-test-graphs-sarif.c } \ { diagnostic_plugin_test_nesting.cc \ diagnostic-test-nesting-text-plain.c \ diagnostic-test-nesting-text-indented.c \ |