[clang] 260b91f - Use getLocation() in "too few/too many arguments" diagnostic

Aaron Ballman via cfe-commits cfe-commits at lists.llvm.org
Tue Feb 18 08:23:37 PST 2020


Author: John Marshall
Date: 2020-02-18T11:23:17-05:00
New Revision: 260b91f379c8f86d3d6008648b3f2a945a007888

URL: https://github.com/llvm/llvm-project/commit/260b91f379c8f86d3d6008648b3f2a945a007888
DIFF: https://github.com/llvm/llvm-project/commit/260b91f379c8f86d3d6008648b3f2a945a007888.diff

LOG: Use getLocation() in "too few/too many arguments" diagnostic

Use the more accurate location when emitting the location of the
function being called's prototype in diagnostics emitted when calling
a function with an incorrect number of arguments.

In particular, avoids showing a trace of irrelevant macro expansions
for "MY_EXPORT static int AwesomeFunction(int, int);". Fixes PR#23564.

Added: 
    

Modified: 
    clang/lib/Sema/SemaExpr.cpp
    clang/test/Misc/serialized-diags.c
    clang/test/Sema/exprs.c

Removed: 
    


################################################################################
diff  --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp
index 3a1865124199..591d079784fe 100644
--- a/clang/lib/Sema/SemaExpr.cpp
+++ b/clang/lib/Sema/SemaExpr.cpp
@@ -5195,7 +5195,7 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
 
       // Emit the location of the prototype.
       if (!TC && FDecl && !FDecl->getBuiltinID() && !IsExecConfig)
-        Diag(FDecl->getBeginLoc(), diag::note_callee_decl) << FDecl;
+        Diag(FDecl->getLocation(), diag::note_callee_decl) << FDecl;
 
       return true;
     }
@@ -5240,7 +5240,7 @@ Sema::ConvertArgumentsForCall(CallExpr *Call, Expr *Fn,
 
       // Emit the location of the prototype.
       if (!TC && FDecl && !FDecl->getBuiltinID() && !IsExecConfig)
-        Diag(FDecl->getBeginLoc(), diag::note_callee_decl) << FDecl;
+        Diag(FDecl->getLocation(), diag::note_callee_decl) << FDecl;
 
       // This deletes the extra arguments.
       Call->shrinkNumArgs(NumParams);

diff  --git a/clang/test/Misc/serialized-diags.c b/clang/test/Misc/serialized-diags.c
index e401477a2ebd..2f4b86fb42f9 100644
--- a/clang/test/Misc/serialized-diags.c
+++ b/clang/test/Misc/serialized-diags.c
@@ -56,7 +56,7 @@ void rdar11040133() {
 // CHECK: Range: {{.*[/\\]}}serialized-diags.c:22:13 {{.*[/\\]}}serialized-diags.c:22:18
 // CHECK: +-{{.*[/\\]}}serialized-diags.c:20:15: note: expanded from macro 'false' []
 // CHECK: +-Range: {{.*[/\\]}}serialized-diags.c:20:15 {{.*[/\\]}}serialized-diags.c:20:16
-// CHECK: +-{{.*[/\\]}}serialized-diags.c:19:1: note: 'taz' declared here []
+// CHECK: +-{{.*[/\\]}}serialized-diags.c:19:6: note: 'taz' declared here []
 // CHECK: {{.*[/\\]}}serialized-diags.h:5:7: warning: incompatible integer to pointer conversion initializing 'char *' with an expression of type 'int' [-Wint-conversion]
 // CHECK: Range: {{.*[/\\]}}serialized-diags.h:5:16 {{.*[/\\]}}serialized-diags.h:5:17
 // CHECK: +-{{.*[/\\]}}serialized-diags.c:26:10: note: in file included from {{.*[/\\]}}serialized-diags.c:26: []

diff  --git a/clang/test/Sema/exprs.c b/clang/test/Sema/exprs.c
index 760c45e02f37..4e144041acae 100644
--- a/clang/test/Sema/exprs.c
+++ b/clang/test/Sema/exprs.c
@@ -163,12 +163,15 @@ void test17(int x) {
   x = sizeof(x/0);  // no warning.
 }
 
-// PR6501 & PR11857
+// PR6501, PR11857, and PR23564
 void test18_a(int a); // expected-note 2 {{'test18_a' declared here}}
 void test18_b(int); // expected-note {{'test18_b' declared here}}
 void test18_c(int a, int b); // expected-note 2 {{'test18_c' declared here}}
 void test18_d(int a, ...); // expected-note {{'test18_d' declared here}}
 void test18_e(int a, int b, ...); // expected-note {{'test18_e' declared here}}
+#define MY_EXPORT __attribute__((visibility("default")))
+MY_EXPORT void // (no "declared here" notes on this line, no "expanded from MY_EXPORT" notes either)
+test18_f(int a, int b); // expected-note 2 {{'test18_f' declared here}}
 void test18(int b) {
   test18_a(b, b); // expected-error {{too many arguments to function call, expected single argument 'a', have 2}}
   test18_a(); // expected-error {{too few arguments to function call, single argument 'a' was not specified}}
@@ -177,6 +180,8 @@ void test18(int b) {
   test18_c(b, b, b); // expected-error {{too many arguments to function call, expected 2, have 3}}
   test18_d(); // expected-error {{too few arguments to function call, at least argument 'a' must be specified}}
   test18_e(); // expected-error {{too few arguments to function call, expected at least 2, have 0}}
+  test18_f(b); // expected-error {{too few arguments to function call, expected 2, have 1}}
+  test18_f(b, b, b); // expected-error {{too many arguments to function call, expected 2, have 3}}
 }
 
 typedef int __attribute__((address_space(256))) int_AS256;


        


More information about the cfe-commits mailing list