From 9369dc09b3d07c3bfc95822bda2ba11fa82e28bd Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 28 Oct 2015 13:21:59 -0400
Subject: [PATCH] Fix issues found in review

gcc/ChangeLog:
	* diagnostic.c (source_range::debug): Add comment.  Add
	DEBUG_FUNCTION.  Provide formerly default argument to
	add_range call.
	* diagnostic.h (diagnostic_get_color_for_kind): Remove
	newline.
	* genmatch.c (linemap_client_expand_location_to_spelling_point):
	Add comment.
	* input.c (linemap_client_expand_location_to_spelling_point):
	Likewise.

gcc/testsuite/ChangeLog:
	* gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
	(test_show_locus): Provide formerly default argument to add_range
	calls.

libcpp/ChangeLog:
	* include/line-map.h (source_range::debug): Add comment.
	(rich_location::add_range): Remove default value for
	show_caret_p argument.
---
 gcc/diagnostic.c                                        | 10 ++++++++--
 gcc/diagnostic.h                                        |  3 +--
 gcc/genmatch.c                                          |  8 ++++++++
 gcc/input.c                                             |  9 +++++++++
 .../gcc.dg/plugin/diagnostic_plugin_test_show_locus.c   | 16 ++++++++--------
 libcpp/include/line-map.h                               | 17 ++++++++++++++---
 6 files changed, 48 insertions(+), 15 deletions(-)

diff --git a/gcc/diagnostic.c b/gcc/diagnostic.c
index 5fe6627..05f1d31 100644
--- a/gcc/diagnostic.c
+++ b/gcc/diagnostic.c
@@ -1343,10 +1343,16 @@ real_abort (void)
   abort ();
 }
 
-void
+/* Display the given source_range instance, with MSG as a descriptive
+   comment.  This issues a "note" diagnostic at the range.
+
+   This is declared within libcpp, but implemented here, since it
+   makes use of the diagnostic-printing machinery.  */
+
+DEBUG_FUNCTION void
 source_range::debug (const char *msg) const
 {
   rich_location richloc (m_start);
-  richloc.add_range (m_start, m_finish);
+  richloc.add_range (m_start, m_finish, false);
   inform_at_rich_loc (&richloc, "%s", msg);
 }
diff --git a/gcc/diagnostic.h b/gcc/diagnostic.h
index 153e84c..9096e16 100644
--- a/gcc/diagnostic.h
+++ b/gcc/diagnostic.h
@@ -352,8 +352,7 @@ diagnostic_same_line (const diagnostic_context *context,
     && context->caret_max_width - CARET_LINE_MARGIN > abs (s1.column - s2.column);
 }
 
-extern const char *
-diagnostic_get_color_for_kind (diagnostic_t kind);
+extern const char *diagnostic_get_color_for_kind (diagnostic_t kind);
 
 /* Pure text formatting support functions.  */
 extern char *file_name_as_prefix (diagnostic_context *, const char *);
diff --git a/gcc/genmatch.c b/gcc/genmatch.c
index 6bfde06..8a03f35 100644
--- a/gcc/genmatch.c
+++ b/gcc/genmatch.c
@@ -53,6 +53,14 @@ unsigned verbose;
 
 static struct line_maps *line_table;
 
+/* The rich_location class within libcpp requires a way to expand
+   source_location instances, and relies on the client code
+   providing a symbol named
+     linemap_client_expand_location_to_spelling_point
+   to do this.
+
+   This is the implementation for genmatch.  */
+
 expanded_location
 linemap_client_expand_location_to_spelling_point (source_location loc)
 {
diff --git a/gcc/input.c b/gcc/input.c
index baf8e7e..0f6d448 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -751,6 +751,15 @@ expand_location_to_spelling_point (source_location loc)
   return expand_location_1 (loc, /*expansion_point_p=*/false);
 }
 
+/* The rich_location class within libcpp requires a way to expand
+   source_location instances, and relies on the client code
+   providing a symbol named
+     linemap_client_expand_location_to_spelling_point
+   to do this.
+
+   This is the implementation for libcommon.a (all host binaries),
+   which simply calls into expand_location_to_spelling_point.  */
+
 expanded_location
 linemap_client_expand_location_to_spelling_point (source_location loc)
 {
diff --git a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
index 3471a4e..8f5724e 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic_plugin_test_show_locus.c
@@ -164,8 +164,8 @@ test_show_locus (function *fun)
     {
       const int line = fnstart_line + 2;
       rich_location richloc (get_loc (line, 15));
-      richloc.add_range (get_loc (line, 10), get_loc (line, 14));
-      richloc.add_range (get_loc (line, 16), get_loc (line, 16));
+      richloc.add_range (get_loc (line, 10), get_loc (line, 14), false);
+      richloc.add_range (get_loc (line, 16), get_loc (line, 16), false);
       warning_at_rich_loc (&richloc, 0, "test");
     }
 
@@ -174,9 +174,9 @@ test_show_locus (function *fun)
       const int line = fnstart_line + 2;
       rich_location richloc (get_loc (line, 24));
       richloc.add_range (get_loc (line, 6),
-			 get_loc (line, 22));
+			 get_loc (line, 22), false);
       richloc.add_range (get_loc (line, 26),
-			 get_loc (line, 43));
+			 get_loc (line, 43), false);
       warning_at_rich_loc (&richloc, 0, "test");
     }
 
@@ -185,9 +185,9 @@ test_show_locus (function *fun)
       const int line = fnstart_line + 2;
       rich_location richloc (get_loc (line + 1, 7));
       richloc.add_range (get_loc (line, 7),
-			 get_loc (line, 23));
+			 get_loc (line, 23), false);
       richloc.add_range (get_loc (line + 1, 9),
-			 get_loc (line + 1, 26));
+			 get_loc (line + 1, 26), false);
       warning_at_rich_loc (&richloc, 0, "test");
     }
 
@@ -196,9 +196,9 @@ test_show_locus (function *fun)
       const int line = fnstart_line + 2;
       rich_location richloc (get_loc (line + 5, 7));
       richloc.add_range (get_loc (line, 7),
-			 get_loc (line + 4, 65));
+			 get_loc (line + 4, 65), false);
       richloc.add_range (get_loc (line + 5, 9),
-			 get_loc (line + 10, 61));
+			 get_loc (line + 10, 61), false);
       warning_at_rich_loc (&richloc, 0, "test");
     }
 
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 84a5ab7..c8f636d 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -144,6 +144,18 @@ struct GTY(()) source_range
   source_location m_start;
   source_location m_finish;
 
+  /* Display this source_range instance, with MSG as a descriptive
+     comment.  This issues a "note" diagnostic at the range, using
+     gcc's diagnostic machinery.
+
+     This is declared here, but is implemented within gcc/diagnostic.c,
+     since it makes use of gcc's diagnostic-printing machinery.  This
+     is a slight layering violation, but this is sufficiently useful
+     for debugging that it's worth it.
+
+     This declaration would have a DEBUG_FUNCTION annotation, but that
+     is implemented in gcc/system.h and thus is not available here in
+     libcpp.  */
   void debug (const char *msg) const;
 
   /* We avoid using constructors, since various structs that
@@ -1187,11 +1199,10 @@ class rich_location
 
   void
   add_range (source_location start, source_location finish,
-	     bool show_caret_p = false);
+	     bool show_caret_p);
 
   void
-  add_range (source_range src_range,
-	     bool show_caret_p = false);
+  add_range (source_range src_range, bool show_caret_p);
 
   void
   add_range (location_range *src_range);
-- 
1.8.5.3

