From f9fd6c4b8754db886a329aa21a956b1e3d267cc5 Mon Sep 17 00:00:00 2001
From: David Malcolm <dmalcolm@redhat.com>
Date: Fri, 4 Sep 2015 04:31:36 -0400
Subject: [PATCH 36/63] FIXME: C FE: Use tree ranges for call of
 non-function-ptr error (convert location hack gcc.dg/20150303-01.c to a
 non-hack example)

Testcase failure: for some reasons param isn't being underlined in decl.
---
 gcc/c/c-typeck.c                                   | 12 +++++++-----
 gcc/location-hacks.c                               |  7 -------
 gcc/testsuite/gcc.dg/diagnostic-tree-expr-ranges.c | 22 ++++++++++++++++++++++
 3 files changed, 29 insertions(+), 12 deletions(-)

diff --git a/gcc/c/c-typeck.c b/gcc/c/c-typeck.c
index f984ee9..1706867 100644
--- a/gcc/c/c-typeck.c
+++ b/gcc/c/c-typeck.c
@@ -2873,6 +2873,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);
@@ -2921,13 +2922,13 @@ build_function_call_vec (location_t loc, vec<location_t> arg_loc,
 		  function);
       else if (DECL_P (function))
 	{
-	  error_at (loc,
+	  error_at (func_range,
 		    "called object %qD is not a function or function pointer",
 		    function);
 	  inform_declaration (function);
 	}
       else
-	error_at (loc,
+	error_at (func_range,
 		  "called object is not a function or function pointer");
       return error_mark_node;
     }
@@ -2958,11 +2959,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");
      }
 
@@ -2999,7 +3001,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 08e0596..20040e5 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/diagnostic-tree-expr-ranges.c b/gcc/testsuite/gcc.dg/diagnostic-tree-expr-ranges.c
index 9a2f77b..f6e564c 100644
--- a/gcc/testsuite/gcc.dg/diagnostic-tree-expr-ranges.c
+++ b/gcc/testsuite/gcc.dg/diagnostic-tree-expr-ranges.c
@@ -55,5 +55,27 @@ 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 "" } */
+
+  argP();       /* { dg-error "called object 'argP' is not a function or function pointer" } */
 
+/* { dg-begin-multiline-output "" }
+   argP();
+   ^~~~
+   { dg-end-multiline-output "" }
+   { dg-begin-multiline-output "" }
+ void call_of_non_function_ptr (char **argP, char **argQ)
+                                       ^~~~
+   { dg-end-multiline-output "" } */
 }
-- 
1.8.5.3

