clang  6.0.0svn
Classes | Namespaces | Macros | Typedefs | Functions
RetainCountChecker.cpp File Reference
#include "AllocationDiagnostics.h"
#include "ClangSACheckers.h"
#include "SelectorExtras.h"
#include "clang/AST/Attr.h"
#include "clang/AST/DeclCXX.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/ParentMap.h"
#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/Basic/LangOptions.h"
#include "clang/Basic/SourceManager.h"
#include "clang/StaticAnalyzer/Checkers/ObjCRetainCount.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.h"
#include "clang/StaticAnalyzer/Core/BugReporter/PathDiagnostic.h"
#include "clang/StaticAnalyzer/Core/Checker.h"
#include "clang/StaticAnalyzer/Core/CheckerManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CheckerContext.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/SymbolManager.h"
#include "llvm/ADT/DenseMap.h"
#include "llvm/ADT/FoldingSet.h"
#include "llvm/ADT/ImmutableList.h"
#include "llvm/ADT/ImmutableMap.h"
#include "llvm/ADT/STLExtras.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringExtras.h"
#include <cstdarg>
#include <utility>
Include dependency graph for RetainCountChecker.cpp:

Go to the source code of this file.

Classes

struct  llvm::FoldingSetTrait< ArgEffect >
 
struct  llvm::FoldingSetTrait< RetEffect >
 
struct  llvm::DenseMapInfo< ObjCSummaryKey >
 

Namespaces

 llvm
 DominatorTree GraphTraits specialization so the DominatorTree can be iterable by generic graph iterators.
 
 clang
 Dataflow Directional Tag Classes.
 
 clang::ento
 
 clang::ento::objc_retain
 

Macros

#define createCallEffect(D, KIND)
 

Typedefs

typedef llvm::ImmutableMap< unsigned, ArgEffectArgEffects
 ArgEffects summarizes the effects of a function/method call on all of its arguments. More...
 

Functions

static const RefVal * getRefBinding (ProgramStateRef State, SymbolRef Sym)
 
static ProgramStateRef setRefBinding (ProgramStateRef State, SymbolRef Sym, RefVal Val)
 
static ProgramStateRef removeRefBinding (ProgramStateRef State, SymbolRef Sym)
 
static bool isRetain (const FunctionDecl *FD, StringRef FName)
 
static bool isRelease (const FunctionDecl *FD, StringRef FName)
 
static bool isAutorelease (const FunctionDecl *FD, StringRef FName)
 
static bool isMakeCollectable (const FunctionDecl *FD, StringRef FName)
 
static ArgEffect getStopTrackingHardEquivalent (ArgEffect E)
 
static bool hasRCAnnotation (const Decl *D, StringRef rcAnnotation)
 Returns true if the declaration 'D' is annotated with 'rcAnnotation'. More...
 
static bool isTrustedReferenceCountImplementation (const FunctionDecl *FD)
 Returns true if the function declaration 'FD' contains 'rc_ownership_trusted_implementation' annotate attribute. More...
 
static bool isGeneralizedObjectRef (QualType Ty)
 
static bool isNumericLiteralExpression (const Expr *E)
 
static bool isSynthesizedAccessor (const StackFrameContext *SFC)
 Returns true if this stack frame is for an Objective-C method that is a property getter or setter whose body has been synthesized by the analyzer. More...
 
static AllocationInfo GetAllocationSite (ProgramStateManager &StateMgr, const ExplodedNode *N, SymbolRef Sym)
 
static QualType GetReturnType (const Expr *RetE, ASTContext &Ctx)
 GetReturnType - Used to get the return type of a message expression or function call with the intention of affixing that type to a tracked symbol. More...
 
static ProgramStateRef updateOutParameter (ProgramStateRef State, SVal ArgVal, ArgEffect Effect)
 

Macro Definition Documentation

◆ createCallEffect

#define createCallEffect (   D,
  KIND 
)
Value:
ASTContext &Ctx = D->getASTContext();\
LangOptions L = Ctx.getLangOpts();\
RetainSummaryManager M(Ctx, L.GCOnly, L.ObjCAutoRefCount);\
const RetainSummary *S = M.get ## KIND ## Summary(D);\
CallEffects CE(S->getRetEffect());\
CE.Receiver = S->getReceiverEffect();\
unsigned N = D->param_size();\
for (unsigned i = 0; i < N; ++i) {\
CE.Args.push_back(S->getArg(i));\
}
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
Definition: ASTContext.h:128
const LangOptions & getLangOpts() const
Definition: ASTContext.h:661

Definition at line 4131 of file RetainCountChecker.cpp.

Referenced by clang::ento::objc_retain::CallEffects::getEffect().

Typedef Documentation

◆ ArgEffects

ArgEffects summarizes the effects of a function/method call on all of its arguments.

Definition at line 73 of file RetainCountChecker.cpp.

Function Documentation

◆ GetAllocationSite()

static AllocationInfo GetAllocationSite ( ProgramStateManager StateMgr,
const ExplodedNode N,
SymbolRef  Sym 
)
static

Definition at line 2275 of file RetainCountChecker.cpp.

References bool, clang::ento::PathDiagnosticLocation::create(), clang::ento::PathDiagnosticLocation::createBegin(), clang::ento::PathDiagnosticLocation::createEndOfPath(), clang::ento::MemRegion::getAs(), clang::ProgramPoint::getAs(), clang::Selector::getAsString(), clang::ento::SVal::getAsSymbol(), clang::ento::CheckerContext::getASTContext(), clang::ento::BugReporterContext::getASTContext(), clang::ento::MemRegion::getBaseRegion(), clang::ento::ExplodedNode::getCodeDecl(), clang::LocationContext::getCurrentStackFrame(), clang::LocationContext::getDecl(), clang::ento::BugReporterVisitor::getDefaultEndPath(), clang::ASTContext::getLangOpts(), clang::ento::ExplodedNode::getLocation(), clang::ento::ExplodedNode::getLocationContext(), clang::ento::CheckerContext::getLocationContext(), clang::ento::SymExpr::getOriginRegion(), getRefBinding(), clang::ento::StoreManager::FindUniqueBinding::getRegion(), clang::ObjCMethodDecl::getSelector(), clang::ento::CheckerContext::getSourceManager(), clang::ento::BugReporterContext::getSourceManager(), clang::FullSourceLoc::getSpellingLineNumber(), clang::ento::VarRegion::getStackFrame(), clang::ento::ExplodedNode::getState(), clang::ento::CheckerContext::getStateManager(), clang::ento::BugReporterContext::getStateManager(), clang::ento::PathDiagnosticLocation::getStmt(), clang::Decl::hasAttr(), clang::LangOptions::HybridGC, clang::ento::CheckerContext::isObjCGCEnabled(), clang::LocationContext::isParentOf(), clang::ento::ProgramStateManager::iterBindings(), clang::ento::BugReport::markInteresting(), clang::OMF_alloc, clang::OMF_init, clang::ento::ExplodedNode::pred_begin(), clang::ento::ExplodedNode::pred_empty(), clang::ento::shouldIncludeAllocationSiteInLeakDiagnostics(), SM, clang::CodeGen::state, and X.

◆ getRefBinding()

static const RefVal* getRefBinding ( ProgramStateRef  State,
SymbolRef  Sym 
)
inlinestatic

◆ GetReturnType()

static QualType GetReturnType ( const Expr RetE,
ASTContext Ctx 
)
static

GetReturnType - Used to get the return type of a message expression or function call with the intention of affixing that type to a tracked symbol.

While the return type can be queried directly from RetEx, when invoking class methods we augment to the return type to be that of a pointer to the class (as opposed it just being id).

more specific than id.

Definition at line 3000 of file RetainCountChecker.cpp.

References clang::ento::CheckerContext::addTransition(), clang::ento::CallEvent::getArgSVal(), clang::Type::getAs(), clang::ento::SVal::getAsLocSymbol(), clang::ento::SVal::getAsSymbol(), clang::ento::objc_retain::RetEffect::getKind(), clang::ento::CallEvent::getNumArgs(), clang::ASTContext::getObjCInterfaceType(), clang::ASTContext::getObjCObjectPointerType(), clang::ObjCMethodCall::getReceiverSVal(), clang::ento::CallEvent::getReturnValue(), clang::ento::CheckerContext::getState(), clang::Expr::getType(), clang::ento::objc_retain::RetEffect::NoRetHard, removeRefBinding(), clang::CodeGen::state, and clang::ento::objc_retain::StopTrackingHard.

Referenced by updateOutParameter().

◆ getStopTrackingHardEquivalent()

static ArgEffect getStopTrackingHardEquivalent ( ArgEffect  E)
static

Definition at line 903 of file RetainCountChecker.cpp.

◆ hasRCAnnotation()

static bool hasRCAnnotation ( const Decl D,
StringRef  rcAnnotation 
)
static

Returns true if the declaration 'D' is annotated with 'rcAnnotation'.

Definition at line 1318 of file RetainCountChecker.cpp.

References clang::Decl::specific_attrs().

Referenced by isGeneralizedObjectRef(), and isTrustedReferenceCountImplementation().

◆ isAutorelease()

static bool isAutorelease ( const FunctionDecl FD,
StringRef  FName 
)
static

Definition at line 893 of file RetainCountChecker.cpp.

◆ isGeneralizedObjectRef()

static bool isGeneralizedObjectRef ( QualType  Ty)
static

Definition at line 1332 of file RetainCountChecker.cpp.

References clang::ento::objc_retain::Autorelease, clang::ento::objc_retain::RetEffect::CF, clang::ento::objc_retain::Dealloc, clang::ento::objc_retain::DecRef, clang::ento::objc_retain::DecRefMsg, clang::ento::objc_retain::DoNothing, clang::LangOptions::GCOnly, clang::ento::objc_retain::RetEffect::Generalized, clang::Type::getAs(), clang::ento::SVal::getAsLocSymbol(), clang::QualType::getAsString(), clang::ObjCMethodCall::getDecl(), clang::ObjCContainerDecl::getInstanceMethod(), clang::ento::objc_retain::RetEffect::getKind(), clang::ObjCMethodDecl::getMethodFamily(), clang::Selector::getMethodFamily(), clang::Selector::getNameForSlot(), clang::GetNullarySelector(), clang::Selector::getNumArgs(), clang::Type::getPointeeType(), clang::ento::BugReport::getRanges(), clang::ObjCMethodCall::getReceiverInterface(), clang::ObjCMethodCall::getReceiverSVal(), getRefBinding(), clang::ObjCMethodDecl::getReturnType(), clang::FunctionDecl::getReturnType(), clang::ObjCMethodCall::getSelector(), clang::ValueDecl::getType(), clang::GetUnarySelector(), clang::Decl::hasAttr(), hasRCAnnotation(), clang::LangOptions::HybridGC, clang::ento::objc_retain::IncRefMsg, clang::ento::coreFoundation::isCFObjectRef(), clang::ento::cocoa::isCocoaObjectRef(), clang::Selector::isKeywordSelector(), clang::QualType::isNull(), clang::Type::isPointerType(), log, clang::ento::objc_retain::RetEffect::MakeNoRet(), clang::ento::objc_retain::RetEffect::MakeNoRetHard(), clang::ento::objc_retain::RetEffect::MakeNotOwned(), clang::ento::objc_retain::RetEffect::MakeOwned(), clang::ento::objc_retain::MayEscape, clang::ento::categories::MemoryCoreFoundationObjectiveC, clang::LangOptions::NonGC, clang::ento::objc_retain::RetEffect::NoRet, clang::ento::objc_retain::RetEffect::ObjC, clang::OMF_alloc, clang::OMF_autorelease, clang::OMF_copy, clang::OMF_dealloc, clang::OMF_finalize, clang::OMF_init, clang::OMF_initialize, clang::OMF_mutableCopy, clang::OMF_new, clang::OMF_None, clang::OMF_performSelector, clang::OMF_release, clang::OMF_retain, clang::OMF_retainCount, clang::OMF_self, clang::ObjCMethodDecl::param_begin(), clang::FunctionDecl::param_begin(), clang::ObjCMethodDecl::param_end(), clang::FunctionDecl::param_end(), clang::ento::objc_retain::RetainedOutParameter, SM, clang::ento::objc_retain::StopTracking, clang::ento::objc_retain::StopTrackingHard, clang::T, and clang::ento::objc_retain::UnretainedOutParameter.

◆ isMakeCollectable()

static bool isMakeCollectable ( const FunctionDecl FD,
StringRef  FName 
)
static

Definition at line 897 of file RetainCountChecker.cpp.

◆ isNumericLiteralExpression()

static bool isNumericLiteralExpression ( const Expr E)
static

Definition at line 1923 of file RetainCountChecker.cpp.

Referenced by isSynthesizedAccessor().

◆ isRelease()

static bool isRelease ( const FunctionDecl FD,
StringRef  FName 
)
static

Definition at line 889 of file RetainCountChecker.cpp.

◆ isRetain()

static bool isRetain ( const FunctionDecl FD,
StringRef  FName 
)
static

Definition at line 885 of file RetainCountChecker.cpp.

◆ isSynthesizedAccessor()

static bool isSynthesizedAccessor ( const StackFrameContext SFC)
static

◆ isTrustedReferenceCountImplementation()

static bool isTrustedReferenceCountImplementation ( const FunctionDecl FD)
static

Returns true if the function declaration 'FD' contains 'rc_ownership_trusted_implementation' annotate attribute.

Definition at line 1328 of file RetainCountChecker.cpp.

References hasRCAnnotation().

◆ removeRefBinding()

static ProgramStateRef removeRefBinding ( ProgramStateRef  State,
SymbolRef  Sym 
)
static

Definition at line 375 of file RetainCountChecker.cpp.

Referenced by GetReturnType().

◆ setRefBinding()

static ProgramStateRef setRefBinding ( ProgramStateRef  State,
SymbolRef  Sym,
RefVal  Val 
)
inlinestatic

Definition at line 370 of file RetainCountChecker.cpp.

Referenced by updateOutParameter().

◆ updateOutParameter()

static ProgramStateRef updateOutParameter ( ProgramStateRef  State,
SVal  ArgVal,
ArgEffect  Effect 
)
static