PR4287: allow a variadic prototype to make a subsequent K&R style 
definition variadic.  I'm not completely sure it's legal, but the 
standard can be interpreted as making it legal, and gcc seems to think 
it's legal, so I didn't add an extension warning.



git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@72689 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index f4bfefc..ee5132a 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -2670,9 +2670,14 @@
       // Check if we have too few/too many template arguments, based
       // on our knowledge of the function definition.
       const FunctionDecl *Def = 0;
-      if (FDecl->getBody(Context, Def) && NumArgs != Def->param_size())
-        Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments)
-          << (NumArgs > Def->param_size()) << FDecl << Fn->getSourceRange();
+      if (FDecl->getBody(Context, Def) && NumArgs != Def->param_size()) {
+        const FunctionProtoType *Proto =
+            Def->getType()->getAsFunctionProtoType();
+        if (!Proto || !(Proto->isVariadic() && NumArgs >= Def->param_size())) {
+          Diag(RParenLoc, diag::warn_call_wrong_number_of_arguments)
+            << (NumArgs > Def->param_size()) << FDecl << Fn->getSourceRange();
+        }
+      }
     }
 
     // Promote the arguments (C99 6.5.2.2p6).