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>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@65642 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaChecking.cpp b/lib/Sema/SemaChecking.cpp
index 3e6bd5a..b0d6901 100644
--- a/lib/Sema/SemaChecking.cpp
+++ b/lib/Sema/SemaChecking.cpp
@@ -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);
}
}