clang  6.0.0svn
Enumerations | Functions
BasicObjCFoundationChecks.cpp File Reference
#include "ClangSACheckers.h"
#include "SelectorExtras.h"
#include "clang/AST/ASTContext.h"
#include "clang/AST/DeclObjC.h"
#include "clang/AST/Expr.h"
#include "clang/AST/ExprObjC.h"
#include "clang/AST/StmtObjC.h"
#include "clang/Analysis/DomainSpecific/CocoaConventions.h"
#include "clang/StaticAnalyzer/Core/BugReporter/BugType.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/ExplodedGraph.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
#include "llvm/ADT/SmallString.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/raw_ostream.h"
Include dependency graph for BasicObjCFoundationChecks.cpp:

Go to the source code of this file.

Enumerations

enum  FoundationClass {
  FC_None, FC_NSArray, FC_NSDictionary, FC_NSEnumerator,
  FC_NSNull, FC_NSOrderedSet, FC_NSSet, FC_NSString
}
 
enum  CFNumberType {
  kCFNumberSInt8Type = 1, kCFNumberSInt16Type = 2, kCFNumberSInt32Type = 3, kCFNumberSInt64Type = 4,
  kCFNumberFloat32Type = 5, kCFNumberFloat64Type = 6, kCFNumberCharType = 7, kCFNumberShortType = 8,
  kCFNumberIntType = 9, kCFNumberLongType = 10, kCFNumberLongLongType = 11, kCFNumberFloatType = 12,
  kCFNumberDoubleType = 13, kCFNumberCFIndexType = 14, kCFNumberNSIntegerType = 15, kCFNumberCGFloatType = 16
}
 

Functions

static StringRef GetReceiverInterfaceName (const ObjCMethodCall &msg)
 
static FoundationClass findKnownClass (const ObjCInterfaceDecl *ID, bool IncludeSuperclasses=true)
 
static Optional< uint64_t > GetCFNumberSize (ASTContext &Ctx, uint64_t i)
 
static bool isKnownNonNilCollectionType (QualType T)
 
static ProgramStateRef checkCollectionNonNil (CheckerContext &C, ProgramStateRef State, const ObjCForCollectionStmt *FCS)
 Assumes that the collection is non-nil. More...
 
static ProgramStateRef checkElementNonNil (CheckerContext &C, ProgramStateRef State, const ObjCForCollectionStmt *FCS)
 Assumes that the collection elements are non-nil. More...
 
static ProgramStateRef assumeCollectionNonEmpty (CheckerContext &C, ProgramStateRef State, SymbolRef CollectionS, bool Assumption)
 Returns NULL state if the collection is known to contain elements (or is known not to contain elements if the Assumption parameter is false.) More...
 
static ProgramStateRef assumeCollectionNonEmpty (CheckerContext &C, ProgramStateRef State, const ObjCForCollectionStmt *FCS, bool Assumption)
 
static bool alreadyExecutedAtLeastOneLoopIteration (const ExplodedNode *N, const ObjCForCollectionStmt *FCS)
 If the fist block edge is a back edge, we are reentering the loop. More...
 
static SymbolRef getMethodReceiverIfKnownImmutable (const CallEvent *Call)
 

Enumeration Type Documentation

◆ CFNumberType

Enumerator
kCFNumberSInt8Type 
kCFNumberSInt16Type 
kCFNumberSInt32Type 
kCFNumberSInt64Type 
kCFNumberFloat32Type 
kCFNumberFloat64Type 
kCFNumberCharType 
kCFNumberShortType 
kCFNumberIntType 
kCFNumberLongType 
kCFNumberLongLongType 
kCFNumberFloatType 
kCFNumberDoubleType 
kCFNumberCFIndexType 
kCFNumberNSIntegerType 
kCFNumberCGFloatType 

Definition at line 351 of file BasicObjCFoundationChecks.cpp.

◆ FoundationClass

Enumerator
FC_None 
FC_NSArray 
FC_NSDictionary 
FC_NSEnumerator 
FC_NSNull 
FC_NSOrderedSet 
FC_NSSet 
FC_NSString 

Definition at line 58 of file BasicObjCFoundationChecks.cpp.

Function Documentation

◆ alreadyExecutedAtLeastOneLoopIteration()

static bool alreadyExecutedAtLeastOneLoopIteration ( const ExplodedNode N,
const ObjCForCollectionStmt FCS 
)
static

If the fist block edge is a back edge, we are reentering the loop.

Definition at line 986 of file BasicObjCFoundationChecks.cpp.

References clang::ProgramPoint::getAs(), clang::ento::ExplodedNode::getLocation(), and P.

◆ assumeCollectionNonEmpty() [1/2]

static ProgramStateRef assumeCollectionNonEmpty ( CheckerContext C,
ProgramStateRef  State,
SymbolRef  CollectionS,
bool  Assumption 
)
static

Returns NULL state if the collection is known to contain elements (or is known not to contain elements if the Assumption parameter is false.)

Definition at line 943 of file BasicObjCFoundationChecks.cpp.

References clang::ento::SValBuilder::evalBinOp(), clang::ento::SVal::getAs(), clang::ento::SValBuilder::getConditionType(), clang::ento::CheckerContext::getSValBuilder(), clang::ento::SValBuilder::makeIntVal(), and State.

Referenced by assumeCollectionNonEmpty().

◆ assumeCollectionNonEmpty() [2/2]

static ProgramStateRef assumeCollectionNonEmpty ( CheckerContext C,
ProgramStateRef  State,
const ObjCForCollectionStmt FCS,
bool  Assumption 
)
static

◆ checkCollectionNonNil()

static ProgramStateRef checkCollectionNonNil ( CheckerContext C,
ProgramStateRef  State,
const ObjCForCollectionStmt FCS 
)
static

Assumes that the collection is non-nil.

If the collection is known to be nil, returns NULL to indicate an infeasible path.

Definition at line 884 of file BasicObjCFoundationChecks.cpp.

References clang::ento::SVal::getAs(), clang::ObjCForCollectionStmt::getCollection(), clang::ento::CheckerContext::getSVal(), and State.

◆ checkElementNonNil()

static ProgramStateRef checkElementNonNil ( CheckerContext C,
ProgramStateRef  State,
const ObjCForCollectionStmt FCS 
)
static

Assumes that the collection elements are non-nil.

This only applies if the collection is one of those known not to contain nil values.

Definition at line 909 of file BasicObjCFoundationChecks.cpp.

References clang::ento::SVal::castAs(), clang::ObjCForCollectionStmt::getCollection(), clang::ObjCForCollectionStmt::getElement(), clang::VarDecl::getInit(), clang::ento::CheckerContext::getLocationContext(), clang::Expr::getType(), isKnownNonNilCollectionType(), and State.

◆ findKnownClass()

static FoundationClass findKnownClass ( const ObjCInterfaceDecl ID,
bool  IncludeSuperclasses = true 
)
static

◆ GetCFNumberSize()

static Optional<uint64_t> GetCFNumberSize ( ASTContext Ctx,
uint64_t  i 
)
static

Definition at line 370 of file BasicObjCFoundationChecks.cpp.

References clang::ento::CheckerContext::addTransition(), clang::ento::objc_retain::Autorelease, clang::ASTContext::CharTy, clang::ASTContext::DoubleTy, clang::ento::CheckerContext::emitReport(), clang::ento::SValBuilder::evalEQ(), clang::ASTContext::FloatTy, clang::ento::CheckerContext::generateErrorNode(), clang::ento::CheckerContext::generateNonFatalErrorNode(), clang::IdentifierTable::get(), clang::CallExpr::getArg(), clang::ento::SVal::getAs(), clang::ento::CheckerContext::getASTContext(), clang::ento::CheckerContext::getCalleeDecl(), clang::ASTContext::getCanonicalType(), clang::NamedDecl::getIdentifier(), clang::ento::CheckerContext::getLocationContext(), clang::GetNullarySelector(), clang::CallExpr::getNumArgs(), clang::ObjCMethodCall::getReceiverInterface(), clang::Stmt::getSourceRange(), clang::ento::CheckerContext::getState(), clang::ento::CheckerContext::getSValBuilder(), clang::Expr::getType(), clang::ASTContext::getTypeSize(), clang::ento::TypedValueRegion::getValueType(), clang::ASTContext::Idents, clang::ASTContext::IntTy, clang::ObjCMethodCall::isInstanceMessage(), clang::Type::isIntegralOrEnumerationType(), kCFNumberCFIndexType, kCFNumberCGFloatType, kCFNumberCharType, kCFNumberDoubleType, kCFNumberFloatType, kCFNumberIntType, kCFNumberLongLongType, kCFNumberLongType, kCFNumberNSIntegerType, kCFNumberShortType, clang::ASTContext::LongLongTy, clang::ASTContext::LongTy, clang::ento::objc_retain::MakeCollectable, clang::ento::SValBuilder::makeZeroVal(), clang::ASTContext::ShortTy, clang::CodeGen::state, clang::T, and clang::ento::bugreporter::trackNullOrUndefValue().

◆ getMethodReceiverIfKnownImmutable()

static SymbolRef getMethodReceiverIfKnownImmutable ( const CallEvent Call)
static

◆ GetReceiverInterfaceName()

static StringRef GetReceiverInterfaceName ( const ObjCMethodCall msg)
static

◆ isKnownNonNilCollectionType()

static bool isKnownNonNilCollectionType ( QualType  T)
static