diff options
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Sema/SemaChecking.cpp | 10 | ||||
-rw-r--r-- | clang/test/Sema/format-attribute.c | 8 |
2 files changed, 14 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaChecking.cpp b/clang/lib/Sema/SemaChecking.cpp index 3e6bd5a2efb..b0d6901953f 100644 --- a/clang/lib/Sema/SemaChecking.cpp +++ b/clang/lib/Sema/SemaChecking.cpp @@ -143,12 +143,14 @@ Sema::CheckFunctionCall(FunctionDecl *FDecl, CallExpr *TheCall) { // 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); } } diff --git a/clang/test/Sema/format-attribute.c b/clang/test/Sema/format-attribute.c index ecdef9dde1a..a1cd0b84b37 100644 --- a/clang/test/Sema/format-attribute.c +++ b/clang/test/Sema/format-attribute.c @@ -24,3 +24,11 @@ struct _mystruct { }; 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); +} |