#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/STLExtras.h"
#include "llvm/Support/raw_ostream.h"
#include <optional>
#include <utility>
usingnamespaceclang;
usingnamespaceento;
namespace {
class BindingKey { … };
}
BindingKey BindingKey::Make(const MemRegion *R, Kind k) { … }
namespace llvm {
static inline raw_ostream &operator<<(raw_ostream &Out, BindingKey K) { … }
}
#if !defined(NDEBUG) || defined(LLVM_ENABLE_DUMP)
void BindingKey::dump() const { llvm::errs() << *this; }
#endif
ClusterBindings;
ClusterBindingsRef;
BindingPair;
RegionBindings;
namespace {
class RegionBindingsRef : public llvm::ImmutableMapRef<const MemRegion *,
ClusterBindings> { … };
}
RegionBindingsConstRef;
std::optional<SVal>
RegionBindingsRef::getDirectBinding(const MemRegion *R) const { … }
std::optional<SVal>
RegionBindingsRef::getDefaultBinding(const MemRegion *R) const { … }
RegionBindingsRef RegionBindingsRef::addBinding(BindingKey K, SVal V) const { … }
RegionBindingsRef RegionBindingsRef::addBinding(const MemRegion *R,
BindingKey::Kind k,
SVal V) const { … }
const SVal *RegionBindingsRef::lookup(BindingKey K) const { … }
const SVal *RegionBindingsRef::lookup(const MemRegion *R,
BindingKey::Kind k) const { … }
RegionBindingsRef RegionBindingsRef::removeBinding(BindingKey K) { … }
RegionBindingsRef RegionBindingsRef::removeBinding(const MemRegion *R,
BindingKey::Kind k){ … }
namespace {
class InvalidateRegionsWorker;
class RegionStoreManager : public StoreManager { … };
}
std::unique_ptr<StoreManager>
ento::CreateRegionStoreManager(ProgramStateManager &StMgr) { … }
namespace {
enum GlobalsFilterKind { … };
template <typename DERIVED>
class ClusterAnalysis { … };
}
bool RegionStoreManager::scanReachableSymbols(Store S, const MemRegion *R,
ScanReachableSymbols &Callbacks) { … }
static inline bool isUnionField(const FieldRegion *FR) { … }
FieldVector;
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) { … }
static void
collectSubRegionBindings(SmallVectorImpl<BindingPair> &Bindings,
SValBuilder &SVB, const ClusterBindings &Cluster,
const SubRegion *Top, bool IncludeAllDefaultBindings) { … }
RegionBindingsRef
RegionStoreManager::removeSubRegionBindings(RegionBindingsConstRef B,
const SubRegion *Top) { … }
namespace {
class InvalidateRegionsWorker : public ClusterAnalysis<InvalidateRegionsWorker>
{ … };
}
bool InvalidateRegionsWorker::AddToWorkList(const MemRegion *R) { … }
void InvalidateRegionsWorker::VisitBinding(SVal V) { … }
void InvalidateRegionsWorker::VisitCluster(const MemRegion *baseR,
const ClusterBindings *C) { … }
bool InvalidateRegionsWorker::isInitiallyIncludedGlobalRegion(
const MemRegion *R) { … }
bool InvalidateRegionsWorker::includeEntireMemorySpace(const MemRegion *Base) { … }
RegionBindingsRef RegionStoreManager::invalidateGlobalRegion(
MemRegion::Kind K, const Stmt *S, unsigned Count,
const LocationContext *LCtx, RegionBindingsRef B,
InvalidatedRegions *Invalidated) { … }
void RegionStoreManager::populateWorkList(InvalidateRegionsWorker &W,
ArrayRef<SVal> Values,
InvalidatedRegions *TopLevelRegions) { … }
StoreRef RegionStoreManager::invalidateRegions(
Store store, ArrayRef<SVal> Values, const Stmt *S, unsigned Count,
const LocationContext *LCtx, const CallEvent *Call, InvalidatedSymbols &IS,
RegionAndSymbolInvalidationTraits &ITraits,
InvalidatedRegions *TopLevelRegions, InvalidatedRegions *Invalidated) { … }
SVal RegionStoreManager::ArrayToPointer(Loc Array, QualType T) { … }
SVal RegionStoreManager::getBinding(RegionBindingsConstRef B, Loc L, QualType T) { … }
static QualType getUnderlyingType(const SubRegion *R) { … }
static std::optional<nonloc::LazyCompoundVal>
getExistingLazyBinding(SValBuilder &SVB, RegionBindingsConstRef B,
const SubRegion *R, bool AllowSubregionBindings) { … }
std::pair<Store, const SubRegion *>
RegionStoreManager::findLazyBinding(RegionBindingsConstRef B,
const SubRegion *R,
const SubRegion *originalRegion) { … }
static SmallVector<uint64_t, 2>
getConstantArrayExtents(const ConstantArrayType *CAT) { … }
static std::pair<SmallVector<SVal, 2>, const MemRegion *>
getElementRegionOffsetsWithBase(const ElementRegion *ER) { … }
static std::optional<SVal>
convertOffsetsFromSvalToUnsigneds(const SmallVector<SVal, 2> &SrcOffsets,
const SmallVector<uint64_t, 2> ArrayExtents,
SmallVector<uint64_t, 2> &DstOffsets) { … }
std::optional<SVal> RegionStoreManager::getConstantValFromConstArrayInitializer(
RegionBindingsConstRef B, const ElementRegion *R) { … }
std::optional<SVal> RegionStoreManager::getSValFromInitListExpr(
const InitListExpr *ILE, const SmallVector<uint64_t, 2> &Offsets,
QualType ElemT) { … }
SVal RegionStoreManager::getSValFromStringLiteral(const StringLiteral *SL,
uint64_t Offset,
QualType ElemT) { … }
static std::optional<SVal> getDerivedSymbolForBinding(
RegionBindingsConstRef B, const TypedValueRegion *BaseRegion,
const TypedValueRegion *SubReg, const ASTContext &Ctx, SValBuilder &SVB) { … }
SVal RegionStoreManager::getBindingForElement(RegionBindingsConstRef B,
const ElementRegion* R) { … }
SVal RegionStoreManager::getBindingForField(RegionBindingsConstRef B,
const FieldRegion* R) { … }
std::optional<SVal> RegionStoreManager::getBindingForDerivedDefaultValue(
RegionBindingsConstRef B, const MemRegion *superR,
const TypedValueRegion *R, QualType Ty) { … }
SVal RegionStoreManager::getLazyBinding(const SubRegion *LazyBindingRegion,
RegionBindingsRef LazyBinding) { … }
SVal
RegionStoreManager::getBindingForFieldOrElementCommon(RegionBindingsConstRef B,
const TypedValueRegion *R,
QualType Ty) { … }
SVal RegionStoreManager::getBindingForObjCIvar(RegionBindingsConstRef B,
const ObjCIvarRegion* R) { … }
SVal RegionStoreManager::getBindingForVar(RegionBindingsConstRef B,
const VarRegion *R) { … }
SVal RegionStoreManager::getBindingForLazySymbol(const TypedValueRegion *R) { … }
const RegionStoreManager::SValListTy &
RegionStoreManager::getInterestingValues(nonloc::LazyCompoundVal LCV) { … }
NonLoc RegionStoreManager::createLazyBinding(RegionBindingsConstRef B,
const TypedValueRegion *R) { … }
static bool isRecordEmpty(const RecordDecl *RD) { … }
SVal RegionStoreManager::getBindingForStruct(RegionBindingsConstRef B,
const TypedValueRegion *R) { … }
SVal RegionStoreManager::getBindingForArray(RegionBindingsConstRef B,
const TypedValueRegion *R) { … }
bool RegionStoreManager::includedInBindings(Store store,
const MemRegion *region) const { … }
StoreRef RegionStoreManager::killBinding(Store ST, Loc L) { … }
RegionBindingsRef
RegionStoreManager::bind(RegionBindingsConstRef B, Loc L, SVal V) { … }
RegionBindingsRef
RegionStoreManager::setImplicitDefaultValue(RegionBindingsConstRef B,
const MemRegion *R,
QualType T) { … }
std::optional<RegionBindingsRef> RegionStoreManager::tryBindSmallArray(
RegionBindingsConstRef B, const TypedValueRegion *R, const ArrayType *AT,
nonloc::LazyCompoundVal LCV) { … }
RegionBindingsRef
RegionStoreManager::bindArray(RegionBindingsConstRef B,
const TypedValueRegion* R,
SVal Init) { … }
RegionBindingsRef RegionStoreManager::bindVector(RegionBindingsConstRef B,
const TypedValueRegion* R,
SVal V) { … }
std::optional<RegionBindingsRef> RegionStoreManager::tryBindSmallStruct(
RegionBindingsConstRef B, const TypedValueRegion *R, const RecordDecl *RD,
nonloc::LazyCompoundVal LCV) { … }
RegionBindingsRef RegionStoreManager::bindStruct(RegionBindingsConstRef B,
const TypedValueRegion *R,
SVal V) { … }
RegionBindingsRef
RegionStoreManager::bindAggregate(RegionBindingsConstRef B,
const TypedRegion *R,
SVal Val) { … }
namespace {
class RemoveDeadBindingsWorker
: public ClusterAnalysis<RemoveDeadBindingsWorker> { … };
}
bool RemoveDeadBindingsWorker::AddToWorkList(const MemRegion *R) { … }
void RemoveDeadBindingsWorker::VisitAddedToCluster(const MemRegion *baseR,
const ClusterBindings &C) { … }
void RemoveDeadBindingsWorker::VisitCluster(const MemRegion *baseR,
const ClusterBindings *C) { … }
void RemoveDeadBindingsWorker::VisitBinding(SVal V) { … }
bool RemoveDeadBindingsWorker::UpdatePostponed() { … }
StoreRef RegionStoreManager::removeDeadBindings(Store store,
const StackFrameContext *LCtx,
SymbolReaper& SymReaper) { … }
void RegionStoreManager::printJson(raw_ostream &Out, Store S, const char *NL,
unsigned int Space, bool IsDot) const { … }