From bfd405f3043674756363ef3013e92ca2fd88741d Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 28 Aug 2015 06:29:19 -0400
Subject: [PATCH 49/66] FIXME: C FE: Convert location hack gcc.dg/20150303-01.c
 to a non-hack example in -2.c (needs tree ranges)

---
 gcc/c/c-typeck.c                           | 19 ++++++++-----------
 gcc/location-hacks.c                       |  7 -------
 gcc/testsuite/gcc.dg/20150303-01.c         | 24 ------------------------
 gcc/testsuite/gcc.dg/diagnostic-ranges-2.c | 23 +++++++++++++++++++++++
 4 files changed, 31 insertions(+), 42 deletions(-)
 delete mode 100644 gcc/testsuite/gcc.dg/20150303-01.c

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index db63d7a..feee6cf 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -2852,11 +2852,7 @@ static void
 inform_declaration (tree decl)
 {
   if (decl && (TREE_CODE (decl) != FUNCTION_DECL || !DECL_IS_BUILTIN (decl)))
-    {
-      gcc_rich_location richloc (DECL_SOURCE_LOCATION (decl));
-      richloc.maybe_add_expr (decl);
-      inform_at_rich_loc (&richloc, "declared here");
-    }
+    inform (DECL_LOCATION_RANGE (decl), "declared here");
 }
 
 /* Build a function call to function FUNCTION with parameters PARAMS.
@@ -2878,6 +2874,7 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
   int nargs;
   tree *argarray;
 
+  source_range func_range = EXPR_LOCATION_RANGE (function);
 
   /* Strip NON_LVALUE_EXPRs, etc., since we aren't using as an lvalue.  */
   STRIP_TYPE_NOPS (function);
@@ -2927,7 +2924,7 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
 		  function);
       else if (DECL_P (function))
 	{
-	  gcc_rich_location richloc (loc); //fn_expr_range);
+	  gcc_rich_location richloc (func_range);
 	  error_at_rich_loc
 	    (&richloc,
 	     "called object %qD is not a function or function pointer",
@@ -2936,8 +2933,7 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
 	}
       else
 	{
-	  gcc_rich_location richloc (loc);
-	  richloc.add_expr (function);
+	  gcc_rich_location richloc (func_range);
 	  error_at_rich_loc
 	    (&richloc,
 	     "called object is not a function or function pointer");
@@ -2971,11 +2967,12 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
       /* This situation leads to run-time undefined behavior.  We can't,
 	 therefore, simply error unless we can prove that all possible
 	 executions of the program must execute the code.  */
-      warning_at (loc, 0, "function called through a non-compatible type");
+      warning_at (func_range, 0,
+		  "function called through a non-compatible type");
 
       if (VOID_TYPE_P (return_type)
 	  && TYPE_QUALS (return_type) != TYPE_UNQUALIFIED)
-	pedwarn (loc, 0,
+	pedwarn (func_range, 0,
 		 "function with qualified void return type called");
      }
 
@@ -3012,7 +3009,7 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
   if (VOID_TYPE_P (TREE_TYPE (result)))
     {
       if (TYPE_QUALS (TREE_TYPE (result)) != TYPE_UNQUALIFIED)
-	pedwarn (loc, 0,
+	pedwarn (func_range, 0,
 		 "function with qualified void return type called");
       return result;
     }
diff --git a/gcc/location-hacks.c b/gcc/location-hacks.c
index 1baf8f0..9251bee 100644
--- a/gcc/location-hacks.c
+++ b/gcc/location-hacks.c
@@ -75,13 +75,6 @@ struct expr_locations_for_testcase
 };
 
 struct expr_locations_for_testcase expr_location_oracle[] = {
-  {"testsuite/gcc.dg/20150303-01.c",
-   3,
-   {{6, 2, 6, 14},
-    {7, 2, 7, 5},
-    {4, 16, 4, 19}}
-  },
-
   {"testsuite/gcc.dg/20150303-04.c",
    2,
    {{9, 2, 9, 9},
diff --git a/gcc/testsuite/gcc.dg/20150303-01.c b/gcc/testsuite/gcc.dg/20150303-01.c
deleted file mode 100644
index a286ebf..0000000
--- a/gcc/testsuite/gcc.dg/20150303-01.c
+++ /dev/null
@@ -1,24 +0,0 @@
-/* Adapted from https://gcc.gnu.org/wiki/ClangDiagnosticsComparison */
-/* { dg-options "-fdiagnostics-show-caret" } */
-
-void foo(char **argP, char **argQ)
-{
-  (argP - argQ)(); /* { dg-error "called object is not a function or function pointer" } */
-  argP();       /* { dg-error "called object 'argP' is not a function or function pointer" } */
-}
-
-/*
-{ dg-begin-multiline-output "" }
-   (argP - argQ)();
-   ^~~~~~~~~~~~~
-{ dg-end-multiline-output "" }
-
-{ dg-begin-multiline-output "" }
-   argP();
-   ^~~~
-{ dg-end-multiline-output "" }
-
-{ dg-begin-multiline-output "" }
- void foo(char **argP, char **argQ)
-                 ^~~~
-{ dg-end-multiline-output "" } */
diff --git a/gcc/testsuite/gcc.dg/diagnostic-ranges-2.c b/gcc/testsuite/gcc.dg/diagnostic-ranges-2.c
index 9a2f77b..fb69324 100644
--- a/gcc/testsuite/gcc.dg/diagnostic-ranges-2.c
+++ b/gcc/testsuite/gcc.dg/diagnostic-ranges-2.c
@@ -55,5 +55,28 @@ FIXME: again, we ought to highlight the specific param in the decl
 FIXME: and again, we ought to highlight the specific param in the decl
 */
 
+}
+
+/* Adapted from https://gcc.gnu.org/wiki/ClangDiagnosticsComparison */
+
+void call_of_non_function_ptr (char **argP, char **argQ)
+{
+  (argP - argQ)(); /* { dg-error "called object is not a function or function pointer" } */
+
+/* { dg-begin-multiline-output "" }
+   (argP - argQ)();
+   ^~~~~~~~~~~~~
+   { dg-end-multiline-output "" } */
+
+/* { dg-begin-multiline-output "" }
+   argP();
+   ^~~~
+   { dg-end-multiline-output "" } */
+
+  argP();       /* { dg-error "called object 'argP' is not a function or function pointer" } */
 
+/* { dg-begin-multiline-output "" }
+ void call_of_non_function_ptr (char **argP, char **argQ)
+                                       ^~~~
+   { dg-end-multiline-output "" } */
 }
-- 
1.8.5.3

