[PATCH] D74087: [Sema] Fix Sema checkArgCount function
Baptiste Saleil via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Feb 6 11:26:23 PST 2020
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
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D74087.242963.patch
Type: text/x-patch
Size: 1503 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200206/878aacfd/attachment.bin>
More information about the cfe-commits
mailing list