bool dumps_are_enabled = false;
-/* Update the "dumps_are_enabled" global; to be called whenever dump_file
- or alt_dump_file change. */
-
-static void
-refresh_dumps_are_enabled ()
-{
- dumps_are_enabled = (dump_file || alt_dump_file || optinfo_enabled_p ());
-}
-
/* Set global "dump_file" to NEW_DUMP_FILE, refreshing the "dumps_are_enabled"
global. */
{
dumpfile_ensure_any_optinfo_are_flushed ();
dump_file = new_dump_file;
- refresh_dumps_are_enabled ();
+ dump_context::get ().refresh_dumps_are_enabled ();
}
/* Set "alt_dump_file" to NEW_ALT_DUMP_FILE, refreshing the "dumps_are_enabled"
{
dumpfile_ensure_any_optinfo_are_flushed ();
alt_dump_file = new_alt_dump_file;
- refresh_dumps_are_enabled ();
+ dump_context::get ().refresh_dumps_are_enabled ();
}
#define DUMP_FILE_INFO(suffix, swtch, dkind, num) \
}
}
+/* Print source location to PP if enabled. */
+
+static void
+dump_loc (dump_flags_t dump_kind, pretty_printer *pp, source_location loc)
+{
+ if (dump_kind)
+ {
+ if (LOCATION_LOCUS (loc) > BUILTINS_LOCATION)
+ pp_printf (pp, "%s:%d:%d: note: ", LOCATION_FILE (loc),
+ LOCATION_LINE (loc), LOCATION_COLUMN (loc));
+ else if (current_function_decl)
+ pp_printf (pp, "%s:%d:%d: note: ",
+ DECL_SOURCE_FILE (current_function_decl),
+ DECL_SOURCE_LINE (current_function_decl),
+ DECL_SOURCE_COLUMN (current_function_decl));
+ /* Indentation based on scope depth. */
+ for (unsigned i = 0; i < get_dump_scope_depth (); i++)
+ pp_character (pp, ' ');
+ }
+}
+
/* Implementation of dump_context member functions. */
/* dump_context's dtor. */
delete m_pending;
}
+/* Update the "dumps_are_enabled" global; to be called whenever dump_file
+ or alt_dump_file change, or when changing dump_context in selftests. */
+
+void
+dump_context::refresh_dumps_are_enabled ()
+{
+ dumps_are_enabled = (dump_file || alt_dump_file || optinfo_enabled_p ()
+ || m_test_pp);
+}
+
/* Print LOC to the appropriate dump destinations, given DUMP_KIND.
If optinfos are enabled, begin a new optinfo. */
void
dump_context::dump_loc (dump_flags_t dump_kind, const dump_location_t &loc)
{
+ end_any_optinfo ();
+
location_t srcloc = loc.get_location_t ();
if (dump_file && (dump_kind & pflags))
if (alt_dump_file && (dump_kind & alt_flags))
::dump_loc (dump_kind, alt_dump_file, srcloc);
+ /* Support for temp_dump_context in selftests. */
+ if (m_test_pp && (dump_kind & m_test_pp_flags))
+ ::dump_loc (dump_kind, m_test_pp, srcloc);
+
if (optinfo_enabled_p ())
{
optinfo &info = begin_next_optinfo (loc);
}
}
+/* Make an item for the given dump call, equivalent to print_gimple_stmt. */
+
+static optinfo_item *
+make_item_for_dump_gimple_stmt (gimple *stmt, int spc, dump_flags_t dump_flags)
+{
+ pretty_printer pp;
+ pp_needs_newline (&pp) = true;
+ pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
+ pp_newline (&pp);
+
+ optinfo_item *item
+ = new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
+ xstrdup (pp_formatted_text (&pp)));
+ return item;
+}
+
/* Dump gimple statement GS with SPC indentation spaces and
EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled. */
dump_flags_t extra_dump_flags,
gimple *gs, int spc)
{
- if (dump_file && (dump_kind & pflags))
- print_gimple_stmt (dump_file, gs, spc, dump_flags | extra_dump_flags);
-
- if (alt_dump_file && (dump_kind & alt_flags))
- print_gimple_stmt (alt_dump_file, gs, spc, dump_flags | extra_dump_flags);
+ optinfo_item *item
+ = make_item_for_dump_gimple_stmt (gs, spc, dump_flags | extra_dump_flags);
+ emit_item (item, dump_kind);
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo ();
info.handle_dump_file_kind (dump_kind);
- info.add_gimple_stmt (gs, spc, dump_flags | extra_dump_flags);
+ info.add_item (item);
}
+ else
+ delete item;
}
/* Similar to dump_gimple_stmt, except additionally print source location. */
dump_gimple_stmt (dump_kind, extra_dump_flags, gs, spc);
}
+/* Make an item for the given dump call, equivalent to print_gimple_expr. */
+
+static optinfo_item *
+make_item_for_dump_gimple_expr (gimple *stmt, int spc, dump_flags_t dump_flags)
+{
+ dump_flags |= TDF_RHS_ONLY;
+ pretty_printer pp;
+ pp_needs_newline (&pp) = true;
+ pp_gimple_stmt_1 (&pp, stmt, spc, dump_flags);
+
+ optinfo_item *item
+ = new optinfo_item (OPTINFO_ITEM_KIND_GIMPLE, gimple_location (stmt),
+ xstrdup (pp_formatted_text (&pp)));
+ return item;
+}
+
/* Dump gimple statement GS with SPC indentation spaces and
EXTRA_DUMP_FLAGS on the dump streams if DUMP_KIND is enabled.
Do not terminate with a newline or semicolon. */
dump_flags_t extra_dump_flags,
gimple *gs, int spc)
{
- if (dump_file && (dump_kind & pflags))
- print_gimple_expr (dump_file, gs, spc, dump_flags | extra_dump_flags);
-
- if (alt_dump_file && (dump_kind & alt_flags))
- print_gimple_expr (alt_dump_file, gs, spc, dump_flags | extra_dump_flags);
+ optinfo_item *item
+ = make_item_for_dump_gimple_expr (gs, spc, dump_flags | extra_dump_flags);
+ emit_item (item, dump_kind);
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo ();
info.handle_dump_file_kind (dump_kind);
- info.add_gimple_expr (gs, spc, dump_flags | extra_dump_flags);
+ info.add_item (item);
}
+ else
+ delete item;
}
/* Similar to dump_gimple_expr, except additionally print source location. */
dump_gimple_expr (dump_kind, extra_dump_flags, gs, spc);
}
+/* Make an item for the given dump call, equivalent to print_generic_expr. */
+
+static optinfo_item *
+make_item_for_dump_generic_expr (tree node, dump_flags_t dump_flags)
+{
+ pretty_printer pp;
+ pp_needs_newline (&pp) = true;
+ pp_translate_identifiers (&pp) = false;
+ dump_generic_node (&pp, node, 0, dump_flags, false);
+
+ location_t loc = UNKNOWN_LOCATION;
+ if (EXPR_HAS_LOCATION (node))
+ loc = EXPR_LOCATION (node);
+
+ optinfo_item *item
+ = new optinfo_item (OPTINFO_ITEM_KIND_TREE, loc,
+ xstrdup (pp_formatted_text (&pp)));
+ return item;
+}
/* Dump expression tree T using EXTRA_DUMP_FLAGS on dump streams if
DUMP_KIND is enabled. */
dump_flags_t extra_dump_flags,
tree t)
{
- if (dump_file && (dump_kind & pflags))
- print_generic_expr (dump_file, t, dump_flags | extra_dump_flags);
-
- if (alt_dump_file && (dump_kind & alt_flags))
- print_generic_expr (alt_dump_file, t, dump_flags | extra_dump_flags);
+ optinfo_item *item
+ = make_item_for_dump_generic_expr (t, dump_flags | extra_dump_flags);
+ emit_item (item, dump_kind);
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo ();
info.handle_dump_file_kind (dump_kind);
- info.add_tree (t, dump_flags | extra_dump_flags);
+ info.add_item (item);
}
+ else
+ delete item;
}
dump_generic_expr (dump_kind, extra_dump_flags, t);
}
+/* Make an item for the given dump call. */
+
+static optinfo_item *
+make_item_for_dump_printf_va (const char *format, va_list ap)
+ ATTRIBUTE_PRINTF (1, 0);
+
+static optinfo_item *
+make_item_for_dump_printf_va (const char *format, va_list ap)
+{
+ char *formatted_text = xvasprintf (format, ap);
+ optinfo_item *item
+ = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
+ formatted_text);
+ return item;
+}
+
+/* Make an item for the given dump call. */
+
+static optinfo_item *
+make_item_for_dump_printf (const char *format, ...)
+ ATTRIBUTE_PRINTF (1, 2);
+
+static optinfo_item *
+make_item_for_dump_printf (const char *format, ...)
+{
+ va_list ap;
+ va_start (ap, format);
+ optinfo_item *item
+ = make_item_for_dump_printf_va (format, ap);
+ va_end (ap);
+ return item;
+}
+
/* Output a formatted message using FORMAT on appropriate dump streams. */
void
dump_context::dump_printf_va (dump_flags_t dump_kind, const char *format,
va_list ap)
{
- if (dump_file && (dump_kind & pflags))
- {
- va_list aq;
- va_copy (aq, ap);
- vfprintf (dump_file, format, aq);
- va_end (aq);
- }
-
- if (alt_dump_file && (dump_kind & alt_flags))
- {
- va_list aq;
- va_copy (aq, ap);
- vfprintf (alt_dump_file, format, aq);
- va_end (aq);
- }
+ optinfo_item *item = make_item_for_dump_printf_va (format, ap);
+ emit_item (item, dump_kind);
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo ();
- va_list aq;
- va_copy (aq, ap);
- info.add_printf_va (format, aq);
- va_end (aq);
+ info.handle_dump_file_kind (dump_kind);
+ info.add_item (item);
}
+ else
+ delete item;
}
/* Similar to dump_printf, except source location is also printed, and
dump_printf_va (dump_kind, format, ap);
}
-/* Output VALUE in decimal to appropriate dump streams. */
+/* Make an item for the given dump call, equivalent to print_dec. */
template<unsigned int N, typename C>
-void
-dump_context::dump_dec (dump_flags_t dump_kind, const poly_int<N, C> &value)
+static optinfo_item *
+make_item_for_dump_dec (const poly_int<N, C> &value)
{
STATIC_ASSERT (poly_coeff_traits<C>::signedness >= 0);
signop sgn = poly_coeff_traits<C>::signedness ? SIGNED : UNSIGNED;
- if (dump_file && (dump_kind & pflags))
- print_dec (value, dump_file, sgn);
- if (alt_dump_file && (dump_kind & alt_flags))
- print_dec (value, alt_dump_file, sgn);
+ pretty_printer pp;
+
+ if (value.is_constant ())
+ pp_wide_int (&pp, value.coeffs[0], sgn);
+ else
+ {
+ pp_character (&pp, '[');
+ for (unsigned int i = 0; i < N; ++i)
+ {
+ pp_wide_int (&pp, value.coeffs[i], sgn);
+ pp_character (&pp, i == N - 1 ? ']' : ',');
+ }
+ }
+
+ optinfo_item *item
+ = new optinfo_item (OPTINFO_ITEM_KIND_TEXT, UNKNOWN_LOCATION,
+ xstrdup (pp_formatted_text (&pp)));
+ return item;
+}
+
+/* Output VALUE in decimal to appropriate dump streams. */
+
+template<unsigned int N, typename C>
+void
+dump_context::dump_dec (dump_flags_t dump_kind, const poly_int<N, C> &value)
+{
+ optinfo_item *item = make_item_for_dump_dec (value);
+ emit_item (item, dump_kind);
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo ();
info.handle_dump_file_kind (dump_kind);
- info.add_poly_int<N,C> (value);
+ info.add_item (item);
}
+ else
+ 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
dump_context::dump_symtab_node (dump_flags_t dump_kind, symtab_node *node)
{
- if (dump_file && (dump_kind & pflags))
- fprintf (dump_file, "%s", node->dump_name ());
-
- if (alt_dump_file && (dump_kind & alt_flags))
- fprintf (alt_dump_file, "%s", node->dump_name ());
+ optinfo_item *item = make_item_for_dump_symtab_node (node);
+ emit_item (item, dump_kind);
if (optinfo_enabled_p ())
{
optinfo &info = ensure_pending_optinfo ();
info.handle_dump_file_kind (dump_kind);
- info.add_symtab_node (node);
+ info.add_item (item);
}
+ else
+ delete item;
}
/* Get the current dump scope-nesting depth.
void
dump_context::begin_scope (const char *name, const dump_location_t &loc)
{
- /* Specialcase, to avoid going through dump_printf_loc,
- so that we can create a optinfo of kind OPTINFO_KIND_SCOPE. */
-
if (dump_file)
- {
- ::dump_loc (MSG_NOTE, dump_file, loc.get_location_t ());
- fprintf (dump_file, "=== %s ===\n", name);
- }
+ ::dump_loc (MSG_NOTE, dump_file, loc.get_location_t ());
if (alt_dump_file)
- {
- ::dump_loc (MSG_NOTE, alt_dump_file, loc.get_location_t ());
- fprintf (alt_dump_file, "=== %s ===\n", name);
- }
+ ::dump_loc (MSG_NOTE, alt_dump_file, loc.get_location_t ());
+
+ /* Support for temp_dump_context in selftests. */
+ if (m_test_pp)
+ ::dump_loc (MSG_NOTE, m_test_pp, loc.get_location_t ());
+
+ optinfo_item *item = make_item_for_dump_printf ("=== %s ===\n", name);
+ emit_item (item, MSG_NOTE);
if (optinfo_enabled_p ())
{
+ optinfo &info = begin_next_optinfo (loc);
+ info.m_kind = OPTINFO_KIND_SCOPE;
+ info.add_item (item);
end_any_optinfo ();
- optinfo info (loc, OPTINFO_KIND_SCOPE, current_pass);
- info.add_printf ("=== %s ===", name);
- info.emit ();
}
+ else
+ delete item;
m_scope_depth++;
}
m_pending = NULL;
}
+/* Emit ITEM to all item destinations (those that don't require
+ consolidation into optinfo instances). */
+
+void
+dump_context::emit_item (optinfo_item *item, dump_flags_t dump_kind)
+{
+ if (dump_file && (dump_kind & pflags))
+ fprintf (dump_file, "%s", item->get_text ());
+
+ if (alt_dump_file && (dump_kind & alt_flags))
+ fprintf (alt_dump_file, "%s", item->get_text ());
+
+ /* Support for temp_dump_context in selftests. */
+ if (m_test_pp && (dump_kind & m_test_pp_flags))
+ pp_string (m_test_pp, item->get_text ());
+}
+
/* The current singleton dump_context, and its default. */
dump_context *dump_context::s_current = &dump_context::s_default;
/* temp_dump_context's ctor. Temporarily override the dump_context
(to forcibly enable optinfo-generation). */
-temp_dump_context::temp_dump_context (bool forcibly_enable_optinfo)
+temp_dump_context::temp_dump_context (bool forcibly_enable_optinfo,
+ dump_flags_t test_pp_flags)
+
: m_context (),
m_saved (&dump_context ().get ())
{
dump_context::s_current = &m_context;
m_context.m_forcibly_enable_optinfo = forcibly_enable_optinfo;
+ m_context.m_test_pp = &m_pp;
+ m_context.m_test_pp_flags = test_pp_flags;
+
+ dump_context::get ().refresh_dumps_are_enabled ();
}
/* temp_dump_context's dtor. Restore the saved dump_context. */
temp_dump_context::~temp_dump_context ()
{
dump_context::s_current = m_saved;
+
+ dump_context::get ().refresh_dumps_are_enabled ();
+}
+
+/* 0-terminate the text dumped so far, and return it. */
+
+const char *
+temp_dump_context::get_dumped_text ()
+{
+ return pp_formatted_text (&m_pp);
}
namespace selftest {
#endif
}
+/* Verify that the text dumped so far in CONTEXT equals
+ EXPECTED_TEXT, using LOC for the location of any failure.
+ As a side-effect, the internal buffer is 0-terminated. */
+
+static void
+verify_dumped_text (const location &loc,
+ temp_dump_context *context,
+ const char *expected_text)
+{
+ gcc_assert (context);
+ ASSERT_STREQ_AT (loc, context->get_dumped_text (),
+ expected_text);
+}
+
+/* Verify that the text dumped so far in CONTEXT equals
+ EXPECTED_TEXT.
+ As a side-effect, the internal buffer is 0-terminated. */
+
+#define ASSERT_DUMPED_TEXT_EQ(CONTEXT, EXPECTED_TEXT) \
+ SELFTEST_BEGIN_STMT \
+ verify_dumped_text (SELFTEST_LOCATION, &(CONTEXT), (EXPECTED_TEXT)); \
+ SELFTEST_END_STMT
+
/* Verify that ITEM has the expected values. */
static void
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)
+ return;
dump_location_t loc = dump_location_t::from_location_t (where);
- /* Test of dump_printf. */
- {
- temp_dump_context tmp (true);
- dump_printf (MSG_NOTE, "int: %i str: %s", 42, "foo");
-
- 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_TEXT (info->get_item (0), "int: 42 str: foo");
- }
-
- /* Tree, via dump_generic_expr. */
- {
- temp_dump_context tmp (true);
- dump_printf_loc (MSG_NOTE, loc, "test of tree: ");
- dump_generic_expr (MSG_NOTE, TDF_SLIM, integer_zero_node);
-
- optinfo *info = tmp.get_pending_optinfo ();
- ASSERT_TRUE (info != NULL);
- ASSERT_EQ (info->get_location_t (), where);
- ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
- ASSERT_EQ (info->num_items (), 2);
- ASSERT_IS_TEXT (info->get_item (0), "test of tree: ");
- ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0");
- }
-
- /* Tree, via dump_generic_expr_loc. */
- {
- temp_dump_context tmp (true);
- dump_generic_expr_loc (MSG_NOTE, loc, TDF_SLIM, integer_one_node);
-
- optinfo *info = tmp.get_pending_optinfo ();
- ASSERT_TRUE (info != NULL);
- ASSERT_EQ (info->get_location_t (), where);
- ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
- ASSERT_EQ (info->num_items (), 1);
- ASSERT_IS_TREE (info->get_item (0), UNKNOWN_LOCATION, "1");
- }
-
- /* Gimple. */
- {
- greturn *stmt = gimple_build_return (NULL);
- gimple_set_location (stmt, where);
-
- /* dump_gimple_stmt_loc. */
- {
- temp_dump_context tmp (true);
- dump_gimple_stmt_loc (MSG_NOTE, loc, TDF_SLIM, stmt, 2);
-
- 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");
- }
-
- /* dump_gimple_stmt. */
- {
- temp_dump_context tmp (true);
- dump_gimple_stmt (MSG_NOTE, TDF_SLIM, stmt, 2);
+ greturn *stmt = gimple_build_return (NULL);
+ gimple_set_location (stmt, where);
- 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");
- }
-
- /* dump_gimple_expr_loc. */
+ /* 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. */
+ for (int i = 0 ; i < 2; i++)
{
- temp_dump_context tmp (true);
- dump_gimple_expr_loc (MSG_NOTE, loc, TDF_SLIM, stmt, 2);
+ bool with_optinfo = (i == 0);
+
+ /* Test of dump_printf. */
+ {
+ temp_dump_context tmp (with_optinfo, MSG_ALL);
+ dump_printf (MSG_NOTE, "int: %i str: %s", 42, "foo");
+
+ ASSERT_DUMPED_TEXT_EQ (tmp, "int: 42 str: foo");
+ 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_TEXT (info->get_item (0), "int: 42 str: foo");
+ }
+ }
+
+ /* Tree, via dump_generic_expr. */
+ {
+ temp_dump_context tmp (with_optinfo, MSG_ALL);
+ dump_printf_loc (MSG_NOTE, loc, "test of tree: ");
+ dump_generic_expr (MSG_NOTE, TDF_SLIM, integer_zero_node);
+
+ ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: test of tree: 0");
+ if (with_optinfo)
+ {
+ optinfo *info = tmp.get_pending_optinfo ();
+ ASSERT_TRUE (info != NULL);
+ ASSERT_EQ (info->get_location_t (), where);
+ ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
+ ASSERT_EQ (info->num_items (), 2);
+ ASSERT_IS_TEXT (info->get_item (0), "test of tree: ");
+ ASSERT_IS_TREE (info->get_item (1), UNKNOWN_LOCATION, "0");
+ }
+ }
+
+ /* Tree, via dump_generic_expr_loc. */
+ {
+ temp_dump_context tmp (with_optinfo, MSG_ALL);
+ dump_generic_expr_loc (MSG_NOTE, loc, TDF_SLIM, integer_one_node);
+
+ ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: 1");
+ if (with_optinfo)
+ {
+ optinfo *info = tmp.get_pending_optinfo ();
+ ASSERT_TRUE (info != NULL);
+ ASSERT_EQ (info->get_location_t (), where);
+ ASSERT_EQ (info->get_kind (), OPTINFO_KIND_NOTE);
+ ASSERT_EQ (info->num_items (), 1);
+ ASSERT_IS_TREE (info->get_item (0), UNKNOWN_LOCATION, "1");
+ }
+ }
+
+ /* Gimple. */
+ {
+ /* dump_gimple_stmt_loc. */
+ {
+ temp_dump_context tmp (with_optinfo, MSG_ALL);
+ dump_gimple_stmt_loc (MSG_NOTE, loc, TDF_SLIM, stmt, 2);
+
+ ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: return;\n");
+ if (with_optinfo)
+ {
+ 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");
+ }
+ }
- 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;");
- }
+ /* dump_gimple_stmt. */
+ {
+ temp_dump_context tmp (with_optinfo, MSG_ALL);
+ dump_gimple_stmt (MSG_NOTE, TDF_SLIM, stmt, 2);
+
+ ASSERT_DUMPED_TEXT_EQ (tmp, "return;\n");
+ if (with_optinfo)
+ {
+ 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");
+ }
+ }
- /* dump_gimple_expr. */
- {
- temp_dump_context tmp (true);
- dump_gimple_expr (MSG_NOTE, TDF_SLIM, stmt, 2);
+ /* dump_gimple_expr_loc. */
+ {
+ temp_dump_context tmp (with_optinfo, MSG_ALL);
+ dump_gimple_expr_loc (MSG_NOTE, loc, TDF_SLIM, stmt, 2);
+
+ ASSERT_DUMPED_TEXT_EQ (tmp, "test.txt:5:10: note: return;");
+ if (with_optinfo)
+ {
+ 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;");
+ }
+ }
- 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;");
+ /* dump_gimple_expr. */
+ {
+ temp_dump_context tmp (with_optinfo, MSG_ALL);
+ dump_gimple_expr (MSG_NOTE, TDF_SLIM, stmt, 2);
+
+ ASSERT_DUMPED_TEXT_EQ (tmp, "return;");
+ if (with_optinfo)
+ {
+ 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;");
+ }
+ }
+ }
+
+ /* poly_int. */
+ {
+ temp_dump_context tmp (with_optinfo, MSG_ALL);
+ dump_dec (MSG_NOTE, poly_int64 (42));
+
+ ASSERT_DUMPED_TEXT_EQ (tmp, "42");
+ if (with_optinfo)
+ {
+ optinfo *info = tmp.get_pending_optinfo ();
+ ASSERT_TRUE (info != NULL);
+ ASSERT_EQ (info->num_items (), 1);
+ ASSERT_IS_TEXT (info->get_item (0), "42");
+ }
+ }
+
+ /* scopes. */
+ {
+ temp_dump_context tmp (with_optinfo, MSG_ALL);
+ dump_printf_loc (MSG_NOTE, stmt, "msg 1\n");
+ {
+ AUTO_DUMP_SCOPE ("outer scope", stmt);
+ dump_printf_loc (MSG_NOTE, stmt, "msg 2\n");
+ {
+ AUTO_DUMP_SCOPE ("middle scope", stmt);
+ dump_printf_loc (MSG_NOTE, stmt, "msg 3\n");
+ {
+ AUTO_DUMP_SCOPE ("inner scope", stmt);
+ dump_printf_loc (MSG_NOTE, stmt, "msg 4\n");
+ }
+ dump_printf_loc (MSG_NOTE, stmt, "msg 5\n");
+ }
+ dump_printf_loc (MSG_NOTE, stmt, "msg 6\n");
+ }
+ dump_printf_loc (MSG_NOTE, stmt, "msg 7\n");
+
+ ASSERT_DUMPED_TEXT_EQ (tmp,
+ "test.txt:5:10: note: msg 1\n"
+ "test.txt:5:10: note: === outer scope ===\n"
+ "test.txt:5:10: note: msg 2\n"
+ "test.txt:5:10: note: === middle scope ===\n"
+ "test.txt:5:10: note: msg 3\n"
+ "test.txt:5:10: note: === inner scope ===\n"
+ "test.txt:5:10: note: msg 4\n"
+ "test.txt:5:10: note: msg 5\n"
+ "test.txt:5:10: note: msg 6\n"
+ "test.txt:5:10: note: msg 7\n");
+ if (with_optinfo)
+ {
+ optinfo *info = tmp.get_pending_optinfo ();
+ ASSERT_TRUE (info != NULL);
+ ASSERT_EQ (info->num_items (), 1);
+ ASSERT_IS_TEXT (info->get_item (0), "msg 7\n");
+ }
+ }
}
- }
-
- /* poly_int. */
- {
- temp_dump_context tmp (true);
- dump_dec (MSG_NOTE, poly_int64 (42));
-
- optinfo *info = tmp.get_pending_optinfo ();
- ASSERT_TRUE (info != NULL);
- ASSERT_EQ (info->num_items (), 1);
- ASSERT_IS_TEXT (info->get_item (0), "42");
- }
/* Verify that MSG_* affects optinfo->get_kind (); we tested MSG_NOTE
above. */
{
/* MSG_OPTIMIZED_LOCATIONS. */
{
- temp_dump_context tmp (true);
+ temp_dump_context tmp (true, MSG_ALL);
dump_printf_loc (MSG_OPTIMIZED_LOCATIONS, loc, "test");
ASSERT_EQ (tmp.get_pending_optinfo ()->get_kind (),
OPTINFO_KIND_SUCCESS);
/* MSG_MISSED_OPTIMIZATION. */
{
- temp_dump_context tmp (true);
+ temp_dump_context tmp (true, MSG_ALL);
dump_printf_loc (MSG_MISSED_OPTIMIZATION, loc, "test");
ASSERT_EQ (tmp.get_pending_optinfo ()->get_kind (),
OPTINFO_KIND_FAILURE);