diff options
author | Jordan Rose <jordan_rose@apple.com> | 2012-05-30 21:53:13 +0000 |
---|---|---|
committer | Jordan Rose <jordan_rose@apple.com> | 2012-05-30 21:53:13 +0000 |
commit | 153acdb7310b20a72e608cbb10946621f161eb70 (patch) | |
tree | ecd45b50745a14c25a02509401a7fa2e1b0f30b4 /lib/Analysis/PrintfFormatString.cpp | |
parent | abe21e36d789cfe800562a1e889738addfd2ac5b (diff) |
Suggest '%@' for Objective-C objects in ObjC format strings.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@157716 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Analysis/PrintfFormatString.cpp')
-rw-r--r-- | lib/Analysis/PrintfFormatString.cpp | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/lib/Analysis/PrintfFormatString.cpp b/lib/Analysis/PrintfFormatString.cpp index e1049b3c68..3b3a0b176e 100644 --- a/lib/Analysis/PrintfFormatString.cpp +++ b/lib/Analysis/PrintfFormatString.cpp @@ -342,7 +342,29 @@ ArgTypeResult PrintfSpecifier::getArgType(ASTContext &Ctx, bool PrintfSpecifier::fixType(QualType QT, const LangOptions &LangOpt, ASTContext &Ctx, bool IsObjCLiteral) { - // Handle strings first (char *, wchar_t *) + // Handle Objective-C objects first. Note that while the '%@' specifier will + // not warn for structure pointer or void pointer arguments (because that's + // how CoreFoundation objects are implemented), we only show a fixit for '%@' + // if we know it's an object (block, id, class, or __attribute__((NSObject))). + if (QT->isObjCRetainableType()) { + if (!IsObjCLiteral) + return false; + + CS.setKind(ConversionSpecifier::ObjCObjArg); + + // Disable irrelevant flags + HasThousandsGrouping = false; + HasPlusPrefix = false; + HasSpacePrefix = false; + HasAlternativeForm = false; + HasLeadingZeroes = false; + Precision.setHowSpecified(OptionalAmount::NotSpecified); + LM.setKind(LengthModifier::None); + + return true; + } + + // Handle strings next (char *, wchar_t *) if (QT->isPointerType() && (QT->getPointeeType()->isAnyCharacterType())) { CS.setKind(ConversionSpecifier::sArg); |