diff options
| author | Ted Kremenek <kremenek@apple.com> | 2009-02-27 17:58:43 +0000 |
|---|---|---|
| committer | Ted Kremenek <kremenek@apple.com> | 2009-02-27 17:58:43 +0000 |
| commit | 9723bcf60fe6467fe4441ed136baf671323ec1ae (patch) | |
| tree | 8e488c5e54cb700be4b6ed370177059f5dea50ac /clang | |
| parent | 96977da72c7cce3109cd787f795e586771980562 (diff) | |
| download | bcm5719-llvm-9723bcf60fe6467fe4441ed136baf671323ec1ae.tar.gz bcm5719-llvm-9723bcf60fe6467fe4441ed136baf671323ec1ae.zip | |
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>.
llvm-svn: 65642
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); +} |

