diff mbox series

dumpfile.c: fix stray dump_loc output (PR tree-optimization/87309)

Message ID 1537356549-60094-1-git-send-email-dmalcolm@redhat.com
State New
Headers show
Series dumpfile.c: fix stray dump_loc output (PR tree-optimization/87309) | expand

Commit Message

David Malcolm Sept. 19, 2018, 11:29 a.m. UTC
In r262891 I reimplemented this call:
  dump_printf_loc (MSG_NOTE, loc, "=== %s ===\n", name);
in dump_begin_scope to use direct calls to dump_loc:
  if (dump_file)
    {
      dump_loc (MSG_NOTE, dump_file, loc.get_location_t ());
      fprintf (dump_file, "=== %s ===\n", name);
    }

  if (alt_dump_file)
   {
     dump_loc (MSG_NOTE, alt_dump_file, loc.get_location_t ());
     fprintf (alt_dump_file, "=== %s ===\n", name);
   }

However ::dump_loc doesn't filter with pflags and alt_flags.

This caused stray output of the form:
  test.cpp:1:6: note: test.cpp:1:11: note:
when using -fopt-info with "optimized" or "missed".

This patch adds this missing filtering, eliminating the stray partial
note output.

Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.

OK for trunk?

gcc/ChangeLog:
	PR tree-optimization/87309
	* dumpfile.c (dump_context::begin_scope): Filter the dump_loc
	calls with pflags and alt_flags.

gcc/testsuite/ChangeLog:
	PR tree-optimization/87309
	* gcc.dg/pr87309.c: New test.
---
 gcc/dumpfile.c                 | 4 ++--
 gcc/testsuite/gcc.dg/pr87309.c | 4 ++++
 2 files changed, 6 insertions(+), 2 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr87309.c

Comments

Richard Biener Sept. 19, 2018, 1:51 p.m. UTC | #1
On Wed, Sep 19, 2018 at 12:42 PM David Malcolm <dmalcolm@redhat.com> wrote:
>
> In r262891 I reimplemented this call:
>   dump_printf_loc (MSG_NOTE, loc, "=== %s ===\n", name);
> in dump_begin_scope to use direct calls to dump_loc:
>   if (dump_file)
>     {
>       dump_loc (MSG_NOTE, dump_file, loc.get_location_t ());
>       fprintf (dump_file, "=== %s ===\n", name);
>     }
>
>   if (alt_dump_file)
>    {
>      dump_loc (MSG_NOTE, alt_dump_file, loc.get_location_t ());
>      fprintf (alt_dump_file, "=== %s ===\n", name);
>    }
>
> However ::dump_loc doesn't filter with pflags and alt_flags.
>
> This caused stray output of the form:
>   test.cpp:1:6: note: test.cpp:1:11: note:
> when using -fopt-info with "optimized" or "missed".
>
> This patch adds this missing filtering, eliminating the stray partial
> note output.
>
> Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
>
> OK for trunk?

OK

> gcc/ChangeLog:
>         PR tree-optimization/87309
>         * dumpfile.c (dump_context::begin_scope): Filter the dump_loc
>         calls with pflags and alt_flags.
>
> gcc/testsuite/ChangeLog:
>         PR tree-optimization/87309
>         * gcc.dg/pr87309.c: New test.
> ---
>  gcc/dumpfile.c                 | 4 ++--
>  gcc/testsuite/gcc.dg/pr87309.c | 4 ++++
>  2 files changed, 6 insertions(+), 2 deletions(-)
>  create mode 100644 gcc/testsuite/gcc.dg/pr87309.c
>
> diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
> index a81ab3e..7333ee3 100644
> --- a/gcc/dumpfile.c
> +++ b/gcc/dumpfile.c
> @@ -1048,10 +1048,10 @@ dump_context::get_scope_depth () const
>  void
>  dump_context::begin_scope (const char *name, const dump_location_t &loc)
>  {
> -  if (dump_file)
> +  if (dump_file && (MSG_NOTE & pflags))
>      ::dump_loc (MSG_NOTE, dump_file, loc.get_location_t ());
>
> -  if (alt_dump_file)
> +  if (alt_dump_file && (MSG_NOTE & alt_flags))
>      ::dump_loc (MSG_NOTE, alt_dump_file, loc.get_location_t ());
>
>    /* Support for temp_dump_context in selftests.  */
> diff --git a/gcc/testsuite/gcc.dg/pr87309.c b/gcc/testsuite/gcc.dg/pr87309.c
> new file mode 100644
> index 0000000..8bd5a44
> --- /dev/null
> +++ b/gcc/testsuite/gcc.dg/pr87309.c
> @@ -0,0 +1,4 @@
> +/* { dg-do compile } */
> +/* { dg-options "-fopt-info-vec-optimized -O3" } */
> +
> +void a() {} /* { dg-bogus "note" } */
> --
> 1.8.5.3
>
David Malcolm Sept. 21, 2018, 3:11 p.m. UTC | #2
On Wed, 2018-09-19 at 15:51 +0200, Richard Biener wrote:
> On Wed, Sep 19, 2018 at 12:42 PM David Malcolm <dmalcolm@redhat.com>
> wrote:
> > 
> > In r262891 I reimplemented this call:
> >   dump_printf_loc (MSG_NOTE, loc, "=== %s ===\n", name);
> > in dump_begin_scope to use direct calls to dump_loc:
> >   if (dump_file)
> >     {
> >       dump_loc (MSG_NOTE, dump_file, loc.get_location_t ());
> >       fprintf (dump_file, "=== %s ===\n", name);
> >     }
> > 
> >   if (alt_dump_file)
> >    {
> >      dump_loc (MSG_NOTE, alt_dump_file, loc.get_location_t ());
> >      fprintf (alt_dump_file, "=== %s ===\n", name);
> >    }
> > 
> > However ::dump_loc doesn't filter with pflags and alt_flags.
> > 
> > This caused stray output of the form:
> >   test.cpp:1:6: note: test.cpp:1:11: note:
> > when using -fopt-info with "optimized" or "missed".
> > 
> > This patch adds this missing filtering, eliminating the stray
> > partial
> > note output.
> > 
> > Successfully bootstrapped & regrtested on x86_64-pc-linux-gnu.
> > 
> > OK for trunk?
> 
> OK

Thanks.

Ilya [CCed] spotted (in bugzilla) that I missed the case of
m_test_pp_flags.  This is only used by selftests, but it seemed
appropriate to get it right, so I fixed that, and added selftest
coverage for it.

For reference, here's what I committed (r264481), self-approving the
slight tweak described above under the "obvious" rule.

Dave

gcc/ChangeLog:
	PR tree-optimization/87309
	* dumpfile.c (dump_context::begin_scope): Filter the dump_loc
	calls with pflags and alt_flags.
	(selftest::test_capture_of_dump_calls): Add test of interaction of
	MSG_OPTIMIZED_LOCATIONS with AUTO_DUMP_SCOPE.

gcc/testsuite/ChangeLog:
	PR tree-optimization/87309
	* gcc.dg/pr87309.c: New test.
---
 gcc/dumpfile.c                 | 29 ++++++++++++++++++++++++++---
 gcc/testsuite/gcc.dg/pr87309.c |  4 ++++
 2 files changed, 30 insertions(+), 3 deletions(-)
 create mode 100644 gcc/testsuite/gcc.dg/pr87309.c

diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index a81ab3e..5655e46 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -1048,14 +1048,14 @@ dump_context::get_scope_depth () const
 void
 dump_context::begin_scope (const char *name, const dump_location_t &loc)
 {
-  if (dump_file)
+  if (dump_file && (MSG_NOTE & pflags))
     ::dump_loc (MSG_NOTE, dump_file, loc.get_location_t ());
 
-  if (alt_dump_file)
+  if (alt_dump_file && (MSG_NOTE & alt_flags))
     ::dump_loc (MSG_NOTE, alt_dump_file, loc.get_location_t ());
 
   /* Support for temp_dump_context in selftests.  */
-  if (m_test_pp)
+  if (m_test_pp && (MSG_NOTE & m_test_pp_flags))
     ::dump_loc (MSG_NOTE, m_test_pp, loc.get_location_t ());
 
   pretty_printer pp;
@@ -2304,6 +2304,29 @@ test_capture_of_dump_calls (const line_table_case &case_)
 		 OPTINFO_KIND_FAILURE);
     }
   }
+
+  /* Verify that MSG_* affect AUTO_DUMP_SCOPE and the dump calls.  */
+  {
+    temp_dump_context tmp (false, MSG_OPTIMIZED_LOCATIONS);
+    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_OPTIMIZED_LOCATIONS, 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 4\n");
+  }
 }
 
 /* Run all of the selftests within this file.  */
diff --git a/gcc/testsuite/gcc.dg/pr87309.c b/gcc/testsuite/gcc.dg/pr87309.c
new file mode 100644
index 0000000..8bd5a44
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr87309.c
@@ -0,0 +1,4 @@
+/* { dg-do compile } */
+/* { dg-options "-fopt-info-vec-optimized -O3" } */
+
+void a() {} /* { dg-bogus "note" } */
diff mbox series

Patch

diff --git a/gcc/dumpfile.c b/gcc/dumpfile.c
index a81ab3e..7333ee3 100644
--- a/gcc/dumpfile.c
+++ b/gcc/dumpfile.c
@@ -1048,10 +1048,10 @@  dump_context::get_scope_depth () const
 void
 dump_context::begin_scope (const char *name, const dump_location_t &loc)
 {
-  if (dump_file)
+  if (dump_file && (MSG_NOTE & pflags))
     ::dump_loc (MSG_NOTE, dump_file, loc.get_location_t ());
 
-  if (alt_dump_file)
+  if (alt_dump_file && (MSG_NOTE & alt_flags))
     ::dump_loc (MSG_NOTE, alt_dump_file, loc.get_location_t ());
 
   /* Support for temp_dump_context in selftests.  */
diff --git a/gcc/testsuite/gcc.dg/pr87309.c b/gcc/testsuite/gcc.dg/pr87309.c
new file mode 100644
index 0000000..8bd5a44
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/pr87309.c
@@ -0,0 +1,4 @@ 
+/* { dg-do compile } */
+/* { dg-options "-fopt-info-vec-optimized -O3" } */
+
+void a() {} /* { dg-bogus "note" } */