diff options
Diffstat (limited to 'clang/include')
-rw-r--r-- | clang/include/clang/StaticAnalyzer/Checkers/Checkers.td | 3 | ||||
-rw-r--r-- | clang/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h | 47 |
2 files changed, 47 insertions, 3 deletions
diff --git a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td index 2933c3e855f..9feb5a87668 100644 --- a/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td +++ b/clang/include/clang/StaticAnalyzer/Checkers/Checkers.td @@ -520,6 +520,9 @@ def MacOSKeychainAPIChecker : Checker<"SecKeychainAPI">, def ObjCPropertyChecker : Checker<"ObjCProperty">, HelpText<"Check for proper uses of Objective-C properties">; +def OSObjectRetainCountChecker : Checker<"OSObjectRetainCount">, + HelpText<"Check for leaks and improper reference count management for OSObject">; + } // end "osx" let ParentPackage = Cocoa in { diff --git a/clang/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h b/clang/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h index c2e9eaa6220..de16a1781a0 100644 --- a/clang/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h +++ b/clang/include/clang/StaticAnalyzer/Core/RetainSummaryManager.h @@ -469,6 +469,8 @@ public: } }; +class RetainSummaryTemplate; + class RetainSummaryManager { typedef llvm::DenseMap<const FunctionDecl*, const RetainSummary *> FuncSummariesTy; @@ -483,7 +485,10 @@ class RetainSummaryManager { /// Records whether or not the analyzed code runs in ARC mode. const bool ARCEnabled; - /// Track sublcasses of OSObject + /// Track Objective-C and CoreFoundation objects. + const bool TrackObjCAndCFObjects; + + /// Track sublcasses of OSObject. const bool TrackOSObjects; /// FuncSummaries - A map from FunctionDecls to summaries. @@ -626,13 +631,36 @@ class RetainSummaryManager { const RetainSummary * generateSummary(const FunctionDecl *FD, bool &AllowAnnotations); + /// Return a summary for OSObject, or nullptr if not found. + const RetainSummary *getSummaryForOSObject(const FunctionDecl *FD, + StringRef FName, QualType RetTy); + + /// Return a summary for Objective-C or CF object, or nullptr if not found. + const RetainSummary *getSummaryForObjCOrCFObject( + const FunctionDecl *FD, + StringRef FName, + QualType RetTy, + const FunctionType *FT, + bool &AllowAnnotations); + + /// Apply the annotation of {@code pd} in function {@code FD} + /// to the resulting summary stored in out-parameter {@code Template}. + /// \return whether an annotation was applied. + bool applyFunctionParamAnnotationEffect(const ParmVarDecl *pd, + unsigned parm_idx, + const FunctionDecl *FD, + ArgEffects::Factory &AF, + RetainSummaryTemplate &Template); + public: RetainSummaryManager(ASTContext &ctx, bool usesARC, - bool trackOSObject) + bool trackObjCAndCFObjects, + bool trackOSObjects) : Ctx(ctx), ARCEnabled(usesARC), - TrackOSObjects(trackOSObject), + TrackObjCAndCFObjects(trackObjCAndCFObjects), + TrackOSObjects(trackOSObjects), AF(BPAlloc), ScratchArgs(AF.getEmptyMap()), ObjCAllocRetE(usesARC ? RetEffect::MakeNotOwned(RetEffect::ObjC) : RetEffect::MakeOwned(RetEffect::ObjC)), @@ -709,6 +737,7 @@ public: void updateSummaryFromAnnotations(const RetainSummary *&Summ, const FunctionDecl *FD); + void updateSummaryForCall(const RetainSummary *&Summ, const CallEvent &Call); @@ -716,9 +745,21 @@ public: RetEffect getObjAllocRetEffect() const { return ObjCAllocRetE; } + /// \return True if the declaration has an attribute {@code T}, + /// AND we are tracking that attribute. False otherwise. + template <class T> + bool hasEnabledAttr(const Decl *D) { + return isAttrEnabled<T>() && D->hasAttr<T>(); + } + + /// Check whether we are tracking properties specified by the attributes. + template <class T> + bool isAttrEnabled(); + friend class RetainSummaryTemplate; }; + // Used to avoid allocating long-term (BPAlloc'd) memory for default retain // summaries. If a function or method looks like it has a default summary, but // it has annotations, the annotations are added to the stack-based template |