From: Eli Friedman Date: Wed, 10 Jun 2009 04:01:38 +0000 (+0000) Subject: PR4350: Make sure we don't create invalid printf attributes. This isn't X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=d7dad72aa5d98194dc19601a435765c94444ba3b;p=clang PR4350: Make sure we don't create invalid printf attributes. This isn't visible anywhere normally because the printf format checks for this case, and we don't print out attribute values anywhere. Original patch by Roberto Bagnara. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@73157 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index c67af295c1..3a4aeb79a1 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3208,7 +3208,7 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) { if (Context.BuiltinInfo.isPrintfLike(BuiltinID, FormatIdx, HasVAListArg)) { if (!FD->getAttr()) FD->addAttr(::new (Context) FormatAttr("printf", FormatIdx + 1, - FormatIdx + 2)); + HasVAListArg ? 0 : FormatIdx + 2)); } // Mark const if we don't care about errno and that is the only @@ -3239,10 +3239,12 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) { // FIXME: We known better than our headers. const_cast(Format)->setType("printf"); } else - FD->addAttr(::new (Context) FormatAttr("printf", 1, 2)); + FD->addAttr(::new (Context) FormatAttr("printf", 1, + Name->isStr("NSLogv") ? 0 : 2)); } else if (Name->isStr("asprintf") || Name->isStr("vasprintf")) { if (!FD->getAttr()) - FD->addAttr(::new (Context) FormatAttr("printf", 2, 3)); + FD->addAttr(::new (Context) FormatAttr("printf", 2, + Name->isStr("vasprintf") ? 0 : 3)); } }