14#ifndef LLVM_CLANG_ANALYSIS_PROGRAMPOINT_H
15#define LLVM_CLANG_ANALYSIS_PROGRAMPOINT_H
19#include "llvm/ADT/DenseMap.h"
20#include "llvm/ADT/FoldingSet.h"
21#include "llvm/ADT/PointerIntPair.h"
22#include "llvm/ADT/StringRef.h"
23#include "llvm/Support/Casting.h"
24#include "llvm/Support/DataTypes.h"
32class AnalysisDeclContext;
48 const void *
const TagKind;
90 llvm::PointerIntPair<const void *, 2, unsigned> Data2;
94 llvm::PointerIntPair<const LocationContext *, 2, unsigned> L;
96 llvm::PointerIntPair<const ProgramPointTag *, 2, unsigned> Tag;
105 : Data1(
P), Data2(
nullptr, (((
unsigned)k) >> 0) & 0x3),
106 L(l, (((
unsigned)k) >> 2) & 0x3), Tag(tag, (((
unsigned)k) >> 4) & 0x3),
116 : Data1(P1), Data2(P2, (((
unsigned)k) >> 0) & 0x3),
117 L(l, (((
unsigned)k) >> 2) & 0x3), Tag(tag, (((
unsigned)k) >> 4) & 0x3),
122 const void *
getData2()
const {
return Data2.getPointer(); }
123 void setData2(
const void *d) { Data2.setPointer(d); }
138 assert(T::isKind(*
this));
147 template <
typename T> std::optional<T>
getAs()
const {
148 if (!T::isKind(*
this))
157 unsigned x = Tag.getInt();
176 return L.getPointer();
185 llvm::FoldingSetNodeID
ID;
187 return ID.ComputeHash();
191 return Data1 == RHS.Data1 && Data2 == RHS.Data2 && L == RHS.L &&
192 Tag == RHS.Tag && ElemRef == RHS.ElemRef;
196 return Data1 != RHS.Data1 || Data2 != RHS.Data2 || L != RHS.L ||
197 Tag != RHS.Tag || ElemRef != RHS.ElemRef;
206 ID.AddPointer(ElemRef.getParent());
207 ID.AddInteger(ElemRef.getIndexInBlock());
210 void printJson(llvm::raw_ostream &Out,
const char *NL =
"\n")
const;
212 LLVM_DUMP_METHOD
void dump()
const;
224 assert(B &&
"BlockEntrance requires non-null block");
233 return B->
empty() ? std::optional<CFGElement>() : B->
front();
276 template <
typename T>
284 unsigned k = Location.
getKind();
293 const Stmt *SubStmt =
nullptr)
325 unsigned k = Location.
getKind();
378 unsigned k = location.
getKind();
502 assert(B1 &&
"BlockEdge: source block must be non-null");
503 assert(B2 &&
"BlockEdge: destination block must be non-null");
645 const CFG *CalleeCFG = CalleeCtx->
getCFG();
733 const void *Data2 =
nullptr,
752template <>
struct DenseMapInfo<
clang::ProgramPoint> {
756 reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getEmptyKey()) & ~0x7;
762 reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getTombstoneKey()) & ~0x7;
767 return Loc.getHashValue();
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
const CFGBlock * getSrc() const
const CFGBlock * getDst() const
BlockEdge(const CFGBlock *B1, const CFGBlock *B2, const LocationContext *L)
std::optional< CFGElement > getFirstElement() const
BlockEntrance(const CFGBlock *B, const LocationContext *L, const ProgramPointTag *tag=nullptr)
const CFGBlock * getBlock() const
const CFGBlock * getBlock() const
const Stmt * getTerminator() const
BlockExit(const CFGBlock *B, const LocationContext *L)
Represents a single basic block in a source-level CFG.
ElementRefImpl< true > ConstCFGElementRef
Stmt * getTerminatorStmt()
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Represents a C++ base or member initializer.
Represents a point when we begin processing an inlined call.
CallEnter(const Stmt *stmt, const StackFrameContext *calleeCtx, const LocationContext *callerCtx)
const Stmt * getCallExpr() const
const CFGBlock * getEntry() const
Returns the entry block in the CFG for the entered function.
const StackFrameContext * getCalleeContext() const
Represents a point when we start the call exit sequence (for inlined call).
CallExitBegin(const StackFrameContext *L, const ReturnStmt *RS)
const ReturnStmt * getReturnStmt() const
Represents a point when we finish the call exit sequence (for inlined call).
CallExitEnd(const StackFrameContext *CalleeCtx, const LocationContext *CallerCtx)
const StackFrameContext * getCalleeContext() const
Decl - This represents one declaration (or definition), e.g.
This is a meta program point, which should be skipped by all the diagnostic reasoning etc.
EpsilonPoint(const LocationContext *L, const void *Data1, const void *Data2=nullptr, const ProgramPointTag *tag=nullptr)
const void * getData() const
const CFGBlock * getBlock() const
const ReturnStmt * getStmt() const
FunctionExitPoint(const ReturnStmt *S, const LocationContext *LC, const ProgramPointTag *tag=nullptr)
Represents an implicit call event.
SourceLocation getLocation() const
ImplicitCallPoint(const Decl *D, SourceLocation Loc, Kind K, const LocationContext *L, const ProgramPointTag *Tag, CFGBlock::ConstCFGElementRef ElemRef)
ImplicitCallPoint()=default
const Decl * getDecl() const
LocationCheck(const Stmt *S, const LocationContext *L, ProgramPoint::Kind K, const ProgramPointTag *tag)
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
const StackFrameContext * getStackFrame() const
Represents a point when we exit a loop.
LoopExit(const Stmt *LoopStmt, const LocationContext *LC)
const Stmt * getLoopStmt() const
PostAllocatorCall(const Stmt *S, const LocationContext *L, const ProgramPointTag *Tag=nullptr)
PostCondition(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Represents a program point just after an implicit call event.
PostImplicitCall(const Decl *D, SourceLocation Loc, const LocationContext *L, CFGBlock::ConstCFGElementRef ElemRef, const ProgramPointTag *Tag=nullptr)
PostInitializer(const CXXCtorInitializer *I, const void *Loc, const LocationContext *L)
Construct a PostInitializer point that represents a location after CXXCtorInitializer expression eval...
const void * getLocationValue() const
Returns the location of the field.
const CXXCtorInitializer * getInitializer() const
PostLValue(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
PostLoad(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Represents a point after we ran remove dead bindings AFTER processing the given statement.
PostStmtPurgeDeadSymbols(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
PostStmt(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
PostStmt(const Stmt *S, const void *data, Kind k, const LocationContext *L, const ProgramPointTag *tag=nullptr)
PostStmt(const Stmt *S, Kind k, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Represents a program point after a store evaluation.
PostStore(const Stmt *S, const LocationContext *L, const void *Loc, const ProgramPointTag *tag=nullptr)
Construct the post store point.
const void * getLocationValue() const
Returns the information about the location used in the store, how it was uttered in the code.
Represents a program point just before an implicit call event.
PreImplicitCall(const Decl *D, SourceLocation Loc, const LocationContext *L, CFGBlock::ConstCFGElementRef ElemRef, const ProgramPointTag *Tag=nullptr)
PreLoad(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Represents a point after we ran remove dead bindings BEFORE processing the given statement.
PreStmtPurgeDeadSymbols(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
const Stmt * getSubStmt() const
PreStmt(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag, const Stmt *SubStmt=nullptr)
PreStore(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
ProgramPoints can be "tagged" as representing points specific to a given analysis entity.
const void * getTagKind() const
Used to implement 'isKind' in subclasses.
ProgramPointTag(void *tagKind=nullptr)
virtual StringRef getTagDescription() const =0
virtual ~ProgramPointTag()
const ProgramPointTag * getTag() const
bool isPurgeKind()
Is this a program point corresponding to purge/removal of dead symbols and bindings.
T castAs() const
Convert to the specified ProgramPoint type, asserting that this ProgramPoint is of the desired type.
static ProgramPoint getProgramPoint(const Stmt *S, ProgramPoint::Kind K, const LocationContext *LC, const ProgramPointTag *tag)
LLVM_DUMP_METHOD void dump() const
CFGBlock::ConstCFGElementRef getElementRef() const
void Profile(llvm::FoldingSetNodeID &ID) const
void printJson(llvm::raw_ostream &Out, const char *NL="\n") const
void setData2(const void *d)
bool operator!=(const ProgramPoint &RHS) const
bool operator==(const ProgramPoint &RHS) const
unsigned getHashValue() const
ProgramPoint(const void *P, Kind k, const LocationContext *l, const ProgramPointTag *tag=nullptr, CFGBlock::ConstCFGElementRef ElemRef={nullptr, 0})
ProgramPoint(const void *P1, const void *P2, Kind k, const LocationContext *l, const ProgramPointTag *tag=nullptr, CFGBlock::ConstCFGElementRef ElemRef={nullptr, 0})
ProgramPoint withTag(const ProgramPointTag *tag) const
Create a new ProgramPoint object that is the same as the original except for using the specified tag ...
@ PreStmtPurgeDeadSymbolsKind
@ PostStmtPurgeDeadSymbolsKind
const void * getData1() const
const void * getData2() const
const StackFrameContext * getStackFrame() const
std::optional< T > getAs() const
Convert to the specified ProgramPoint type, returning std::nullopt if this ProgramPoint is not of the...
const LocationContext * getLocationContext() const
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
StringRef getTagDescription() const override
Encodes a location in the source.
static SourceLocation getFromPtrEncoding(const void *Encoding)
Turn a pointer encoding of a SourceLocation object back into a real SourceLocation.
It represents a stack frame of the call stack (based on CallEvent).
StmtPoint(const Stmt *S, const void *p2, Kind k, const LocationContext *L, const ProgramPointTag *tag)
const Stmt * getStmt() const
const T * getStmtAs() const
Stmt - This represents one statement.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
The JSON file list parser is used to communicate input to InstallAPI.
const FunctionProtoType * T
Diagnostic wrappers for TextAPI types for error reporting.
__UINTPTR_TYPE__ uintptr_t
An unsigned integer type with the property that any valid pointer to void can be converted to this ty...
static bool isEqual(const clang::ProgramPoint &L, const clang::ProgramPoint &R)
static clang::ProgramPoint getTombstoneKey()
static unsigned getHashValue(const clang::ProgramPoint &Loc)
static clang::ProgramPoint getEmptyKey()