summaryrefslogtreecommitdiffstats
path: root/clang/lib/Analysis/PrintfFormatString.cpp
diff options
context:
space:
mode:
authorJordan Rose <jordan_rose@apple.com>2012-05-30 21:53:13 +0000
committerJordan Rose <jordan_rose@apple.com>2012-05-30 21:53:13 +0000
commit68f6d3b1a6f4c134e0f35ed27546941b56baf4e9 (patch)
tree0f9a7fed7f051b14e19d729b77d34a3a4cdc9589 /clang/lib/Analysis/PrintfFormatString.cpp
parent05e2245fc6485c6cdd32e45d25082b08ffe27074 (diff)
downloadbcm5719-llvm-68f6d3b1a6f4c134e0f35ed27546941b56baf4e9.tar.gz
bcm5719-llvm-68f6d3b1a6f4c134e0f35ed27546941b56baf4e9.zip
Suggest '%@' for Objective-C objects in ObjC format strings.
llvm-svn: 157716
Diffstat (limited to 'clang/lib/Analysis/PrintfFormatString.cpp')
-rw-r--r--clang/lib/Analysis/PrintfFormatString.cpp24
1 files changed, 23 insertions, 1 deletions
diff --git a/clang/lib/Analysis/PrintfFormatString.cpp b/clang/lib/Analysis/PrintfFormatString.cpp
index e1049b3c685..3b3a0b176e9 100644
--- a/clang/lib/Analysis/PrintfFormatString.cpp
+++ b/clang/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);
OpenPOWER on IntegriCloud