clang  15.0.0git
Namespaces | Typedefs | Functions | Variables
RegionStore.cpp File Reference
#include "clang/AST/Attr.h"
#include "clang/AST/CharUnits.h"
#include "clang/ASTMatchers/ASTMatchFinder.h"
#include "clang/Analysis/Analyses/LiveVariables.h"
#include "clang/Analysis/AnalysisDeclContext.h"
#include "clang/Basic/JsonSupport.h"
#include "clang/Basic/TargetInfo.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/AnalysisManager.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/CallEvent.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ExprEngine.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/MemRegion.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramState.h"
#include "clang/StaticAnalyzer/Core/PathSensitive/ProgramStateTrait.h"
#include "llvm/ADT/ImmutableMap.h"
#include "llvm/ADT/Optional.h"
#include "llvm/Support/raw_ostream.h"
#include <utility>
Include dependency graph for RegionStore.cpp:

Go to the source code of this file.

Namespaces

 llvm
 YAML serialization mapping.
 

Typedefs

typedef llvm::ImmutableMap< BindingKey, SVal > ClusterBindings
 
typedef llvm::ImmutableMapRef< BindingKey, SVal > ClusterBindingsRef
 
typedef std::pair< BindingKey, SVal > BindingPair
 
typedef llvm::ImmutableMap< const MemRegion *, ClusterBindingsRegionBindings
 
typedef SmallVector< const FieldDecl *, 8 > FieldVector
 

Functions

static raw_ostream & llvm::operator<< (raw_ostream &Out, BindingKey K)
 
static bool isUnionField (const FieldRegion *FR)
 
static void getSymbolicOffsetFields (BindingKey K, FieldVector &Fields)
 
static bool isCompatibleWithFields (BindingKey K, const FieldVector &Fields)
 
static void collectSubRegionBindings (SmallVectorImpl< BindingPair > &Bindings, SValBuilder &SVB, const ClusterBindings &Cluster, const SubRegion *Top, BindingKey TopKey, bool IncludeAllDefaultBindings)
 Collects all bindings in Cluster that may refer to bindings within Top. More...
 
static void collectSubRegionBindings (SmallVectorImpl< BindingPair > &Bindings, SValBuilder &SVB, const ClusterBindings &Cluster, const SubRegion *Top, bool IncludeAllDefaultBindings)
 
static QualType getUnderlyingType (const SubRegion *R)
 
static Optional< nonloc::LazyCompoundVal > getExistingLazyBinding (SValBuilder &SVB, RegionBindingsConstRef B, const SubRegion *R, bool AllowSubregionBindings)
 Checks to see if store B has a lazy binding for region R. More...
 
static SmallVector< uint64_t, 2 > getConstantArrayExtents (const ConstantArrayType *CAT)
 This is a helper function for getConstantValFromConstArrayInitializer. More...
 
static std::pair< SmallVector< SVal, 2 >, const MemRegion * > getElementRegionOffsetsWithBase (const ElementRegion *ER)
 This is a helper function for getConstantValFromConstArrayInitializer. More...
 
static Optional< SVal > convertOffsetsFromSvalToUnsigneds (const SmallVector< SVal, 2 > &SrcOffsets, const SmallVector< uint64_t, 2 > ArrayExtents, SmallVector< uint64_t, 2 > &DstOffsets)
 
static bool isRecordEmpty (const RecordDecl *RD)
 

Variables

const typedef RegionBindingsRef & RegionBindingsConstRef
 

Typedef Documentation

◆ BindingPair

typedef std::pair<BindingKey, SVal> BindingPair

◆ ClusterBindings

typedef llvm::ImmutableMap<BindingKey, SVal> ClusterBindings

◆ ClusterBindingsRef

typedef llvm::ImmutableMapRef<BindingKey, SVal> ClusterBindingsRef

◆ FieldVector

typedef SmallVector<const FieldDecl *, 8> FieldVector

◆ RegionBindings

typedef llvm::ImmutableMap<const MemRegion *, ClusterBindings> RegionBindings

Function Documentation

◆ collectSubRegionBindings() [1/2]

static void collectSubRegionBindings ( SmallVectorImpl< BindingPair > &  Bindings,
SValBuilder &  SVB,
const ClusterBindings Cluster,
const SubRegion *  Top,
BindingKey  TopKey,
bool  IncludeAllDefaultBindings 
)
static

Collects all bindings in Cluster that may refer to bindings within Top.

Each binding is a pair whose first is the key (a BindingKey) and whose second is the value (an SVal).

The IncludeAllDefaultBindings parameter specifies whether to include default bindings that may extend beyond Top itself, e.g. if Top is an aggregate within a larger aggregate with a default binding.

Examples
/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/StaticAnalyzer/Core/RegionStore.cpp.

Definition at line 846 of file RegionStore.cpp.

References getSymbolicOffsetFields(), and isCompatibleWithFields().

Referenced by collectSubRegionBindings(), and getExistingLazyBinding().

◆ collectSubRegionBindings() [2/2]

static void collectSubRegionBindings ( SmallVectorImpl< BindingPair > &  Bindings,
SValBuilder &  SVB,
const ClusterBindings Cluster,
const SubRegion *  Top,
bool  IncludeAllDefaultBindings 
)
static

Definition at line 918 of file RegionStore.cpp.

References collectSubRegionBindings().

◆ convertOffsetsFromSvalToUnsigneds()

static Optional<SVal> convertOffsetsFromSvalToUnsigneds ( const SmallVector< SVal, 2 > &  SrcOffsets,
const SmallVector< uint64_t, 2 >  ArrayExtents,
SmallVector< uint64_t, 2 > &  DstOffsets 
)
static

◆ getConstantArrayExtents()

static SmallVector<uint64_t, 2> getConstantArrayExtents ( const ConstantArrayType CAT)
static

This is a helper function for getConstantValFromConstArrayInitializer.

Return an array of extents of the declared array type.

E.g. for int x[1][2][3]; returns { 1, 2, 3 }.

Examples
/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/StaticAnalyzer/Core/RegionStore.cpp.

Definition at line 1623 of file RegionStore.cpp.

References clang::Type::getCanonicalTypeInternal(), clang::ArrayType::getElementType(), and clang::ConstantArrayType::getSize().

◆ getElementRegionOffsetsWithBase()

static std::pair<SmallVector<SVal, 2>, const MemRegion *> getElementRegionOffsetsWithBase ( const ElementRegion *  ER)
static

This is a helper function for getConstantValFromConstArrayInitializer.

Return an array of offsets from nested ElementRegions and a root base region. The array is never empty and a base region is never null.

E.g. for Element{Element{Element{VarRegion},1},2},3} returns { 3, 2, 1 }. This represents an access through indirection: arr[1][2][3];

Parameters
ERThe given (possibly nested) ElementRegion.
Note
The result array is in the reverse order of indirection expression: arr[1][2][3] -> { 3, 2, 1 }. This helps to provide complexity O(n), where n is a number of indirections. It may not affect performance in real-life code, though.
Examples
/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/StaticAnalyzer/Core/RegionStore.cpp.

Definition at line 1648 of file RegionStore.cpp.

◆ getExistingLazyBinding()

static Optional<nonloc::LazyCompoundVal> getExistingLazyBinding ( SValBuilder &  SVB,
RegionBindingsConstRef  B,
const SubRegion *  R,
bool  AllowSubregionBindings 
)
static

Checks to see if store B has a lazy binding for region R.

If AllowSubregionBindings is false, a lazy binding will be rejected if there are additional bindings within R.

Note that unlike RegionStoreManager::findLazyBinding, this will not search for lazy bindings for super-regions of R.

Examples
/home/buildbot/as-worker-4/publish-doxygen-docs/llvm-project/clang/lib/StaticAnalyzer/Core/RegionStore.cpp.

Definition at line 1541 of file RegionStore.cpp.

References collectSubRegionBindings(), getUnderlyingType(), clang::QualType::isNull(), clang::Type::isVoidPointerType(), and V.

◆ getSymbolicOffsetFields()

static void getSymbolicOffsetFields ( BindingKey  K,
FieldVector Fields 
)
static

◆ getUnderlyingType()

static QualType getUnderlyingType ( const SubRegion *  R)
static

◆ isCompatibleWithFields()

static bool isCompatibleWithFields ( BindingKey  K,
const FieldVector Fields 
)
static

◆ isRecordEmpty()

static bool isRecordEmpty ( const RecordDecl RD)
static

◆ isUnionField()

static bool isUnionField ( const FieldRegion *  FR)
inlinestatic

Variable Documentation

◆ RegionBindingsConstRef

const typedef RegionBindingsRef& RegionBindingsConstRef