From 6f962eb0c42256f59f0f7430661dfa008be39d7c Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 6 Dec 2017 15:47:05 -0500
Subject: [PATCH 13/29] FIXME: add d-s-l to
 diagnostic_unwind_inlining_information

---
 gcc/cp/error.c                                     |  6 ++++--
 gcc/langhooks.c                                    |  7 +++++--
 .../g++.dg/plugin/diagnostic-test-inlining-1.C     |  8 ++++++++
 .../gcc.dg/plugin/diagnostic-test-inlining-1.c     |  8 ++++++++
 .../gcc.dg/plugin/diagnostic-test-inlining-2.c     |  8 ++++++++
 gcc/tree-diagnostic.c                              | 22 ++++++++++++++++++++--
 6 files changed, 53 insertions(+), 6 deletions(-)

diff --git a/gcc/cp/error.c b/gcc/cp/error.c
index 4071762..f1a768e 100644
--- a/gcc/cp/error.c
+++ b/gcc/cp/error.c
@@ -3332,7 +3332,10 @@ cp_print_error_function (diagnostic_context *context,
       pp_set_prefix (context->printer, new_prefix);
 
       if (current_function_decl == NULL)
-	pp_string (context->printer, _("At global scope:"));
+	{
+	  pp_string (context->printer, _("At global scope:"));
+	  pp_newline (context->printer);
+	}
       else
 	{
 	  tree fndecl, ao;
@@ -3356,7 +3359,6 @@ cp_print_error_function (diagnostic_context *context,
 	  diagnostic_unwind_inlining_information (context, abstract_origin,
 						  print_fn_decl);
 	}
-      pp_newline (context->printer);
 
       diagnostic_set_last_function (context, diagnostic);
       pp_destroy_prefix (context->printer);
diff --git a/gcc/langhooks.c b/gcc/langhooks.c
index 472900a..ef1a8d9 100644
--- a/gcc/langhooks.c
+++ b/gcc/langhooks.c
@@ -384,7 +384,10 @@ lhd_print_error_function (diagnostic_context *context, const char *file,
       pp_set_prefix (context->printer, new_prefix);
 
       if (current_function_decl == NULL)
-	pp_printf (context->printer, _("At top level:"));
+	{
+	  pp_printf (context->printer, _("At top level:"));
+	  pp_newline (context->printer);
+	}
       else
 	{
 	  tree fndecl, ao;
@@ -416,7 +419,7 @@ lhd_print_error_function (diagnostic_context *context, const char *file,
 	}
 
       diagnostic_set_last_function (context, diagnostic);
-      pp_newline_and_flush (context->printer);
+      pp_flush (context->printer);
       context->printer->prefix = old_prefix;
       free ((char*) new_prefix);
     }
diff --git a/gcc/testsuite/g++.dg/plugin/diagnostic-test-inlining-1.C b/gcc/testsuite/g++.dg/plugin/diagnostic-test-inlining-1.C
index df7bb1f..165bf05 100644
--- a/gcc/testsuite/g++.dg/plugin/diagnostic-test-inlining-1.C
+++ b/gcc/testsuite/g++.dg/plugin/diagnostic-test-inlining-1.C
@@ -26,7 +26,15 @@ int main()
 
 /* { dg-regexp "In function 'void foo\\(\\)'," "" } */
 /* { dg-regexp "    inlined from 'void bar\\(\\)' at .+/diagnostic-test-inlining-1.C:18:7," "" } */
+/* { dg-begin-multiline-output "" }
+   foo ();
+       ^
+   { dg-end-multiline-output "" } */
 /* { dg-regexp "    inlined from 'int main\\(\\)' at .+/diagnostic-test-inlining-1.C:23:7:" "" } */
+/* { dg-begin-multiline-output "" }
+   bar ();
+       ^
+   { dg-end-multiline-output "" } */
 /* { dg-warning "18: message" "" { target *-*-* } 12 } */
 /* { dg-begin-multiline-output "" }
    __emit_warning ("message");
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-1.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-1.c
index a24b7f8..336432e 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-1.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-1.c
@@ -26,7 +26,15 @@ int main()
 
 /* { dg-regexp "In function 'foo'," "" } */
 /* { dg-regexp "    inlined from 'bar' at .+/diagnostic-test-inlining-1.c:15:3," "" } */
+/* { dg-begin-multiline-output "" }
+   foo ();
+   ^
+   { dg-end-multiline-output "" } */
 /* { dg-regexp "    inlined from 'main' at .+/diagnostic-test-inlining-1.c:20:3:" "" } */
+/* { dg-begin-multiline-output "" }
+   bar ();
+   ^
+   { dg-end-multiline-output "" } */
 /* { dg-warning "3: message" "" { target *-*-* } 9 } */
 /* { dg-begin-multiline-output "" }
    __emit_warning ("message");
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-2.c b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-2.c
index 52e4825..8473dcc 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-2.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-2.c
@@ -30,7 +30,15 @@ int main()
 
 /* { dg-regexp "In function 'foo'," "" } */
 /* { dg-regexp "    inlined from 'bar' at .+/diagnostic-test-inlining-2.c:19:3," "" } */
+/* { dg-begin-multiline-output "" }
+   foo ();
+   ^
+   { dg-end-multiline-output "" } */
 /* { dg-regexp "    inlined from 'main' at .+/diagnostic-test-inlining-2.c:24:3:" "" } */
+/* { dg-begin-multiline-output "" }
+   bar ();
+   ^
+   { dg-end-multiline-output "" } */
 /* { dg-warning "28: message" "" { target c } 6 } */
 /* { dg-begin-multiline-output "" }
  #define INNER_WARNING(MSG) __emit_warning (MSG)
diff --git a/gcc/tree-diagnostic.c b/gcc/tree-diagnostic.c
index a4b66b4..107dd8c 100644
--- a/gcc/tree-diagnostic.c
+++ b/gcc/tree-diagnostic.c
@@ -29,6 +29,7 @@ along with GCC; see the file COPYING3.  If not see
 #include "tree-diagnostic.h"
 #include "langhooks.h"
 #include "intl.h"
+#include "gcc-rich-location.h"
 
 /* Prints out, if necessary, the name of the current function
    that caused an error.  Called from all error and warning functions.  */
@@ -321,6 +322,8 @@ diagnostic_unwind_inlining_information (diagnostic_context *context,
 					tree abstract_origin,
 					const char * (*print_fn_decl_cb) (tree))
 {
+  location_t pending_loc = UNKNOWN_LOCATION;
+
   while (abstract_origin)
     {
       location_t *locus;
@@ -364,7 +367,15 @@ diagnostic_unwind_inlining_information (diagnostic_context *context,
 	{
 	  expanded_location s = expand_location (*locus);
 	  pp_comma (context->printer);
-	  pp_newline (context->printer);
+
+	  if (pending_loc)
+	    {
+	      gcc_rich_location richloc (pending_loc);
+	      diagnostic_show_locus (context, &richloc, DK_NOTE);
+	    }
+	  else
+	    pp_newline (context->printer);
+
 	  if (s.file != NULL)
 	    {
 	      if (context->show_column && s.column != 0)
@@ -377,12 +388,19 @@ diagnostic_unwind_inlining_information (diagnostic_context *context,
 			   _("    inlined from %qs at %r%s:%d%R"),
 			   print_fn_decl_cb (fndecl),
 			   "locus", s.file, s.line);
-
 	    }
 	  else
 	    pp_printf (context->printer, _("    inlined from %qs"),
 		       print_fn_decl_cb (fndecl));
 	}
+
+      pending_loc = *locus;
     }
   pp_colon (context->printer);
+
+  if (pending_loc)
+    {
+      gcc_rich_location richloc (pending_loc);
+      diagnostic_show_locus (context, &richloc, DK_NOTE);
+    }
 }
-- 
1.8.5.3

