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
32class AnalysisDeclContext;
33class LocationContext;
34
35
36
37
39public:
43
44
45 const void *getTagKind() const { return TagKind; }
46
47private:
48 const void *const TagKind;
49};
50
52 std::string Desc;
53public:
56};
57
59public:
87
88private:
89 const void *Data1;
90 llvm::PointerIntPair<const void *, 2, unsigned> Data2;
91
92
93
94 llvm::PointerIntPair<const LocationContext *, 2, unsigned> L;
95
96 llvm::PointerIntPair<const ProgramPointTag *, 2, unsigned> Tag;
97
99
100protected:
105 : Data1(P), Data2(nullptr, (((unsigned)k) >> 0) & 0x3),
106 L(l, (((unsigned)k) >> 2) & 0x3), Tag(tag, (((unsigned)k) >> 4) & 0x3),
107 ElemRef(ElemRef) {
111 }
112
116 : Data1(P1), Data2(P2, (((unsigned)k) >> 0) & 0x3),
117 L(l, (((unsigned)k) >> 2) & 0x3), Tag(tag, (((unsigned)k) >> 4) & 0x3),
118 ElemRef(ElemRef) {}
119
120protected:
121 const void *getData1() const { return Data1; }
122 const void *getData2() const { return Data2.getPointer(); }
123 void setData2(const void *d) { Data2.setPointer(d); }
125
126public:
127
128
132 }
133
134
135
136 template
138 assert(T::isKind(*this));
139 T t;
141 PP = *this;
142 return t;
143 }
144
145
146
147 template std::optional getAs() const {
148 if (!T::isKind(*this))
149 return std::nullopt;
150 T t;
152 PP = *this;
153 return t;
154 }
155
157 unsigned x = Tag.getInt();
158 x <<= 2;
159 x |= L.getInt();
160 x <<= 2;
161 x |= Data2.getInt();
162 return (Kind) x;
163 }
164
165
166
171 }
172
174
176 return L.getPointer();
177 }
178
181 }
182
183
185 llvm::FoldingSetNodeID ID;
187 return ID.ComputeHash();
188 }
189
191 return Data1 == RHS.Data1 && Data2 == RHS.Data2 && L == RHS.L &&
192 Tag == RHS.Tag && ElemRef == RHS.ElemRef;
193 }
194
196 return Data1 != RHS.Data1 || Data2 != RHS.Data2 || L != RHS.L ||
197 Tag != RHS.Tag || ElemRef != RHS.ElemRef;
198 }
199
200 void Profile(llvm::FoldingSetNodeID& ID) const {
201 ID.AddInteger((unsigned) getKind());
206 ID.AddPointer(ElemRef.getParent());
207 ID.AddInteger(ElemRef.getIndexInBlock());
208 }
209
210 void printJson(llvm::raw_ostream &Out, const char *NL = "\n") const;
211
212 LLVM_DUMP_METHOD void dump() const;
213
217};
218
220public:
224 assert(B && "BlockEntrance requires non-null block");
225 }
226
229 }
230
233 return B->empty() ? std::optional() : B->front();
234 }
235
236private:
239 static bool isKind(const ProgramPoint &Location) {
241 }
242};
243
245public:
248
251 }
252
255 }
256
257private:
260 static bool isKind(const ProgramPoint &Location) {
262 }
263};
264
265
267public:
271 assert(S);
272 }
273
275
276 template
278
279protected:
281private:
283 static bool isKind(const ProgramPoint &Location) {
284 unsigned k = Location.getKind();
286 }
287};
288
289
291public:
293 const Stmt *SubStmt = nullptr)
295
297
298private:
301 static bool isKind(const ProgramPoint &Location) {
303 }
304};
305
307protected:
311 : StmtPoint(S, data, k, L, tag) {}
312
313public:
316 : StmtPoint(S, nullptr, k, L, tag) {}
317
321
322private:
324 static bool isKind(const ProgramPoint &Location) {
325 unsigned k = Location.getKind();
327 }
328};
329
331public:
336
339 }
340
343 }
344
345private:
348 static bool isKind(const ProgramPoint &Location) {
350 }
351};
352
353
355public:
359
360private:
363 static bool isKind(const ProgramPoint &Location) {
365 }
366};
367
369protected:
373 : StmtPoint(S, nullptr, K, L, tag) {}
374
375private:
377 static bool isKind(const ProgramPoint &location) {
378 unsigned k = location.getKind();
380 }
381};
382
384public:
388
389private:
392 static bool isKind(const ProgramPoint &location) {
394 }
395};
396
398public:
402
403private:
406 static bool isKind(const ProgramPoint &location) {
408 }
409};
410
412public:
416
417private:
420 static bool isKind(const ProgramPoint &Location) {
422 }
423};
424
425
427public:
428
429
430
434 assert(getData2() == nullptr);
436 }
437
438
439
442 }
443
444private:
447 static bool isKind(const ProgramPoint &Location) {
449 }
450};
451
453public:
457
458private:
461 static bool isKind(const ProgramPoint &Location) {
463 }
464};
465
466
467
469public:
473
474private:
477 static bool isKind(const ProgramPoint &Location) {
479 }
480};
481
482
483
485public:
489
490private:
493 static bool isKind(const ProgramPoint &Location) {
495 }
496};
497
499public:
502 assert(B1 && "BlockEdge: source block must be non-null");
503 assert(B2 && "BlockEdge: destination block must be non-null");
504 }
505
508 }
509
512 }
513
514private:
517 static bool isKind(const ProgramPoint &Location) {
519 }
520};
521
523public:
524
525
526
527
528
530 const void *Loc,
533
536 }
537
538
541 }
542
543private:
546 static bool isKind(const ProgramPoint &Location) {
548 }
549};
550
551
552
553
555public:
559 : ProgramPoint(Loc.getPtrEncoding(), D, K, L, Tag, ElemRef) {}
560
564 }
565
566protected:
568private:
570 static bool isKind(const ProgramPoint &Location) {
573 }
574};
575
576
577
578
580public:
585
586private:
589 static bool isKind(const ProgramPoint &Location) {
591 }
592};
593
594
595
596
598public:
603
604private:
607 static bool isKind(const ProgramPoint &Location) {
609 }
610};
611
613public:
617
618private:
621 static bool isKind(const ProgramPoint &Location) {
623 }
624};
625
626
627
629public:
633
635 return static_cast<const Stmt *>(getData1());
636 }
637
640 }
641
642
645 const CFG *CalleeCFG = CalleeCtx->getCFG();
646 return &(CalleeCFG->getEntry());
647 }
648
649private:
652 static bool isKind(const ProgramPoint &Location) {
654 }
655};
656
657
658
659
660
661
662
663
664
665
667public:
668
671
674 }
675
676private:
679 static bool isKind(const ProgramPoint &Location) {
681 }
682};
683
684
685
687public:
688
692
695 }
696
697private:
700 static bool isKind(const ProgramPoint &Location) {
702 }
703};
704
705
706
707
708
709
710
712public:
715
717 return static_cast<const Stmt *>(getData1());
718 }
719
720private:
723 static bool isKind(const ProgramPoint &Location) {
725 }
726};
727
728
729
731public:
733 const void *Data2 = nullptr,
736
738
739private:
742 static bool isKind(const ProgramPoint &Location) {
744 }
745};
746
747}
748
749
750namespace llvm {
751
752template <> struct DenseMapInfo<clang::ProgramPoint> {
753
756 reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getEmptyKey()) & ~0x7;
758}
759
762 reinterpret_cast<uintptr_t>(DenseMapInfo<void*>::getTombstoneKey()) & ~0x7;
764}
765
767 return Loc.getHashValue();
768}
769
772 return L == R;
773}
774
775};
776
777}
778
779#endif
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()