clang: include/clang/Analysis/ProgramPoint.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_ANALYSIS_PROGRAMPOINT_H
15#define LLVM_CLANG_ANALYSIS_PROGRAMPOINT_H
16
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"
25#include
26#include
27#include
28#include
29
31
34
35
36
37
39public:
42
43
44
46
47
48 const void *getTagKind() const { return TagKind; }
49
50private:
51 const void *const TagKind;
52};
53
55 std::string Desc;
56public:
59};
60
62public:
90
93
94private:
95 const void *Data1;
96 llvm::PointerIntPair<const void *, 2, unsigned> Data2;
97
98
99
100 llvm::PointerIntPair<const LocationContext *, 2, unsigned> L;
101
102 llvm::PointerIntPair<const ProgramPointTag *, 2, unsigned> Tag;
103
105
106protected:
112 L(l, (((unsigned)k) >> 2) & 0x3), Tag(tag, (((unsigned)k) >> 4) & 0x3),
113 ElemRef(ElemRef) {
117 }
118
122 : Data1(P1), Data2(P2, (((unsigned)k) >> 0) & 0x3),
123 L(l, (((unsigned)k) >> 2) & 0x3), Tag(tag, (((unsigned)k) >> 4) & 0x3),
124 ElemRef(ElemRef) {}
125
126protected:
127 const void *getData1() const { return Data1; }
128 const void *getData2() const { return Data2.getPointer(); }
129 void setData2(const void *d) { Data2.setPointer(d); }
131
132public:
133
134
139
140
141
142 template
144 assert(T::isKind(*this));
145 T t;
147 PP = *this;
148 return t;
149 }
150
151
152
153 template std::optional getAs() const {
154 if (!T::isKind(*this))
155 return std::nullopt;
156 T t;
158 PP = *this;
159 return t;
160 }
161
163 unsigned x = Tag.getInt();
164 x <<= 2;
165 x |= L.getInt();
166 x <<= 2;
167 x |= Data2.getInt();
168 return (Kind) x;
169 }
170
171
172
178
180
182 return L.getPointer();
183 }
184
188
189
191 llvm::FoldingSetNodeID ID;
193 return ID.ComputeHash();
194 }
195
197 return Data1 == RHS.Data1 && Data2 == RHS.Data2 && L == RHS.L &&
198 Tag == RHS.Tag && ElemRef == RHS.ElemRef;
199 }
200
202 return Data1 != RHS.Data1 || Data2 != RHS.Data2 || L != RHS.L ||
203 Tag != RHS.Tag || ElemRef != RHS.ElemRef;
204 }
205
206 void Profile(llvm::FoldingSetNodeID& ID) const {
207 ID.AddInteger((unsigned) getKind());
211 ID.AddPointer(getTag());
212 ID.AddPointer(ElemRef.getParent());
213 ID.AddInteger(ElemRef.getIndexInBlock());
214 }
215
216 void printJson(llvm::raw_ostream &Out, const char *NL = "\n") const;
217
218 LLVM_DUMP_METHOD void dump() const;
219
223};
224
226public:
230 assert(CurrBlock && "BlockEntrance requires non-null block");
231 }
232
236
240
243 return B->empty() ? std::optional() : B->front();
244 }
245
246private:
249 static bool isKind(const ProgramPoint &Location) {
251 }
252};
253
255public:
258
262
266
267private:
270 static bool isKind(const ProgramPoint &Location) {
272 }
273};
274
275
277public:
283
285
286 template
288
289protected:
291private:
293 static bool isKind(const ProgramPoint &Location) {
294 unsigned k = Location.getKind();
296 }
297};
298
299
301public:
303 const Stmt *SubStmt = nullptr)
305
307
308private:
311 static bool isKind(const ProgramPoint &Location) {
312 return Location.getKind() == PreStmtKind;
313 }
314};
315
317protected:
322
323public:
327
331
332private:
334 static bool isKind(const ProgramPoint &Location) {
335 unsigned k = Location.getKind();
337 }
338};
339
341public:
346
350
354
355private:
358 static bool isKind(const ProgramPoint &Location) {
360 }
361};
362
363
365public:
369
370private:
373 static bool isKind(const ProgramPoint &Location) {
375 }
376};
377
379protected:
384
385private:
387 static bool isKind(const ProgramPoint &location) {
388 unsigned k = location.getKind();
390 }
391};
392
394public:
398
399private:
402 static bool isKind(const ProgramPoint &location) {
404 }
405};
406
408public:
412
413private:
416 static bool isKind(const ProgramPoint &location) {
418 }
419};
420
422public:
426
427private:
430 static bool isKind(const ProgramPoint &Location) {
432 }
433};
434
435
437public:
438
439
440
444 assert(getData2() == nullptr);
446 }
447
448
449
453
454private:
457 static bool isKind(const ProgramPoint &Location) {
459 }
460};
461
463public:
467
468private:
471 static bool isKind(const ProgramPoint &Location) {
473 }
474};
475
476
477
479public:
483
484private:
487 static bool isKind(const ProgramPoint &Location) {
489 }
490};
491
492
493
495public:
499
500private:
503 static bool isKind(const ProgramPoint &Location) {
505 }
506};
507
509public:
512 assert(B1 && "BlockEdge: source block must be non-null");
513 assert(B2 && "BlockEdge: destination block must be non-null");
514 }
515
519
523
524private:
527 static bool isKind(const ProgramPoint &Location) {
529 }
530};
531
533public:
534
535
536
537
538
543
547
548
552
553private:
556 static bool isKind(const ProgramPoint &Location) {
558 }
559};
560
561
562
563
565public:
569 : ProgramPoint(Loc.getPtrEncoding(), D, K, L, Tag, ElemRef) {}
570
575
576protected:
578private:
580 static bool isKind(const ProgramPoint &Location) {
583 }
584};
585
586
587
588
590public:
595
596private:
599 static bool isKind(const ProgramPoint &Location) {
601 }
602};
603
604
605
606
608public:
613
614private:
617 static bool isKind(const ProgramPoint &Location) {
619 }
620};
621
623public:
627
628private:
631 static bool isKind(const ProgramPoint &Location) {
633 }
634};
635
636
637
639public:
643
647
651
652
655 const CFG *CalleeCFG = CalleeCtx->getCFG();
656 return &(CalleeCFG->getEntry());
657 }
658
659private:
662 static bool isKind(const ProgramPoint &Location) {
664 }
665};
666
667
668
669
670
671
672
673
674
675
677public:
678
681
685
686private:
689 static bool isKind(const ProgramPoint &Location) {
691 }
692};
693
694
695
697public:
698
702
706
707private:
710 static bool isKind(const ProgramPoint &Location) {
712 }
713};
714
715
716
717
718
719
720
722public:
725
729
730private:
733 static bool isKind(const ProgramPoint &Location) {
735 }
736};
737
738
739
741public:
743 const void *Data2 = nullptr,
746
748
749private:
752 static bool isKind(const ProgramPoint &Location) {
753 return Location.getKind() == EpsilonKind;
754 }
755};
756
757}
758
759
760namespace llvm {
761
762template <> struct DenseMapInfo<clang::ProgramPoint> {
763
766 reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getEmptyKey()) & ~0x7;
768 nullptr);
769}
770
773 reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getTombstoneKey()) & ~0x7;
775 nullptr);
776}
777
781
786
787};
788
789}
790
791#endif
This file defines AnalysisDeclContext, a class that manages the analysis context data for context sen...
AnalysisDeclContext contains the context data for the function, method or block under analysis.
const CFGBlock * getSrc() const
Definition ProgramPoint.h:516
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:525
const CFGBlock * getDst() const
Definition ProgramPoint.h:520
BlockEdge(const CFGBlock *B1, const CFGBlock *B2, const LocationContext *L)
Definition ProgramPoint.h:510
Definition ProgramPoint.h:225
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:247
BlockEntrance(const CFGBlock *PrevBlock, const CFGBlock *CurrBlock, const LocationContext *L, const ProgramPointTag *Tag=nullptr)
Definition ProgramPoint.h:227
std::optional< CFGElement > getFirstElement() const
Definition ProgramPoint.h:241
const CFGBlock * getPreviousBlock() const
Definition ProgramPoint.h:233
const CFGBlock * getBlock() const
Definition ProgramPoint.h:237
const CFGBlock * getBlock() const
Definition ProgramPoint.h:259
const Stmt * getTerminator() const
Definition ProgramPoint.h:263
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:268
BlockExit(const CFGBlock *B, const LocationContext *L)
Definition ProgramPoint.h:256
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.
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:660
CallEnter(const Stmt *stmt, const StackFrameContext *calleeCtx, const LocationContext *callerCtx)
Definition ProgramPoint.h:640
const Stmt * getCallExpr() const
Definition ProgramPoint.h:644
const CFGBlock * getEntry() const
Returns the entry block in the CFG for the entered function.
Definition ProgramPoint.h:653
const StackFrameContext * getCalleeContext() const
Definition ProgramPoint.h:648
CallExitBegin(const StackFrameContext *L, const ReturnStmt *RS)
Definition ProgramPoint.h:679
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:687
const ReturnStmt * getReturnStmt() const
Definition ProgramPoint.h:682
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:708
CallExitEnd(const StackFrameContext *CalleeCtx, const LocationContext *CallerCtx)
Definition ProgramPoint.h:699
const StackFrameContext * getCalleeContext() const
Definition ProgramPoint.h:703
Decl - This represents one declaration (or definition), e.g.
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:750
EpsilonPoint(const LocationContext *L, const void *Data1, const void *Data2=nullptr, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:742
const void * getData() const
Definition ProgramPoint.h:747
const CFGBlock * getBlock() const
Definition ProgramPoint.h:347
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:356
const ReturnStmt * getStmt() const
Definition ProgramPoint.h:351
FunctionExitPoint(const ReturnStmt *S, const LocationContext *LC, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:342
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:579
SourceLocation getLocation() const
Definition ProgramPoint.h:572
ImplicitCallPoint(const Decl *D, SourceLocation Loc, Kind K, const LocationContext *L, const ProgramPointTag *Tag, CFGBlock::ConstCFGElementRef ElemRef)
Definition ProgramPoint.h:566
ImplicitCallPoint()=default
const Decl * getDecl() const
Definition ProgramPoint.h:571
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:386
LocationCheck(const Stmt *S, const LocationContext *L, ProgramPoint::Kind K, const ProgramPointTag *tag)
Definition ProgramPoint.h:381
It wraps the AnalysisDeclContext to represent both the call stack with the help of StackFrameContext ...
const StackFrameContext * getStackFrame() const
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:731
LoopExit(const Stmt *LoopStmt, const LocationContext *LC)
Definition ProgramPoint.h:723
const Stmt * getLoopStmt() const
Definition ProgramPoint.h:726
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:629
PostAllocatorCall(const Stmt *S, const LocationContext *L, const ProgramPointTag *Tag=nullptr)
Definition ProgramPoint.h:624
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:371
PostCondition(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:366
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:615
PostImplicitCall(const Decl *D, SourceLocation Loc, const LocationContext *L, CFGBlock::ConstCFGElementRef ElemRef, const ProgramPointTag *Tag=nullptr)
Definition ProgramPoint.h:609
PostInitializer(const CXXCtorInitializer *I, const void *Loc, const LocationContext *L)
Construct a PostInitializer point that represents a location after CXXCtorInitializer expression eval...
Definition ProgramPoint.h:539
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:554
const void * getLocationValue() const
Returns the location of the field.
Definition ProgramPoint.h:549
const CXXCtorInitializer * getInitializer() const
Definition ProgramPoint.h:544
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:469
PostLValue(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:464
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:428
PostLoad(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:423
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:501
PostStmtPurgeDeadSymbols(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:496
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:333
PostStmt(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:328
PostStmt(const Stmt *S, const void *data, Kind k, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:319
PostStmt(const Stmt *S, Kind k, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:324
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:455
PostStore(const Stmt *S, const LocationContext *L, const void *Loc, const ProgramPointTag *tag=nullptr)
Construct the post store point.
Definition ProgramPoint.h:441
const void * getLocationValue() const
Returns the information about the location used in the store, how it was uttered in the code.
Definition ProgramPoint.h:450
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:597
PreImplicitCall(const Decl *D, SourceLocation Loc, const LocationContext *L, CFGBlock::ConstCFGElementRef ElemRef, const ProgramPointTag *Tag=nullptr)
Definition ProgramPoint.h:591
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:400
PreLoad(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:395
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:485
PreStmtPurgeDeadSymbols(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:480
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:309
const Stmt * getSubStmt() const
Definition ProgramPoint.h:306
PreStmt(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag, const Stmt *SubStmt=nullptr)
Definition ProgramPoint.h:302
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:414
PreStore(const Stmt *S, const LocationContext *L, const ProgramPointTag *tag=nullptr)
Definition ProgramPoint.h:409
ProgramPoints can be "tagged" as representing points specific to a given analysis entity.
Definition ProgramPoint.h:38
const void * getTagKind() const
Used to implement 'isKind' in subclasses.
Definition ProgramPoint.h:48
virtual StringRef getDebugTag() const =0
The description of this program point which will be dumped for debugging purposes.
ProgramPointTag(void *tagKind=nullptr)
Definition ProgramPoint.h:40
virtual ~ProgramPointTag()
Definition ProgramPoint.h:61
const ProgramPointTag * getTag() const
Definition ProgramPoint.h:179
Kind getKind() const
Definition ProgramPoint.h:162
bool isPurgeKind()
Is this a program point corresponding to purge/removal of dead symbols and bindings.
Definition ProgramPoint.h:173
T castAs() const
Convert to the specified ProgramPoint type, asserting that this ProgramPoint is of the desired type.
Definition ProgramPoint.h:143
static ProgramPoint getProgramPoint(const Stmt *S, ProgramPoint::Kind K, const LocationContext *LC, const ProgramPointTag *tag)
static StringRef getProgramPointKindName(Kind K)
LLVM_DUMP_METHOD void dump() const
CFGBlock::ConstCFGElementRef getElementRef() const
Definition ProgramPoint.h:130
std::optional< SourceLocation > getSourceLocation() const
void Profile(llvm::FoldingSetNodeID &ID) const
Definition ProgramPoint.h:206
void printJson(llvm::raw_ostream &Out, const char *NL="\n") const
void setData2(const void *d)
Definition ProgramPoint.h:129
bool operator!=(const ProgramPoint &RHS) const
Definition ProgramPoint.h:201
bool operator==(const ProgramPoint &RHS) const
Definition ProgramPoint.h:196
unsigned getHashValue() const
Definition ProgramPoint.h:190
ProgramPoint(const void *P, Kind k, const LocationContext *l, const ProgramPointTag *tag=nullptr, CFGBlock::ConstCFGElementRef ElemRef={nullptr, 0})
Definition ProgramPoint.h:108
ProgramPoint(const void *P1, const void *P2, Kind k, const LocationContext *l, const ProgramPointTag *tag=nullptr, CFGBlock::ConstCFGElementRef ElemRef={nullptr, 0})
Definition ProgramPoint.h:119
ProgramPoint withTag(const ProgramPointTag *tag) const
Create a new ProgramPoint object that is the same as the original except for using the specified tag ...
Definition ProgramPoint.h:135
Kind
Definition ProgramPoint.h:63
@ PostLoadKind
Definition ProgramPoint.h:71
@ PreLoadKind
Definition ProgramPoint.h:70
@ EpsilonKind
Definition ProgramPoint.h:89
@ PostInitializerKind
Definition ProgramPoint.h:79
@ BlockExitKind
Definition ProgramPoint.h:65
@ MinPostStmtKind
Definition ProgramPoint.h:77
@ PostImplicitCallKind
Definition ProgramPoint.h:85
@ PreStmtKind
Definition ProgramPoint.h:66
@ PostConditionKind
Definition ProgramPoint.h:74
@ MaxPostStmtKind
Definition ProgramPoint.h:78
@ FunctionExitKind
Definition ProgramPoint.h:83
@ CallExitEndKind
Definition ProgramPoint.h:82
@ PreStmtPurgeDeadSymbolsKind
Definition ProgramPoint.h:67
@ MinImplicitCallKind
Definition ProgramPoint.h:86
@ LoopExitKind
Definition ProgramPoint.h:88
@ BlockEdgeKind
Definition ProgramPoint.h:63
@ PostStmtPurgeDeadSymbolsKind
Definition ProgramPoint.h:68
@ PostStmtKind
Definition ProgramPoint.h:69
@ CallEnterKind
Definition ProgramPoint.h:80
@ PostStoreKind
Definition ProgramPoint.h:73
@ PreImplicitCallKind
Definition ProgramPoint.h:84
@ PreStoreKind
Definition ProgramPoint.h:72
@ PostLValueKind
Definition ProgramPoint.h:75
@ MaxImplicitCallKind
Definition ProgramPoint.h:87
@ PostAllocatorCallKind
Definition ProgramPoint.h:76
@ BlockEntranceKind
Definition ProgramPoint.h:64
@ CallExitBeginKind
Definition ProgramPoint.h:81
const void * getData1() const
Definition ProgramPoint.h:127
const void * getData2() const
Definition ProgramPoint.h:128
const StackFrameContext * getStackFrame() const
Definition ProgramPoint.h:185
std::optional< T > getAs() const
Convert to the specified ProgramPoint type, returning std::nullopt if this ProgramPoint is not of the...
Definition ProgramPoint.h:153
const LocationContext * getLocationContext() const
Definition ProgramPoint.h:181
ReturnStmt - This represents a return, optionally of an expression: return; return 4;.
StringRef getDebugTag() const override
The description of this program point which will be dumped for debugging purposes.
SimpleProgramPointTag(StringRef MsgProvider, StringRef Msg)
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).
friend class ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition ProgramPoint.h:292
StmtPoint(const Stmt *S, const void *p2, Kind k, const LocationContext *L, const ProgramPointTag *tag)
Definition ProgramPoint.h:278
const Stmt * getStmt() const
Definition ProgramPoint.h:284
const T * getStmtAs() const
Definition ProgramPoint.h:287
Stmt - This represents one statement.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
The JSON file list parser is used to communicate input to InstallAPI.
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
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)
Definition ProgramPoint.h:782
static clang::ProgramPoint getTombstoneKey()
Definition ProgramPoint.h:771
static unsigned getHashValue(const clang::ProgramPoint &Loc)
Definition ProgramPoint.h:778
static clang::ProgramPoint getEmptyKey()
Definition ProgramPoint.h:764