diff options
Diffstat (limited to 'contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp')
-rw-r--r-- | contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp | 97 |
1 files changed, 45 insertions, 52 deletions
diff --git a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp index cc940be..1926600 100644 --- a/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp +++ b/contrib/llvm/tools/clang/lib/StaticAnalyzer/Checkers/IvarInvalidationChecker.cpp @@ -49,6 +49,9 @@ struct ChecksFilter { DefaultBool check_MissingInvalidationMethod; /// Check that all ivars are invalidated. DefaultBool check_InstanceVariableInvalidation; + + CheckName checkName_MissingInvalidationMethod; + CheckName checkName_InstanceVariableInvalidation; }; class IvarInvalidationCheckerImpl { @@ -154,7 +157,7 @@ class IvarInvalidationCheckerImpl { PropertySetterToIvarMap(InPropertySetterToIvarMap), PropertyGetterToIvarMap(InPropertyGetterToIvarMap), PropertyToIvarMap(InPropertyToIvarMap), - InvalidationMethod(0), + InvalidationMethod(nullptr), Ctx(InCtx) {} void VisitStmt(const Stmt *S) { VisitChildren(S); } @@ -200,7 +203,8 @@ class IvarInvalidationCheckerImpl { const ObjCIvarDecl *IvarDecl, const IvarToPropMapTy &IvarToPopertyMap); - void reportNoInvalidationMethod(const ObjCIvarDecl *FirstIvarDecl, + void reportNoInvalidationMethod(CheckName CheckName, + const ObjCIvarDecl *FirstIvarDecl, const IvarToPropMapTy &IvarToPopertyMap, const ObjCInterfaceDecl *InterfaceD, bool MissingDeclaration) const; @@ -223,10 +227,7 @@ public: }; static bool isInvalidationMethod(const ObjCMethodDecl *M, bool LookForPartial) { - for (specific_attr_iterator<AnnotateAttr> - AI = M->specific_attr_begin<AnnotateAttr>(), - AE = M->specific_attr_end<AnnotateAttr>(); AI != AE; ++AI) { - const AnnotateAttr *Ann = *AI; + for (const auto *Ann : M->specific_attrs<AnnotateAttr>()) { if (!LookForPartial && Ann->getAnnotation() == "objc_instance_variable_invalidator") return true; @@ -247,33 +248,22 @@ void IvarInvalidationCheckerImpl::containsInvalidationMethod( // TODO: Cache the results. // Check all methods. - for (ObjCContainerDecl::method_iterator - I = D->meth_begin(), - E = D->meth_end(); I != E; ++I) { - const ObjCMethodDecl *MDI = *I; - if (isInvalidationMethod(MDI, Partial)) - OutInfo.addInvalidationMethod( - cast<ObjCMethodDecl>(MDI->getCanonicalDecl())); - } + for (const auto *MDI : D->methods()) + if (isInvalidationMethod(MDI, Partial)) + OutInfo.addInvalidationMethod( + cast<ObjCMethodDecl>(MDI->getCanonicalDecl())); // If interface, check all parent protocols and super. if (const ObjCInterfaceDecl *InterfD = dyn_cast<ObjCInterfaceDecl>(D)) { // Visit all protocols. - for (ObjCInterfaceDecl::protocol_iterator - I = InterfD->protocol_begin(), - E = InterfD->protocol_end(); I != E; ++I) { - containsInvalidationMethod((*I)->getDefinition(), OutInfo, Partial); - } + for (const auto *I : InterfD->protocols()) + containsInvalidationMethod(I->getDefinition(), OutInfo, Partial); // Visit all categories in case the invalidation method is declared in // a category. - for (ObjCInterfaceDecl::visible_extensions_iterator - Ext = InterfD->visible_extensions_begin(), - ExtEnd = InterfD->visible_extensions_end(); - Ext != ExtEnd; ++Ext) { - containsInvalidationMethod(*Ext, OutInfo, Partial); - } + for (const auto *Ext : InterfD->visible_extensions()) + containsInvalidationMethod(Ext, OutInfo, Partial); containsInvalidationMethod(InterfD->getSuperClass(), OutInfo, Partial); return; @@ -281,10 +271,8 @@ void IvarInvalidationCheckerImpl::containsInvalidationMethod( // If protocol, check all parent protocols. if (const ObjCProtocolDecl *ProtD = dyn_cast<ObjCProtocolDecl>(D)) { - for (ObjCInterfaceDecl::protocol_iterator - I = ProtD->protocol_begin(), - E = ProtD->protocol_end(); I != E; ++I) { - containsInvalidationMethod((*I)->getDefinition(), OutInfo, Partial); + for (const auto *I : ProtD->protocols()) { + containsInvalidationMethod(I->getDefinition(), OutInfo, Partial); } return; } @@ -318,7 +306,7 @@ const ObjCIvarDecl *IvarInvalidationCheckerImpl::findPropertyBackingIvar( const ObjCInterfaceDecl *InterfaceD, IvarSet &TrackedIvars, const ObjCIvarDecl **FirstIvarDecl) { - const ObjCIvarDecl *IvarD = 0; + const ObjCIvarDecl *IvarD = nullptr; // Lookup for the synthesized case. IvarD = Prop->getPropertyIvarDecl(); @@ -355,7 +343,7 @@ const ObjCIvarDecl *IvarInvalidationCheckerImpl::findPropertyBackingIvar( // Note, this is a possible source of false positives. We could look at the // getter implementation to find the ivar when its name is not derived from // the property name. - return 0; + return nullptr; } void IvarInvalidationCheckerImpl::printIvar(llvm::raw_svector_ostream &os, @@ -379,7 +367,7 @@ visit(const ObjCImplementationDecl *ImplD) const { // Record the first Ivar needing invalidation; used in reporting when only // one ivar is sufficient. Cannot grab the first on the Ivars set to ensure // deterministic output. - const ObjCIvarDecl *FirstIvarDecl = 0; + const ObjCIvarDecl *FirstIvarDecl = nullptr; const ObjCInterfaceDecl *InterfaceD = ImplD->getClassInterface(); // Collect ivars declared in this class, its extensions and its implementation @@ -476,7 +464,8 @@ visit(const ObjCImplementationDecl *ImplD) const { // Report an error in case none of the invalidation methods are declared. if (!Info.needsInvalidation() && !PartialInfo.needsInvalidation()) { if (Filter.check_MissingInvalidationMethod) - reportNoInvalidationMethod(FirstIvarDecl, IvarToPopertyMap, InterfaceD, + reportNoInvalidationMethod(Filter.checkName_MissingInvalidationMethod, + FirstIvarDecl, IvarToPopertyMap, InterfaceD, /*MissingDeclaration*/ true); // If there are no invalidation methods, there is no ivar validation work // to be done. @@ -529,20 +518,20 @@ visit(const ObjCImplementationDecl *ImplD) const { // invalidation methods. for (IvarSet::const_iterator I = Ivars.begin(), E = Ivars.end(); I != E; ++I) - reportIvarNeedsInvalidation(I->first, IvarToPopertyMap, 0); + reportIvarNeedsInvalidation(I->first, IvarToPopertyMap, nullptr); } else { // Otherwise, no invalidation methods were implemented. - reportNoInvalidationMethod(FirstIvarDecl, IvarToPopertyMap, InterfaceD, + reportNoInvalidationMethod(Filter.checkName_InstanceVariableInvalidation, + FirstIvarDecl, IvarToPopertyMap, InterfaceD, /*MissingDeclaration*/ false); } } } -void IvarInvalidationCheckerImpl:: -reportNoInvalidationMethod(const ObjCIvarDecl *FirstIvarDecl, - const IvarToPropMapTy &IvarToPopertyMap, - const ObjCInterfaceDecl *InterfaceD, - bool MissingDeclaration) const { +void IvarInvalidationCheckerImpl::reportNoInvalidationMethod( + CheckName CheckName, const ObjCIvarDecl *FirstIvarDecl, + const IvarToPropMapTy &IvarToPopertyMap, + const ObjCInterfaceDecl *InterfaceD, bool MissingDeclaration) const { SmallString<128> sbuf; llvm::raw_svector_ostream os(sbuf); assert(FirstIvarDecl); @@ -557,7 +546,7 @@ reportNoInvalidationMethod(const ObjCIvarDecl *FirstIvarDecl, PathDiagnosticLocation IvarDecLocation = PathDiagnosticLocation::createBegin(FirstIvarDecl, BR.getSourceManager()); - BR.EmitBasicReport(FirstIvarDecl, "Incomplete invalidation", + BR.EmitBasicReport(FirstIvarDecl, CheckName, "Incomplete invalidation", categories::CoreFoundationObjectiveC, os.str(), IvarDecLocation); } @@ -575,15 +564,16 @@ reportIvarNeedsInvalidation(const ObjCIvarDecl *IvarD, PathDiagnosticLocation::createEnd(MethodD->getBody(), BR.getSourceManager(), Mgr.getAnalysisDeclContext(MethodD)); - BR.EmitBasicReport(MethodD, "Incomplete invalidation", + BR.EmitBasicReport(MethodD, Filter.checkName_InstanceVariableInvalidation, + "Incomplete invalidation", categories::CoreFoundationObjectiveC, os.str(), MethodDecLocation); } else { - BR.EmitBasicReport(IvarD, "Incomplete invalidation", - categories::CoreFoundationObjectiveC, os.str(), - PathDiagnosticLocation::createBegin(IvarD, - BR.getSourceManager())); - + BR.EmitBasicReport( + IvarD, Filter.checkName_InstanceVariableInvalidation, + "Incomplete invalidation", categories::CoreFoundationObjectiveC, + os.str(), + PathDiagnosticLocation::createBegin(IvarD, BR.getSourceManager())); } } @@ -727,7 +717,7 @@ void IvarInvalidationCheckerImpl::MethodCrawler::VisitObjCMessageExpr( if (Receiver) { InvalidationMethod = MD; check(Receiver->IgnoreParenCasts()); - InvalidationMethod = 0; + InvalidationMethod = nullptr; } VisitStmt(ME); @@ -750,10 +740,13 @@ public: }; } -#define REGISTER_CHECKER(name) \ -void ento::register##name(CheckerManager &mgr) {\ - mgr.registerChecker<IvarInvalidationChecker>()->Filter.check_##name = true;\ -} +#define REGISTER_CHECKER(name) \ + void ento::register##name(CheckerManager &mgr) { \ + IvarInvalidationChecker *checker = \ + mgr.registerChecker<IvarInvalidationChecker>(); \ + checker->Filter.check_##name = true; \ + checker->Filter.checkName_##name = mgr.getCurrentCheckName(); \ + } REGISTER_CHECKER(InstanceVariableInvalidation) REGISTER_CHECKER(MissingInvalidationMethod) |