summaryrefslogtreecommitdiffstats
path: root/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
diff options
context:
space:
mode:
authorDevin Coughlin <dcoughlin@apple.com>2016-03-01 00:39:04 +0000
committerDevin Coughlin <dcoughlin@apple.com>2016-03-01 00:39:04 +0000
commit6d0c8a036e1f6eabae4962b711836920f1a354e3 (patch)
tree53cf343d2a1e7f2f9832fc625763f56ab047f1b7 /clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
parentaafe4b63d98fd596625763064250d4ebd7af2dcd (diff)
downloadbcm5719-llvm-6d0c8a036e1f6eabae4962b711836920f1a354e3.tar.gz
bcm5719-llvm-6d0c8a036e1f6eabae4962b711836920f1a354e3.zip
[analyzer] Update CheckObjCDealloc diagnostic for missing -dealloc.
Update the diagnostic for classes missing -dealloc to mention an instance variable that needs to be released. llvm-svn: 262277
Diffstat (limited to 'clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp')
-rw-r--r--clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp28
1 files changed, 18 insertions, 10 deletions
diff --git a/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp b/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
index ea64d9b3d73..c09924cfc2e 100644
--- a/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
+++ b/clang/lib/StaticAnalyzer/Checkers/CheckObjCDealloc.cpp
@@ -190,23 +190,27 @@ void ObjCDeallocChecker::checkASTDecl(const ObjCImplementationDecl *D,
initIdentifierInfoAndSelectors(Mgr.getASTContext());
const ObjCInterfaceDecl *ID = D->getClassInterface();
+ // If the class is known to have a lifecycle with a separate teardown method
+ // then it may not require a -dealloc method.
+ if (classHasSeparateTeardown(ID))
+ return;
// Does the class contain any synthesized properties that are retainable?
// If not, skip the check entirely.
- bool containsRetainedSynthesizedProperty = false;
+ const ObjCPropertyImplDecl *PropImplRequiringRelease = nullptr;
+ bool HasOthers = false;
for (const auto *I : D->property_impls()) {
if (getDeallocReleaseRequirement(I) == ReleaseRequirement::MustRelease) {
- containsRetainedSynthesizedProperty = true;
- break;
+ if (!PropImplRequiringRelease)
+ PropImplRequiringRelease = I;
+ else {
+ HasOthers = true;
+ break;
+ }
}
}
- if (!containsRetainedSynthesizedProperty)
- return;
-
- // If the class is known to have a lifecycle with a separate teardown method
- // then it may not require a -dealloc method.
- if (classHasSeparateTeardown(ID))
+ if (!PropImplRequiringRelease)
return;
const ObjCMethodDecl *MD = nullptr;
@@ -224,8 +228,12 @@ void ObjCDeallocChecker::checkASTDecl(const ObjCImplementationDecl *D,
std::string Buf;
llvm::raw_string_ostream OS(Buf);
- OS << "Objective-C class '" << *D << "' lacks a 'dealloc' instance method";
+ OS << "'" << *D << "' lacks a 'dealloc' instance method but "
+ << "must release '" << *PropImplRequiringRelease->getPropertyIvarDecl()
+ << "'";
+ if (HasOthers)
+ OS << " and others";
PathDiagnosticLocation DLoc =
PathDiagnosticLocation::createBegin(D, BR.getSourceManager());
OpenPOWER on IntegriCloud