]> granicus.if.org Git - clang/commitdiff
Get rid of bogus warnings when the second argument in va_start is either an implicit...
authorAnders Carlsson <andersca@mac.com>
Mon, 11 Feb 2008 04:20:54 +0000 (04:20 +0000)
committerAnders Carlsson <andersca@mac.com>
Mon, 11 Feb 2008 04:20:54 +0000 (04:20 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@46950 91177308-0d34-0410-b5e6-96231b3b80d8

Sema/SemaChecking.cpp
test/Sema/varargs.c

index 470211d9abee599d886502312bc1ce68b457aabd..76363c9dc0a358b90c67686ab20a4ba9e36b38fb 100644 (file)
@@ -149,11 +149,21 @@ bool Sema::SemaBuiltinVAStart(CallExpr *TheCall) {
   // Verify that the second argument to the builtin is the last argument of the
   // current function or method.
   bool SecondArgIsLastNamedArgument = false;
-  if (DeclRefExpr *DR = dyn_cast<DeclRefExpr>(TheCall->getArg(1))) {
-    if (ParmVarDecl *PV = dyn_cast<ParmVarDecl>(DR->getDecl())) {
+  const Expr *Arg = TheCall->getArg(1);
+  while (1) {
+    if (const ParenExpr *PE = dyn_cast<ParenExpr>(Arg))
+      Arg = PE->getSubExpr();
+    else if (const ImplicitCastExpr *CE = dyn_cast<ImplicitCastExpr>(Arg))
+      Arg = CE->getSubExpr();
+    else
+      break;
+  }
+  
+  if (const DeclRefExpr *DR = dyn_cast<DeclRefExpr>(Arg)) {
+    if (const ParmVarDecl *PV = dyn_cast<ParmVarDecl>(DR->getDecl())) {
       // FIXME: This isn't correct for methods (results in bogus warning).
       // Get the last formal in the current function.
-      ParmVarDecl *LastArg;
+      const ParmVarDecl *LastArg;
       if (CurFunctionDecl)
         LastArg = *(CurFunctionDecl->param_end()-1);
       else
index 92faf9ff50b3c19b5787da5ba88e50987da66065..f52921c5fca6dac0f9e608c80099ce9b7a573153 100644 (file)
@@ -16,3 +16,11 @@ void f2(int a, int b, ...)
     __builtin_va_start(ap, a); // expected-warning {{second parameter of 'va_start' not last named argument}}
     __builtin_va_start(ap, b);
 }
+
+void f3(float a, ...)
+{
+    __builtin_va_list ap;
+    
+    __builtin_va_start(ap, a);
+    __builtin_va_start(ap, (a));
+}