aboutsummaryrefslogtreecommitdiff
path: root/gcc/dumpfile.c
diff options
context:
space:
mode:
authorDavid Malcolm <dmalcolm@redhat.com>2018-11-08 15:28:20 +0000
committerDavid Malcolm <dmalcolm@gcc.gnu.org>2018-11-08 15:28:20 +0000
commitd8010ee4560a947f690891f919db177b03581f9a (patch)
treec6bb3ddeba0c95c166a971951e837fb414559832 /gcc/dumpfile.c
parent0d8f74b4cf06835a327aaef69787a4b7d9dc8e66 (diff)
downloadgcc-d8010ee4560a947f690891f919db177b03581f9a.zip
gcc-d8010ee4560a947f690891f919db177b03581f9a.tar.gz
gcc-d8010ee4560a947f690891f919db177b03581f9a.tar.bz2
dump_printf: add "%C" for dumping cgraph_node *
This patch implements support for %C in dump_printf for dumping cgraph_node *. (I would have preferred to have a code for printing symtab_node * and both subclasses, but there doesn't seem to be a good way for -Wformat to handle inheritance, so, failing that, I went with this approach). gcc/c-family/ChangeLog: * c-format.c (local_cgraph_node_ptr_node): New variable. (gcc_dump_printf_char_table): Add entry for %C. (get_pointer_to_named_type): New function, taken from the handling code for "gimple *" from... (init_dynamic_diag_info): ...here. Add handling for "cgraph_node *". * c-format.h (T_CGRAPH_NODE): New. gcc/ChangeLog: * dump-context.h (ASSERT_IS_CGRAPH_NODE): New macro. * dumpfile.c (make_item_for_dump_cgraph_node): Move to before... (dump_pretty_printer::decode_format): Implement "%C" for cgraph_node *. (selftest::test_capture_of_dump_calls): Rename "where" to "stmt_loc". Convert test_decl to a function decl and set its location. Add a symbol_table_test RAII instance and a cgraph_node, using it to test "%C" and dump_symtab_node. gcc/testsuite/ChangeLog: * gcc.dg/format/gcc_diag-10.c (cgraph_node): New typedef. (test_dump): Add testing of %C. From-SVN: r265918
Diffstat (limited to 'gcc/dumpfile.c')
-rw-r--r--gcc/dumpfile.c115
1 files changed, 86 insertions, 29 deletions
diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index 0b140ff..09c2490 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -748,6 +748,18 @@ dump_context::dump_generic_expr_loc (dump_flags_t dump_kind,
dump_generic_expr (dump_kind, extra_dump_flags, t);
}
+/* Make an item for the given dump call. */
+
+static optinfo_item *
+make_item_for_dump_symtab_node (symtab_node *node)
+{
+ location_t loc = DECL_SOURCE_LOCATION (node->decl);
+ optinfo_item *item
+ = new optinfo_item (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc,
+ xstrdup (node->dump_name ()));
+ return item;
+}
+
/* dump_pretty_printer's ctor. */
dump_pretty_printer::dump_pretty_printer (dump_context *context,
@@ -881,6 +893,8 @@ dump_pretty_printer::format_decoder_cb (pretty_printer *pp, text_info *text,
Supported format codes (in addition to the standard pretty_printer ones)
are:
+ %C: cgraph_node *:
+ Equivalent to: dump_symtab_node (MSG_*, node)
%E: gimple *:
Equivalent to: dump_gimple_expr (MSG_*, TDF_SLIM, stmt, 0)
%G: gimple *:
@@ -888,7 +902,9 @@ dump_pretty_printer::format_decoder_cb (pretty_printer *pp, text_info *text,
%T: tree:
Equivalent to: dump_generic_expr (MSG_*, arg, TDF_SLIM).
- FIXME: add symtab_node?
+ TODO: add a format code that can handle (symtab_node*) *and* both
+ subclasses (presumably means teaching -Wformat about non-virtual
+ subclasses).
These format codes build optinfo_item instances, thus capturing metadata
about the arguments being dumped, as well as the textual output. */
@@ -901,6 +917,16 @@ dump_pretty_printer::decode_format (text_info *text, const char *spec,
for later use (to capture metadata, rather than plain text). */
switch (*spec)
{
+ case 'C':
+ {
+ cgraph_node *node = va_arg (*text->args_ptr, cgraph_node *);
+
+ /* Make an item for the node, and stash it. */
+ optinfo_item *item = make_item_for_dump_symtab_node (node);
+ stash_item (buffer_ptr, item);
+ return true;
+ }
+
case 'E':
{
gimple *stmt = va_arg (*text->args_ptr, gimple *);
@@ -1023,18 +1049,6 @@ dump_context::dump_dec (dump_flags_t dump_kind, const poly_int<N, C> &value)
delete item;
}
-/* Make an item for the given dump call. */
-
-static optinfo_item *
-make_item_for_dump_symtab_node (symtab_node *node)
-{
- location_t loc = DECL_SOURCE_LOCATION (node->decl);
- optinfo_item *item
- = new optinfo_item (OPTINFO_ITEM_KIND_SYMTAB_NODE, loc,
- xstrdup (node->dump_name ()));
- return item;
-}
-
/* Output the name of NODE on appropriate dump streams. */
void
@@ -2067,18 +2081,26 @@ test_capture_of_dump_calls (const line_table_case &case_)
linemap_add (line_table, LC_ENTER, false, "test.txt", 0);
linemap_line_start (line_table, 5, 100);
linemap_add (line_table, LC_LEAVE, false, NULL, 0);
- location_t where = linemap_position_for_column (line_table, 10);
- if (where > LINE_MAP_MAX_LOCATION_WITH_COLS)
+ location_t decl_loc = linemap_position_for_column (line_table, 8);
+ location_t stmt_loc = linemap_position_for_column (line_table, 10);
+ if (stmt_loc > LINE_MAP_MAX_LOCATION_WITH_COLS)
return;
- dump_location_t loc = dump_location_t::from_location_t (where);
+ dump_location_t loc = dump_location_t::from_location_t (stmt_loc);
gimple *stmt = gimple_build_return (NULL);
- gimple_set_location (stmt, where);
+ gimple_set_location (stmt, stmt_loc);
- tree test_decl = build_decl (UNKNOWN_LOCATION, VAR_DECL,
+ tree test_decl = build_decl (decl_loc, FUNCTION_DECL,
get_identifier ("test_decl"),
- integer_type_node);
+ build_function_type_list (void_type_node,
+ NULL_TREE));
+
+ symbol_table_test tmp_symtab;
+
+ cgraph_node *node = cgraph_node::get_create (test_decl);
+ gcc_assert (node);
+
/* Run all tests twice, with and then without optinfo enabled, to ensure
that immediate destinations vs optinfo-based destinations both
work, independently of each other, with no leaks. */
@@ -2135,7 +2157,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
ASSERT_EQ (info->num_items (), 2);
ASSERT_IS_TEXT (info->get_item (0), "gimple: ");
- ASSERT_IS_GIMPLE (info->get_item (1), where, "return;");
+ ASSERT_IS_GIMPLE (info->get_item (1), stmt_loc, "return;");
}
}
@@ -2153,7 +2175,25 @@ test_capture_of_dump_calls (const line_table_case &case_)
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
ASSERT_EQ (info->num_items (), 2);
ASSERT_IS_TEXT (info->get_item (0), "gimple: ");
- ASSERT_IS_GIMPLE (info->get_item (1), where, "return;\n");
+ ASSERT_IS_GIMPLE (info->get_item (1), stmt_loc, "return;\n");
+ }
+ }
+
+ /* Test of dump_printf with %C. */
+ {
+ temp_dump_context tmp (with_optinfo, true,
+ MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
+ dump_printf (MSG_NOTE, "node: %C", node);
+
+ ASSERT_DUMPED_TEXT_EQ (tmp, "node: test_decl/0");
+ if (with_optinfo)
+ {
+ optinfo *info = tmp.get_pending_optinfo ();
+ ASSERT_TRUE (info != NULL);
+ ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
+ ASSERT_EQ (info->num_items (), 2);
+ ASSERT_IS_TEXT (info->get_item (0), "node: ");
+ ASSERT_IS_SYMTAB_NODE (info->get_item (1), decl_loc, "test_decl/0");
}
}
@@ -2184,8 +2224,8 @@ test_capture_of_dump_calls (const line_table_case &case_)
ASSERT_IS_TEXT (info->get_item (2), " and ");
ASSERT_IS_TREE (info->get_item (3), UNKNOWN_LOCATION, "test_decl");
ASSERT_IS_TEXT (info->get_item (4), " 42 consecutive ");
- ASSERT_IS_GIMPLE (info->get_item (5), where, "return;");
- ASSERT_IS_GIMPLE (info->get_item (6), where, "return;");
+ ASSERT_IS_GIMPLE (info->get_item (5), stmt_loc, "return;");
+ ASSERT_IS_GIMPLE (info->get_item (6), stmt_loc, "return;");
ASSERT_IS_TEXT (info->get_item (7), " after\n");
}
}
@@ -2202,7 +2242,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
{
optinfo *info = tmp.get_pending_optinfo ();
ASSERT_TRUE (info != NULL);
- ASSERT_EQ (info->get_location_t (), where);
+ ASSERT_EQ (info->get_location_t (), stmt_loc);
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
ASSERT_EQ (info->num_items (), 2);
ASSERT_IS_TEXT (info->get_item (0), "test of tree: ");
@@ -2221,7 +2261,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
{
optinfo *info = tmp.get_pending_optinfo ();
ASSERT_TRUE (info != NULL);
- ASSERT_EQ (info->get_location_t (), where);
+ ASSERT_EQ (info->get_location_t (), stmt_loc);
ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
ASSERT_EQ (info->num_items (), 1);
ASSERT_IS_TREE (info->get_item (0), UNKNOWN_LOCATION, "1");
@@ -2242,7 +2282,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
optinfo *info = tmp.get_pending_optinfo ();
ASSERT_TRUE (info != NULL);
ASSERT_EQ (info->num_items (), 1);
- ASSERT_IS_GIMPLE (info->get_item (0), where, "return;\n");
+ ASSERT_IS_GIMPLE (info->get_item (0), stmt_loc, "return;\n");
}
}
@@ -2258,7 +2298,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
optinfo *info = tmp.get_pending_optinfo ();
ASSERT_TRUE (info != NULL);
ASSERT_EQ (info->num_items (), 1);
- ASSERT_IS_GIMPLE (info->get_item (0), where, "return;\n");
+ ASSERT_IS_GIMPLE (info->get_item (0), stmt_loc, "return;\n");
}
}
@@ -2274,7 +2314,7 @@ test_capture_of_dump_calls (const line_table_case &case_)
optinfo *info = tmp.get_pending_optinfo ();
ASSERT_TRUE (info != NULL);
ASSERT_EQ (info->num_items (), 1);
- ASSERT_IS_GIMPLE (info->get_item (0), where, "return;");
+ ASSERT_IS_GIMPLE (info->get_item (0), stmt_loc, "return;");
}
}
@@ -2290,11 +2330,28 @@ test_capture_of_dump_calls (const line_table_case &case_)
optinfo *info = tmp.get_pending_optinfo ();
ASSERT_TRUE (info != NULL);
ASSERT_EQ (info->num_items (), 1);
- ASSERT_IS_GIMPLE (info->get_item (0), where, "return;");
+ ASSERT_IS_GIMPLE (info->get_item (0), stmt_loc, "return;");
}
}
}
+ /* symtab_node. */
+ {
+ temp_dump_context tmp (with_optinfo, true,
+ MSG_ALL_KINDS | MSG_PRIORITY_USER_FACING);
+ dump_symtab_node (MSG_NOTE, node);
+
+ ASSERT_DUMPED_TEXT_EQ (tmp, "test_decl/0");
+ if (with_optinfo)
+ {
+ optinfo *info = tmp.get_pending_optinfo ();
+ ASSERT_TRUE (info != NULL);
+ ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
+ ASSERT_EQ (info->num_items (), 1);
+ ASSERT_IS_SYMTAB_NODE (info->get_item (0), decl_loc, "test_decl/0");
+ }
+ }
+
/* poly_int. */
{
temp_dump_context tmp (with_optinfo, true,