bsaleil updated this revision to Diff 242963.
bsaleil added a comment.

Adding test case


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D74087/new/

https://reviews.llvm.org/D74087

Files:
  clang/lib/Sema/SemaChecking.cpp
  clang/test/Sema/custom-checking.c


Index: clang/test/Sema/custom-checking.c
===================================================================
--- /dev/null
+++ clang/test/Sema/custom-checking.c
@@ -0,0 +1,29 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s -strict-whitespace
+
+int few_args() {
+  int r = 0;
+  __builtin_add_overflow(1, 2);
+  return r;
+}
+
+// CHECK: error: too few arguments to function call, expected 3, have 2
+// CHECK:   __builtin_add_overflow(1, 2);
+// CHECK:   ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
+
+int many_args() {
+  int r = 0;
+  __builtin_add_overflow(1, 2, &r, 3, 4, 5, 6);
+  return r;
+}
+
+// CHECK: error: too many arguments to function call, expected 3, have 7
+// CHECK:   __builtin_add_overflow(1, 2, &r, 3, 4, 5, 6);
+// CHECK:                                    ^~~~~~~~~~
+
+int equal_args() {
+  int r = 0;
+  __builtin_add_overflow(1, 2, &r);
+  return r;
+}
+
+// CHECK: 2 errors generated.
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -121,8 +121,7 @@
                     call->getArg(argCount - 1)->getEndLoc());
 
   return S.Diag(range.getBegin(), diag::err_typecheck_call_too_many_args)
-    << 0 /*function call*/ << desiredArgCount << argCount
-    << call->getArg(1)->getSourceRange();
+    << 0 /*function call*/ << desiredArgCount << argCount << range;
 }
 
 /// Check that the first argument to __builtin_annotation is an integer


Index: clang/test/Sema/custom-checking.c
===================================================================
--- /dev/null
+++ clang/test/Sema/custom-checking.c
@@ -0,0 +1,29 @@
+// RUN: not %clang_cc1 -fsyntax-only %s 2>&1 | FileCheck %s -strict-whitespace
+
+int few_args() {
+  int r = 0;
+  __builtin_add_overflow(1, 2);
+  return r;
+}
+
+// CHECK: error: too few arguments to function call, expected 3, have 2
+// CHECK:   __builtin_add_overflow(1, 2);
+// CHECK:   ~~~~~~~~~~~~~~~~~~~~~~~~~~~^
+
+int many_args() {
+  int r = 0;
+  __builtin_add_overflow(1, 2, &r, 3, 4, 5, 6);
+  return r;
+}
+
+// CHECK: error: too many arguments to function call, expected 3, have 7
+// CHECK:   __builtin_add_overflow(1, 2, &r, 3, 4, 5, 6);
+// CHECK:                                    ^~~~~~~~~~
+
+int equal_args() {
+  int r = 0;
+  __builtin_add_overflow(1, 2, &r);
+  return r;
+}
+
+// CHECK: 2 errors generated.
Index: clang/lib/Sema/SemaChecking.cpp
===================================================================
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -121,8 +121,7 @@
                     call->getArg(argCount - 1)->getEndLoc());
 
   return S.Diag(range.getBegin(), diag::err_typecheck_call_too_many_args)
-    << 0 /*function call*/ << desiredArgCount << argCount
-    << call->getArg(1)->getSourceRange();
+    << 0 /*function call*/ << desiredArgCount << argCount << range;
 }
 
 /// Check that the first argument to __builtin_annotation is an integer
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to