]> granicus.if.org Git - clang/commitdiff
fix PR7885, rejecting invalid uses of __builtin_constant_p.
authorChris Lattner <sabre@nondot.org>
Tue, 12 Oct 2010 17:47:42 +0000 (17:47 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 12 Oct 2010 17:47:42 +0000 (17:47 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116317 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaChecking.cpp
test/Sema/builtins.c
test/Sema/const-eval.c

index f03e1f931032996e3ef17d69021b7c3b38a0a255..1a07a86f80cfcacbe7eeaeb3b9553de6be0e0803 100644 (file)
@@ -198,6 +198,16 @@ Sema::CheckBuiltinFunctionCall(unsigned BuiltinID, CallExpr *TheCall) {
     if (SemaBuiltinLongjmp(TheCall))
       return ExprError();
     break;
+  case Builtin::BI__builtin_constant_p:
+    if (TheCall->getNumArgs() == 0)
+      return Diag(TheCall->getLocEnd(), diag::err_typecheck_call_too_few_args)
+        << 0 /*function call*/ << 1 << 0 << TheCall->getSourceRange();
+    if (TheCall->getNumArgs() > 1)
+      return Diag(TheCall->getArg(1)->getLocStart(),
+                  diag::err_typecheck_call_too_many_args)
+        << 0 /*function call*/ << 1 << TheCall->getNumArgs()
+        << TheCall->getArg(1)->getSourceRange();
+    break;
   case Builtin::BI__sync_fetch_and_add:
   case Builtin::BI__sync_fetch_and_sub:
   case Builtin::BI__sync_fetch_and_or:
index 21a1f72e1d5f9cde08def9a8a428bad0dd3d58c1..7f284dabcd545f27ed7d38cbeecc1e6787b16d04 100644 (file)
@@ -95,3 +95,10 @@ void test14() {
 void test15(const char *s) {
   __builtin_printf("string is %s\n", s);
 }
+
+// PR7885
+int test16() {
+  return __builtin_constant_p() + // expected-error{{too few arguments}}
+         __builtin_constant_p(1, 2); // expected-error {{too many arguments}}
+}
+  
index 42097e75f317432afc39b31bcefabd3176d30cea..9f2d32769fb3a21ed00ec30a26634806042f83e1 100644 (file)
@@ -41,7 +41,7 @@ struct s {
 
 EVAL_EXPR(19, ((int)&*(char*)10 == 10 ? 1 : -1));
 
-EVAL_EXPR(20, __builtin_constant_p(*((int*) 10), -1, 1));
+EVAL_EXPR(20, __builtin_constant_p(*((int*) 10)));
 
 EVAL_EXPR(21, (__imag__ 2i) == 2 ? 1 : -1);