[PATCH] D74087: [Sema] Fix Sema checkArgCount function

2020-02-06 Thread Baptiste Saleil via Phabricator via cfe-commits
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


[PATCH] D74087: [Sema] Fix Sema checkArgCount function

2020-02-06 Thread Yi-Hong Lyu via Phabricator via cfe-commits
Yi-Hong.Lyu requested changes to this revision.
Yi-Hong.Lyu added a comment.
This revision now requires changes to proceed.

Please add tests


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D74087



___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[PATCH] D74087: [Sema] Fix Sema checkArgCount function

2020-02-05 Thread Baptiste Saleil via Phabricator via cfe-commits
bsaleil created this revision.
bsaleil added a reviewer: rsmith.
bsaleil added a project: clang.
Herald added a subscriber: cfe-commits.

This patch fixes the checkArgCount function in Sema that is used to check the 
number of arguments of a call when doing custom type-checking.
The patch fixes that function in two ways:

1. It now displays the right range in case the number of actual arguments is 
greater than the number of expected arguments
2. It allows the function to properly handle the case in which the desired 
argument count is 0 and the number of actual arguments is 1


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D74087

Files:
  clang/lib/Sema/SemaChecking.cpp


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -122,7 +122,7 @@
 
   return S.Diag(range.getBegin(), diag::err_typecheck_call_too_many_args)
 << 0 /*function call*/ << desiredArgCount << argCount
-<< call->getArg(1)->getSourceRange();
+<< range;
 }
 
 /// Check that the first argument to __builtin_annotation is an integer


Index: clang/lib/Sema/SemaChecking.cpp
===
--- clang/lib/Sema/SemaChecking.cpp
+++ clang/lib/Sema/SemaChecking.cpp
@@ -122,7 +122,7 @@
 
   return S.Diag(range.getBegin(), diag::err_typecheck_call_too_many_args)
 << 0 /*function call*/ << desiredArgCount << argCount
-<< call->getArg(1)->getSourceRange();
+<< 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