From 318feba7b7fd8f75cc16de107f7007c7cef1dd34 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Wed, 6 Dec 2017 16:36:10 -0500
Subject: [PATCH 14/29] FIXME: fix underlining of inlined callsites

(we can't simply use the location, the block has to be NULL or we run
into a gimple verification failure; TODO: which?)
---
 gcc/input.h                                              |  4 ++++
 gcc/testsuite/g++.dg/plugin/diagnostic-test-inlining-1.C |  4 ++--
 gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-1.c |  4 ++--
 gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-2.c |  4 ++--
 gcc/tree-inline.c                                        |  4 ++--
 libcpp/include/line-map.h                                |  2 ++
 libcpp/line-map.c                                        | 16 ++++++++++++++++
 7 files changed, 30 insertions(+), 8 deletions(-)

diff --git a/gcc/input.h b/gcc/input.h
index f58d248..f38da1e 100644
--- a/gcc/input.h
+++ b/gcc/input.h
@@ -58,6 +58,10 @@ extern location_t input_location;
 #define LOCATION_LOCUS(LOC) \
   ((IS_ADHOC_LOC (LOC)) ? get_location_from_adhoc_loc (line_table, LOC) \
    : (LOC))
+#define LOCATION_LOCUS_AND_RANGE(LOC) \
+  ((IS_ADHOC_LOC (LOC)) \
+   ? get_location_and_range_from_adhoc_loc (line_table, LOC)	\
+   : (LOC))
 #define LOCATION_BLOCK(LOC) \
   ((tree) ((IS_ADHOC_LOC (LOC)) ? get_data_from_adhoc_loc (line_table, (LOC)) \
    : NULL))
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 165bf05..5c770c3 100644
--- a/gcc/testsuite/g++.dg/plugin/diagnostic-test-inlining-1.C
+++ b/gcc/testsuite/g++.dg/plugin/diagnostic-test-inlining-1.C
@@ -28,12 +28,12 @@ int main()
 /* { 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 "" }
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 336432e..7177339 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-1.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-1.c
@@ -28,12 +28,12 @@ int main()
 /* { 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 "" }
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 8473dcc..d1b6c9d 100644
--- a/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-2.c
+++ b/gcc/testsuite/gcc.dg/plugin/diagnostic-test-inlining-2.c
@@ -32,12 +32,12 @@ int main()
 /* { 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 "" }
diff --git a/gcc/tree-inline.c b/gcc/tree-inline.c
index ca98e43..5b44770 100644
--- a/gcc/tree-inline.c
+++ b/gcc/tree-inline.c
@@ -4525,8 +4525,8 @@ expand_call_inline (basic_block bb, gimple *stmt, copy_body_data *id)
     {
       id->block = make_node (BLOCK);
       BLOCK_ABSTRACT_ORIGIN (id->block) = fn;
-      BLOCK_SOURCE_LOCATION (id->block) 
-	= LOCATION_LOCUS (gimple_location (stmt));
+      BLOCK_SOURCE_LOCATION (id->block)
+	= LOCATION_LOCUS_AND_RANGE (gimple_location (stmt));
       prepend_lexical_block (gimple_block (stmt), id->block);
     }
 
diff --git a/libcpp/include/line-map.h b/libcpp/include/line-map.h
index 1151484..051420d 100644
--- a/libcpp/include/line-map.h
+++ b/libcpp/include/line-map.h
@@ -1008,6 +1008,8 @@ extern source_location get_combined_adhoc_loc (struct line_maps *,
 extern void *get_data_from_adhoc_loc (struct line_maps *, source_location);
 extern source_location get_location_from_adhoc_loc (struct line_maps *,
 						    source_location);
+extern source_location get_location_and_range_from_adhoc_loc (struct line_maps *,
+							      source_location);
 
 extern source_range get_range_from_loc (line_maps *set, source_location loc);
 
diff --git a/libcpp/line-map.c b/libcpp/line-map.c
index ac621e9..74fc8c6 100644
--- a/libcpp/line-map.c
+++ b/libcpp/line-map.c
@@ -262,6 +262,22 @@ get_location_from_adhoc_loc (struct line_maps *set, source_location loc)
   return set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION].locus;
 }
 
+/* Return a combined form of the location+range for the adhoc loc,
+   with any data effectively as NULL.  */
+
+source_location
+get_location_and_range_from_adhoc_loc (struct line_maps *set,
+				       source_location loc)
+{
+  linemap_assert (IS_ADHOC_LOC (loc));
+
+  location_adhoc_data *data
+    = &set->location_adhoc_data_map.data[loc & MAX_SOURCE_LOCATION];
+
+  return COMBINE_LOCATION_DATA (set, get_pure_location (set, data->locus),
+				data->src_range, NULL);
+}
+
 /* Return the source_range for adhoc location LOC.  */
 
 static source_range
-- 
1.8.5.3

