aboutsummaryrefslogtreecommitdiff
path: root/lib/Sema/SemaDecl.cpp
diff options
context:
space:
mode:
authorJean-Daniel Dupas <devlists@shadowlab.org>2012-01-24 22:32:46 +0000
committerJean-Daniel Dupas <devlists@shadowlab.org>2012-01-24 22:32:46 +0000
commit1acbe5e65631c7b52fa559df2bdcfdf76d4c410a (patch)
treefa28611cf7e7e4a844bf893f38d6ddb57671da37 /lib/Sema/SemaDecl.cpp
parent9bc4fc4ee96f6da0e7be3edfdedd45912e5f1161 (diff)
Replace a hack to handle NSLog/NSLogv in sema by declaring them as Library Builtins.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@148873 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaDecl.cpp')
-rw-r--r--lib/Sema/SemaDecl.cpp21
1 files changed, 9 insertions, 12 deletions
diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp
index a84612edfc..e7ff5c5400 100644
--- a/lib/Sema/SemaDecl.cpp
+++ b/lib/Sema/SemaDecl.cpp
@@ -7420,10 +7420,16 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
unsigned FormatIdx;
bool HasVAListArg;
if (Context.BuiltinInfo.isPrintfLike(BuiltinID, FormatIdx, HasVAListArg)) {
- if (!FD->getAttr<FormatAttr>())
+ if (!FD->getAttr<FormatAttr>()) {
+ const char *fmt = "printf";
+ unsigned int NumParams = FD->getNumParams();
+ if (FormatIdx < NumParams && // NumParams may be 0 (e.g. vfprintf)
+ FD->getParamDecl(FormatIdx)->getType()->isObjCObjectPointerType())
+ fmt = "NSString";
FD->addAttr(::new (Context) FormatAttr(FD->getLocation(), Context,
- "printf", FormatIdx+1,
+ fmt, FormatIdx+1,
HasVAListArg ? 0 : FormatIdx+2));
+ }
}
if (Context.BuiltinInfo.isScanfLike(BuiltinID, FormatIdx,
HasVAListArg)) {
@@ -7464,16 +7470,7 @@ void Sema::AddKnownFunctionAttributes(FunctionDecl *FD) {
} else
return;
- if (Name->isStr("NSLog") || Name->isStr("NSLogv")) {
- // FIXME: NSLog and NSLogv should be target specific
- if (const FormatAttr *Format = FD->getAttr<FormatAttr>()) {
- // FIXME: We known better than our headers.
- const_cast<FormatAttr *>(Format)->setType(Context, "printf");
- } else
- FD->addAttr(::new (Context) FormatAttr(FD->getLocation(), Context,
- "printf", 1,
- Name->isStr("NSLogv") ? 0 : 2));
- } else if (Name->isStr("asprintf") || Name->isStr("vasprintf")) {
+ if (Name->isStr("asprintf") || Name->isStr("vasprintf")) {
// FIXME: asprintf and vasprintf aren't C99 functions. Should they be
// target-specific builtins, perhaps?
if (!FD->getAttr<FormatAttr>())