[cfe-commits] r65642 - in /cfe/trunk: lib/Sema/SemaChecking.cpp test/Sema/format-attribute.c

Ted Kremenek kremenek at apple.com
Fri Feb 27 09:58:43 PST 2009


Author: kremenek
Date: Fri Feb 27 11:58:43 2009
New Revision: 65642

URL: http://llvm.org/viewvc/llvm-project?rev=65642&view=rev
Log:
When checking printf-arguments for functions with '__attribute__ ((format (printf, X, Y)))'
set HasVAListArg to true when 'Y' is 0 (i.e., ignore the data arguments).

This fixes <rdar://problem/6623513>.


Modified:
    cfe/trunk/lib/Sema/SemaChecking.cpp
    cfe/trunk/test/Sema/format-attribute.c

Modified: cfe/trunk/lib/Sema/SemaChecking.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaChecking.cpp?rev=65642&r1=65641&r2=65642&view=diff

==============================================================================
--- cfe/trunk/lib/Sema/SemaChecking.cpp (original)
+++ cfe/trunk/lib/Sema/SemaChecking.cpp Fri Feb 27 11:58:43 2009
@@ -143,12 +143,14 @@
   // Printf checking.
   if (const FormatAttr *Format = FDecl->getAttr<FormatAttr>()) {
     if (Format->getType() == "printf") {
-      bool HasVAListArg = false;
-      if (const FunctionProtoType *Proto 
-          = FDecl->getType()->getAsFunctionProtoType())
+      bool HasVAListArg = Format->getFirstArg() == 0;
+      if (!HasVAListArg) {
+        if (const FunctionProtoType *Proto 
+            = FDecl->getType()->getAsFunctionProtoType())
         HasVAListArg = !Proto->isVariadic();
+      }
       CheckPrintfArguments(TheCall, HasVAListArg, Format->getFormatIdx() - 1,
-                           Format->getFirstArg() - 1);
+                           HasVAListArg ? 0 : Format->getFirstArg() - 1);
     }
   }
 

Modified: cfe/trunk/test/Sema/format-attribute.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Sema/format-attribute.c?rev=65642&r1=65641&r2=65642&view=diff

==============================================================================
--- cfe/trunk/test/Sema/format-attribute.c (original)
+++ cfe/trunk/test/Sema/format-attribute.c Fri Feb 27 11:58:43 2009
@@ -24,3 +24,11 @@
 };
 
 typedef int (*f3_ptr)(char*,...) __attribute__((format(printf,1,0))); // no-error
+
+// <rdar://problem/6623513>
+int rdar6623513(void *, const char*, const char*, ...)
+  __attribute__ ((format (printf, 3, 0)));
+
+int rdar6623513_aux(int len, const char* s) {
+  rdar6623513(0, "hello", "%.*s", len, s);
+}





More information about the cfe-commits mailing list