From fb55ed83cb17b74e8e54cea0c0d2028ece1267fd Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Thu, 14 Jul 2016 16:52:07 -0400
Subject: [PATCH 40/42] Expose ASSERT_LOCATION_EQ from selftest.h for use
 outside of input.c

gcc/ChangeLog:
	* input.c (selftest::assert_loceq): Rename to...
	(selftest::assert_location_eq): ...this, and add REPORT_LOC param,
	using it in the various assertions.
	(selftest::test_accessing_ordinary_linemaps): Use
	ASSERT_LOCATION_EQ rather than assert_loceq.
	(selftest::test_builtins): Likewise.
	* selftest.h (selftest::assert_location_eq): New declaration.
	(ASSERT_LOCATION_EQ): New macro.
---
 gcc/input.c    | 32 +++++++++++++++++---------------
 gcc/selftest.h | 15 +++++++++++++++
 2 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/gcc/input.c b/gcc/input.c
index 79ce355..c0581cd 100644
--- a/gcc/input.c
+++ b/gcc/input.c
@@ -1629,21 +1629,23 @@ test_should_have_column_data_p ()
 }
 
 /* Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN
-   on LOC.  */
+   on ACTUAL_LOC, using REPORT_LOC as the effective location when
+   reporting problems.  */
 
-static void
-assert_loceq (const char *exp_filename, int exp_linenum, int exp_colnum,
-	      location_t loc)
+void
+assert_location_eq (const location &report_loc,
+		    const char *exp_filename, int exp_linenum, int exp_colnum,
+		    location_t actual_loc)
 {
-  ASSERT_STREQ (exp_filename, LOCATION_FILE (loc));
-  ASSERT_EQ (exp_linenum, LOCATION_LINE (loc));
+  ASSERT_STREQ_AT (report_loc, exp_filename, LOCATION_FILE (actual_loc));
+  ASSERT_EQ_AT (report_loc, exp_linenum, LOCATION_LINE (actual_loc));
   /* If location_t values are sufficiently high, then column numbers
      will be unavailable and LOCATION_COLUMN (loc) will be 0.
      When close to the threshold, column numbers *may* be present: if
      the final linemap before the threshold contains a line that straddles
      the threshold, locations in that line have column information.  */
-  if (should_have_column_data_p (loc))
-    ASSERT_EQ (exp_colnum, LOCATION_COLUMN (loc));
+  if (should_have_column_data_p (actual_loc))
+    ASSERT_EQ_AT (report_loc, exp_colnum, LOCATION_COLUMN (actual_loc));
 }
 
 /* Various selftests involve constructing a line table and one or more
@@ -1750,12 +1752,12 @@ test_accessing_ordinary_linemaps (const line_table_case &case_)
   linemap_add (line_table, LC_LEAVE, false, NULL, 0);
 
   /* Verify that we can recover the location info.  */
-  assert_loceq ("foo.c", 1, 1, loc_a);
-  assert_loceq ("foo.c", 1, 23, loc_b);
-  assert_loceq ("foo.c", 2, 1, loc_c);
-  assert_loceq ("foo.c", 2, 17, loc_d);
-  assert_loceq ("foo.c", 3, 700, loc_e);
-  assert_loceq ("bar.c", 1, 150, loc_f);
+  ASSERT_LOCATION_EQ ("foo.c", 1, 1, loc_a);
+  ASSERT_LOCATION_EQ ("foo.c", 1, 23, loc_b);
+  ASSERT_LOCATION_EQ ("foo.c", 2, 1, loc_c);
+  ASSERT_LOCATION_EQ ("foo.c", 2, 17, loc_d);
+  ASSERT_LOCATION_EQ ("foo.c", 3, 700, loc_e);
+  ASSERT_LOCATION_EQ ("bar.c", 1, 150, loc_f);
 
   ASSERT_FALSE (is_location_from_builtin_token (loc_a));
   ASSERT_TRUE (pure_location_p (line_table, loc_a));
@@ -1785,7 +1787,7 @@ test_unknown_location ()
 static void
 test_builtins ()
 {
-  assert_loceq (_("<built-in>"), 0, 0, BUILTINS_LOCATION);
+  ASSERT_LOCATION_EQ (_("<built-in>"), 0, 0, BUILTINS_LOCATION);
   ASSERT_PRED1 (is_location_from_builtin_token, BUILTINS_LOCATION);
 }
 
diff --git a/gcc/selftest.h b/gcc/selftest.h
index 8b1eb42..d7293c3 100644
--- a/gcc/selftest.h
+++ b/gcc/selftest.h
@@ -94,6 +94,12 @@ class named_temp_file
   char *m_filename;
 };
 
+/* Implementation detail of ASSERT_LOCATION_EQ.  */
+
+extern void assert_location_eq (const location &report_loc,
+				const char *exp_filename, int exp_linenum,
+				int exp_colnum, location_t actual_loc);
+
 /* A class for writing out a temporary sourcefile for use in selftests
    of input handling.  */
 
@@ -350,6 +356,15 @@ extern int num_passes;
     ::selftest::fail (SELFTEST_LOCATION, desc);			\
   SELFTEST_END_STMT
 
+/* Verify the result of LOCATION_FILE/LOCATION_LINE/LOCATION_COLUMN
+   on LOC.  */
+
+#define ASSERT_LOCATION_EQ(EXP_FILENAME, EXP_LINENUM, EXP_COLNUM, LOC)	\
+  SELFTEST_BEGIN_STMT							\
+  ::selftest::assert_location_eq (SELFTEST_LOCATION, (EXP_FILENAME),	\
+				  (EXP_LINENUM), (EXP_COLNUM), (LOC));	\
+  SELFTEST_END_STMT
+
 #define SELFTEST_BEGIN_STMT do {
 #define SELFTEST_END_STMT   } while (0)
 
-- 
1.8.5.3

