clang: include/clang/Analysis/CFG.h Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14#ifndef LLVM_CLANG_ANALYSIS_CFG_H
15#define LLVM_CLANG_ANALYSIS_CFG_H
16
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/GraphTraits.h"
25#include "llvm/ADT/PointerIntPair.h"
26#include "llvm/ADT/iterator_range.h"
27#include "llvm/Support/Allocator.h"
28#include "llvm/Support/raw_ostream.h"
29#include
30#include
31#include
32#include
33#include
34#include
35#include
36
38
53
54
56public:
81
82protected:
83
84 llvm::PointerIntPair<void *, 2> Data1;
85 llvm::PointerIntPair<void *, 2> Data2;
86
92
94
95public:
96
97
98 template
100 assert(T::isKind(*this));
101 T t;
103 e = *this;
104 return t;
105 }
106
107
108
109 template std::optional getAs() const {
110 if (!T::isKind(*this))
111 return std::nullopt;
112 T t;
114 e = *this;
115 return t;
116 }
117
119 unsigned x = Data2.getInt();
120 x <<= 2;
121 x |= Data1.getInt();
122 return (Kind) x;
123 }
124
126 bool TerminateWithNewLine = true) const;
127
131};
132
134public:
136 assert(isKind(*this));
137 }
138
140 return static_cast<const Stmt *>(Data1.getPointer());
141 }
142
143private:
145
146 static bool isKind(const CFGElement &E) {
148 }
149
150protected:
152};
153
154
155
156
158public:
165
169
170private:
172
174
175 static bool isKind(const CFGElement &E) {
177 }
178};
179
180
181
182
183
184
185
187public:
188
189
198
211
215
216private:
218
220
221 static bool isKind(const CFGElement &E) {
223 }
224};
225
226
227
229public:
232
236
237private:
239
241
242 static bool isKind(const CFGElement &E) {
244 }
245};
246
247
249public:
252
253
257
258private:
260
262
263 static bool isKind(const CFGElement &elem) {
265 }
266};
267
268
269
270
271
272
273
275public:
277
279 return static_cast<Stmt *>(Data1.getPointer());
280 }
281
282private:
284
286
287 static bool isKind(const CFGElement &elem) {
289 }
290};
291
292
294public:
297
299 return static_cast<VarDecl *>(Data1.getPointer());
300 }
301
303 return static_cast<Stmt *>(Data2.getPointer());
304 }
305
306private:
308
310
311 static bool isKind(const CFGElement &elem) {
313 }
314};
315
316
317
319public:
323
324
326 return static_cast<Stmt*>(Data2.getPointer());
327 }
328
329
331 return static_cast<VarDecl *>(Data1.getPointer());
332 }
333
334private:
336 static bool isKind(const CFGElement &E) {
339 }
340};
341
342
343
345public:
348
350 return static_cast<VarDecl *>(Data1.getPointer());
351 }
352
354 return static_cast<Stmt *>(Data2.getPointer());
355 }
356
357private:
359 static bool isKind(const CFGElement &E) {
362 }
363};
364
365
366
368protected:
370
375
376public:
379
380private:
382
383 static bool isKind(const CFGElement &E) {
386 }
387};
388
390public:
394 assert(VD->hasAttr());
395 }
396
398 return static_cast<VarDecl *>(Data1.getPointer());
399 }
400
401
404 return A->getFunctionDecl();
405 }
406
407private:
409
410 static bool isKind(const CFGElement E) {
412 }
413};
414
415
416
417
419public:
422
426
427
429 return static_cast<Stmt*>(Data2.getPointer());
430 }
431
432private:
434
436
437 static bool isKind(const CFGElement &elem) {
439 }
440};
441
442
444public:
447
451
452
456
457private:
459
461
462 static bool isKind(const CFGElement &elem) {
464 }
465};
466
467
468
470public:
473
477
478private:
480
482
483 static bool isKind(const CFGElement &E) {
485 }
486};
487
488
489
491public:
494
498
499private:
501
503
504 static bool isKind(const CFGElement &E) {
506 }
507};
508
509
510
512public:
515
519
520private:
522
524
525 static bool isKind(const CFGElement &E) {
527 }
528};
529
530
531
533public:
535
536
538
539
540
542
543
544
546
547
548
549
551 };
552
553private:
554 static constexpr int KindBits = 2;
556 "Not enough room for kind!");
557 llvm::PointerIntPair<Stmt *, KindBits> Data;
558
559public:
562
563 bool isValid() const { return Data.getOpaqueValue() != nullptr; }
565 const Stmt *getStmt() const { return Data.getPointer(); }
567
577};
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
606 class ElementList {
608
609 ImplTy Impl;
610
611 public:
613
614 using iterator = std::reverse_iteratorImplTy::iterator;
615 using const_iterator = std::reverse_iteratorImplTy::const\_iterator;
619
621
624 return Impl.insert(I, Cnt, E, C);
625 }
626
627 const_reference front() const { return Impl.back(); }
628 const_reference back() const { return Impl.front(); }
629
638
640 assert(i < Impl.size());
641 return Impl[Impl.size() - 1 - i];
642 }
643
644 size_t size() const { return Impl.size(); }
645 bool empty() const { return Impl.empty(); }
646 };
647
648
649
650
651 template class ElementRefImpl {
652
653 template friend class ElementRefImpl;
654
655 using CFGBlockPtr =
656 std::conditional_t<IsConst, const CFGBlock *, CFGBlock *>;
657
658 using CFGElementPtr =
659 std::conditional_t<IsConst, const CFGElement *, CFGElement *>;
660
661 protected:
662 CFGBlockPtr Parent;
663 size_t Index;
664
665 public:
666 ElementRefImpl(CFGBlockPtr Parent, size_t Index)
667 : Parent(Parent), Index(Index) {}
668
669 template
670 ElementRefImpl(ElementRefImpl Other)
671 : ElementRefImpl(Other.Parent, Other.Index) {}
672
673 size_t getIndexInBlock() const { return Index; }
674
675 CFGBlockPtr getParent() { return Parent; }
676 CFGBlockPtr getParent() const { return Parent; }
677
679 return std::make_pair(Parent, Index) <
680 std::make_pair(Other.Parent, Other.Index);
681 }
682
684 return Parent == Other.Parent && Index == Other.Index;
685 }
686
689 CFGElementPtr operator->() const { return &*(Parent->begin() + Index); }
690
691 void dumpToStream(llvm::raw_ostream &OS) const {
692 OS << getIndexInBlock() + 1 << ": ";
693 (*this)->dumpToStream(OS);
694 }
695
696 void dump() const {
697 dumpToStream(llvm::errs());
698 }
699
700 void Profile(llvm::FoldingSetNodeID &ID) const {
701 ID.AddPointer(Parent);
702 ID.AddInteger(Index);
703 }
704 };
705
706 template <bool IsReverse, bool IsConst> class ElementRefIterator {
707
708 template <bool IsOtherReverse, bool IsOtherConst>
709 friend class ElementRefIterator;
710
711 using CFGBlockRef =
712 std::conditional_t<IsConst, const CFGBlock *, CFGBlock *>;
713
714 using UnderlayingIteratorTy = std::conditional_t<
715 IsConst,
716 std::conditional_t<IsReverse, ElementList::const_reverse_iterator,
717 ElementList::const_iterator>,
718 std::conditional_t<IsReverse, ElementList::reverse_iterator,
719 ElementList::iterator>>;
720
721 using IteratorTraits = typename std::iterator_traits;
722 using ElementRef = typename CFGBlock::ElementRefImpl;
723
724 public:
725 using difference_type = typename IteratorTraits::difference_type;
726 using value_type = ElementRef;
727 using pointer = ElementRef *;
728 using iterator_category = typename IteratorTraits::iterator_category;
729
730 private:
731 CFGBlockRef Parent;
732 UnderlayingIteratorTy Pos;
733
734 public:
735 ElementRefIterator(CFGBlockRef Parent, UnderlayingIteratorTy Pos)
736 : Parent(Parent), Pos(Pos) {}
737
738 template
739 ElementRefIterator(ElementRefIterator<false, IsOtherConst> E)
740 : ElementRefIterator(E.Parent, E.Pos.base()) {}
741
742 template
743 ElementRefIterator(ElementRefIterator<true, IsOtherConst> E)
744 : ElementRefIterator(E.Parent, std::make_reverse_iterator(E.Pos)) {}
745
747 assert(Parent == Other.Parent);
748 return Pos < Other.Pos;
749 }
750
752 return Parent == Other.Parent && Pos == Other.Pos;
753 }
754
756 return !(*this == Other);
757 }
758
759 private:
760 template
761 static size_t
762 getIndexInBlock(CFGBlock::ElementRefIterator<true, IsOtherConst> E) {
763 return E.Parent->size() - (E.Pos - E.Parent->rbegin()) - 1;
764 }
765
766 template
767 static size_t
768 getIndexInBlock(CFGBlock::ElementRefIterator<false, IsOtherConst> E) {
769 return E.Pos - E.Parent->begin();
770 }
771
772 public:
773 value_type operator*() { return {Parent, getIndexInBlock(*this)}; }
774
775 difference_type operator-(ElementRefIterator Other) const {
776 return Pos - Other.Pos;
777 }
778
779 ElementRefIterator operator++() {
780 ++this->Pos;
781 return *this;
782 }
783 ElementRefIterator operator++(int) {
784 ElementRefIterator Ret = *this;
785 ++*this;
786 return Ret;
787 }
788 ElementRefIterator operator+(size_t count) {
789 this->Pos += count;
790 return *this;
791 }
792 ElementRefIterator operator-(size_t count) {
793 this->Pos -= count;
794 return *this;
795 }
796 };
797
798public:
799
801
802
803
804
806
807
808
810
811
812
813
815
816
818
819public:
820
821
822
823
824
826 enum Kind {
827 AB_Normal,
828 AB_Unreachable,
829 AB_Alternate
830 };
831
833 llvm::PointerIntPair<CFGBlock *, 2> UnreachableBlock;
834
835 public:
836
838
839
840
842
843
845 return ReachableBlock;
846 }
847
848
850 return UnreachableBlock.getPointer();
851 }
852
853
854
858
862
866
868 Kind K = (Kind) UnreachableBlock.getInt();
869 return K == AB_Normal || K == AB_Alternate;
870 }
871 };
872
873private:
874
876 AdjacentBlocks Preds;
877 AdjacentBlocks Succs;
878
879
880
881
882
883
884
885
886
887
888 LLVM_PREFERRED_TYPE(bool)
889 unsigned HasNoReturnElement : 1;
890
891
892 CFG *Parent;
893
894public:
897 Succs(C, 1), HasNoReturnElement(false), Parent(parent) {}
898
899
904
906
909
914
919
922
927
930
933 llvm::iterator_range<const_reverse_ref_iterator>;
934
939
944
951
954
956
957
962 using pred_range = llvm::iterator_range<pred_iterator>;
964
969 using succ_range = llvm::iterator_range<succ_iterator>;
971
976
981
985
989
994
999
1003
1007
1008 unsigned succ_size() const { return Succs.size(); }
1010
1011 unsigned pred_size() const { return Preds.size(); }
1013
1014
1016 public:
1017 LLVM_PREFERRED_TYPE(bool)
1019 LLVM_PREFERRED_TYPE(bool)
1021
1024 };
1025
1028
1029 template <typename IMPL, bool IsPred>
1031 private:
1035
1036 public:
1040 : I(i), E(e), F(f), From(from) {
1041 while (hasMore() && Filter(*I))
1042 ++I;
1043 }
1044
1046
1048 do { ++I; } while (hasMore() && Filter(*I));
1049 return *this;
1050 }
1051
1053
1054 private:
1055 bool Filter(const CFGBlock *To) {
1057 }
1058 };
1059
1062
1065
1069
1073
1074
1075
1080
1081
1082
1084
1086
1089
1090
1091
1092
1093
1094
1095
1097
1099
1103
1105
1108
1110
1112
1114
1115 void dump() const;
1116
1117 void dump(const CFG *cfg, const LangOptions &LO, bool ShowColors = false) const;
1119 bool ShowColors) const;
1120
1123 bool AddQuotes) const;
1124
1128
1129
1131
1135
1140
1146
1151
1156
1161
1165
1169
1173
1177
1181
1185
1189
1193
1197};
1198
1200
1201
1202
1204public:
1207
1211 bool isAlwaysTrue) {}
1213};
1214
1215
1216
1217
1218
1219
1220
1221
1223public:
1224
1225
1226
1227
1229
1230
1231 std::bitset<Stmt::lastStmtConstant + 1> alwaysAddMask;
1232
1233 public:
1234 using ForcedBlkExprs = llvm::DenseMap<const Stmt *, const CFGBlock *>;
1235
1255
1257
1259 return alwaysAddMask[stmt->getStmtClass()];
1260 }
1261
1263 alwaysAddMask[stmtClass] = val;
1264 return *this;
1265 }
1266
1268 alwaysAddMask.set();
1269 return *this;
1270 }
1271 };
1272
1273
1275 const BuildOptions &BO);
1276
1277
1278
1280
1281
1282
1283
1285
1286
1287
1289
1290
1291
1292
1293
1299
1302
1307
1310
1311 llvm::iterator_range nodes() { return {begin(), end()}; }
1315
1318
1323
1330
1335
1338
1341
1343 return TryDispatchBlocks.begin();
1344 }
1345
1347 return TryDispatchBlocks.end();
1348 }
1349
1353
1355 TryDispatchBlocks.push_back(block);
1356 }
1357
1358
1359
1360
1361
1364 assert(Synthetic->isSingleDecl() && "Can handle single declarations only");
1365 assert(Synthetic != Source && "Don't include original DeclStmts in map");
1366 assert(!SyntheticDeclStmts.count(Synthetic) && "Already in map");
1367 SyntheticDeclStmts[Synthetic] = Source;
1368 }
1369
1371 llvm::DenseMap<const DeclStmt *, const DeclStmt *>::const_iterator;
1373
1374
1375
1376
1377
1378
1380 return SyntheticDeclStmts.begin();
1381 }
1382
1383
1385 return SyntheticDeclStmts.end();
1386 }
1387
1388
1392
1393
1394
1395
1396
1399 for (const CFGElement &Elem : *BB) {
1400 if (std::optional stmt = Elem.getAs<CFGStmt>())
1401 O(const_cast<Stmt *>(stmt->getStmt()));
1402 }
1403 }
1404
1405
1406
1407
1408
1409
1411
1412
1413
1414
1415 unsigned size() const { return NumBlockIDs; }
1416
1417
1418
1419
1420
1422
1423
1424
1425
1426
1428 void print(raw_ostream &OS, const LangOptions &LO, bool ShowColors) const;
1429 void dump(const LangOptions &LO, bool ShowColors) const;
1430
1431
1432
1433
1434
1435 CFG() : Blocks(BlkBVC, 10) {}
1436
1438 return BlkBVC.getAllocator();
1439 }
1440
1442 return BlkBVC;
1443 }
1444
1445private:
1448
1449
1450 CFGBlock* IndirectGotoBlock = nullptr;
1451
1452 unsigned NumBlockIDs = 0;
1453
1455
1457
1458
1459
1460 std::vector<const CFGBlock *> TryDispatchBlocks;
1461
1462
1463
1464 llvm::DenseMap<const DeclStmt *, const DeclStmt *> SyntheticDeclStmts;
1465};
1466
1468
1469}
1470
1471
1472
1473
1474
1475namespace llvm {
1476
1477
1478
1486
1487
1488
1497
1499 using NodeRef = const ::clang::CFGBlock *;
1501
1505};
1506
1510
1512 return G.Graph;
1513 }
1514
1517};
1518
1520 using NodeRef = const ::clang::CFGBlock *;
1522
1524 return G.Graph;
1525 }
1526
1529};
1530
1531
1532
1534 : public GraphTraits< ::clang::CFGBlock *> {
1536
1541};
1542
1544 : public GraphTraits<const ::clang::CFGBlock *> {
1546
1548
1550 return F->nodes_begin();
1551 }
1552
1554 return F->nodes_end();
1555 }
1556
1557 static unsigned size(const ::clang::CFG* F) {
1558 return F->size();
1559 }
1560};
1561
1562template <> struct GraphTraits<Inverse< ::clang::CFG *>>
1563 : public GraphTraits<Inverse< ::clang::CFGBlock *>> {
1565
1569};
1570
1571template <> struct GraphTraits<Inverse<const ::clang::CFG *>>
1572 : public GraphTraits<Inverse<const ::clang::CFGBlock *>> {
1574
1576
1578 return F->nodes_begin();
1579 }
1580
1582 return F->nodes_end();
1583 }
1584};
1585
1586}
1587
1588#endif
clang::CharUnits operator*(clang::CharUnits::QuantityType Scale, const clang::CharUnits &CU)
Defines the clang::Expr interface and subclasses for C++ expressions.
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
Holds long-lived AST nodes (such as types and decls) that can be referred to throughout the semantic ...
A builtin binary operation expression such as "x + y" or "x <= y".
std::reverse_iterator< const_iterator > const_reverse_iterator
const CFGElement & const_reference
std::reverse_iterator< iterator > reverse_iterator
const CFGElement * const_iterator
Represents C++ object destructor implicitly generated for automatic object or temporary bound to cons...
Definition CFG.h:418
const VarDecl * getVarDecl() const
Definition CFG.h:423
const Stmt * getTriggerStmt() const
Definition CFG.h:428
friend class CFGElement
Definition CFG.h:433
CFGAutomaticObjDtor(const VarDecl *var, const Stmt *stmt)
Definition CFG.h:420
Represents C++ object destructor implicitly generated for base object in destructor.
Definition CFG.h:469
friend class CFGElement
Definition CFG.h:479
CFGBaseDtor(const CXXBaseSpecifier *base)
Definition CFG.h:471
const CXXBaseSpecifier * getBaseSpecifier() const
Definition CFG.h:474
CFGBlock & operator*() const
Definition CFG.h:859
AdjacentBlock(CFGBlock *B, bool IsReachable)
Construct an AdjacentBlock with a possibly unreachable block.
CFGBlock * operator->() const
Definition CFG.h:863
CFGBlock * getReachableBlock() const
Get the reachable block, if one exists.
Definition CFG.h:844
bool isReachable() const
Definition CFG.h:867
CFGBlock * getPossiblyUnreachableBlock() const
Get the potentially unreachable block.
Definition CFG.h:849
unsigned IgnoreNullPredecessors
Definition CFG.h:1018
unsigned IgnoreDefaultsWithCoveredEnums
Definition CFG.h:1020
FilterOptions()
Definition CFG.h:1022
FilteredCFGBlockIterator & operator++()
Definition CFG.h:1047
const CFGBlock * operator*() const
Definition CFG.h:1052
FilteredCFGBlockIterator(const IMPL &i, const IMPL &e, const CFGBlock *from, const FilterOptions &f)
Definition CFG.h:1037
bool hasMore() const
Definition CFG.h:1045
Represents a single basic block in a source-level CFG.
Definition CFG.h:605
void appendAutomaticObjDtor(VarDecl *VD, Stmt *S, BumpVectorContext &C)
Definition CFG.h:1178
void printTerminator(raw_ostream &OS, const LangOptions &LO) const
printTerminator - A simple pretty printer of the terminator of a CFGBlock.
ElementList::reverse_iterator reverse_iterator
Definition CFG.h:902
ElementList::iterator iterator
Definition CFG.h:900
void setLoopTarget(const Stmt *loopTarget)
Definition CFG.h:1078
bool isInevitablySinking() const
Returns true if the block would eventually end with a sink (a noreturn node).
filtered_pred_iterator filtered_pred_start_end(const FilterOptions &f) const
Definition CFG.h:1066
pred_iterator pred_end()
Definition CFG.h:973
size_t getIndexInCFG() const
succ_iterator succ_end()
Definition CFG.h:991
void appendScopeBegin(const VarDecl *VD, const Stmt *S, BumpVectorContext &C)
Definition CFG.h:1157
AdjacentBlocks::reverse_iterator pred_reverse_iterator
Definition CFG.h:960
const_reverse_iterator rend() const
Definition CFG.h:918
CFGElement operator[](size_t i) const
Definition CFG.h:955
llvm::iterator_range< pred_iterator > pred_range
Definition CFG.h:962
const_reverse_ref_iterator_range rrefs() const
Definition CFG.h:948
llvm::iterator_range< const_succ_iterator > succ_const_range
Definition CFG.h:970
static bool FilterEdge(const FilterOptions &F, const CFGBlock *Src, const CFGBlock *Dst)
ElementRefIterator< false, false > ref_iterator
Definition CFG.h:923
ref_iterator ref_begin()
Definition CFG.h:935
reverse_iterator rbegin()
Definition CFG.h:915
void setTerminator(CFGTerminator Term)
Definition CFG.h:1076
void printAsOperand(raw_ostream &OS, bool)
Definition CFG.h:1125
void appendMemberDtor(FieldDecl *FD, BumpVectorContext &C)
Definition CFG.h:1170
filtered_succ_iterator filtered_succ_start_end(const FilterOptions &f) const
Definition CFG.h:1070
llvm::iterator_range< reverse_ref_iterator > reverse_ref_iterator_range
Definition CFG.h:929
void appendLifetimeEnds(VarDecl *VD, Stmt *S, BumpVectorContext &C)
Definition CFG.h:1186
void print(raw_ostream &OS, const CFG *cfg, const LangOptions &LO, bool ShowColors) const
print - A simple pretty printer of a CFGBlock that outputs to an ostream.
ElementList::const_iterator const_iterator
Definition CFG.h:901
const Stmt * getLabel() const
Definition CFG.h:1107
reverse_iterator rend()
Definition CFG.h:916
AdjacentBlocks::iterator pred_iterator
Definition CFG.h:958
pred_reverse_iterator pred_rend()
Definition CFG.h:978
bool hasNoReturnElement() const
Definition CFG.h:1109
CFGElement back() const
Definition CFG.h:908
ElementList::const_reverse_iterator const_reverse_iterator
Definition CFG.h:903
succ_reverse_iterator succ_rend()
Definition CFG.h:996
ElementRefIterator< true, false > reverse_ref_iterator
Definition CFG.h:928
CFGElement front() const
Definition CFG.h:907
const_reverse_ref_iterator rref_end() const
Definition CFG.h:943
unsigned size() const
Definition CFG.h:952
const_succ_iterator succ_begin() const
Definition CFG.h:992
void appendDeleteDtor(CXXRecordDecl *RD, CXXDeleteExpr *DE, BumpVectorContext &C)
Definition CFG.h:1194
void appendScopeEnd(const VarDecl *VD, const Stmt *S, BumpVectorContext &C)
Definition CFG.h:1162
const_pred_iterator pred_end() const
Definition CFG.h:975
const_iterator begin() const
Definition CFG.h:912
void appendInitializer(CXXCtorInitializer *initializer, BumpVectorContext &C)
Definition CFG.h:1147
unsigned BlockID
A numerical ID assigned to a CFGBlock during construction of the CFG.
Definition CFG.h:817
iterator begin()
Definition CFG.h:910
FilteredCFGBlockIterator< const_pred_iterator, true > filtered_pred_iterator
Definition CFG.h:1060
const_pred_reverse_iterator pred_rbegin() const
Definition CFG.h:979
succ_reverse_iterator succ_rbegin()
Definition CFG.h:995
void printTerminatorJson(raw_ostream &Out, const LangOptions &LO, bool AddQuotes) const
printTerminatorJson - Pretty-prints the terminator in JSON format.
llvm::iterator_range< ref_iterator > ref_iterator_range
Definition CFG.h:924
succ_range succs()
Definition CFG.h:1000
bool empty() const
Definition CFG.h:953
AdjacentBlocks::const_reverse_iterator const_succ_reverse_iterator
Definition CFG.h:968
ref_iterator_range refs()
Definition CFG.h:945
ElementRefIterator< false, true > const_ref_iterator
Definition CFG.h:925
ElementRefImpl< true > ConstCFGElementRef
Definition CFG.h:921
void appendNewAllocator(CXXNewExpr *NE, BumpVectorContext &C)
Definition CFG.h:1152
CFGBlock(unsigned blockid, BumpVectorContext &C, CFG *parent)
Definition CFG.h:895
Stmt * Label
An (optional) label that prefixes the executable statements in the block.
Definition CFG.h:805
const_ref_iterator ref_begin() const
Definition CFG.h:937
Stmt * getLabel()
Definition CFG.h:1106
CFGTerminator getTerminator() const
Definition CFG.h:1085
succ_iterator succ_begin()
Definition CFG.h:990
Stmt * getTerminatorStmt()
Definition CFG.h:1087
const_succ_reverse_iterator succ_rend() const
Definition CFG.h:998
void appendTemporaryDtor(CXXBindTemporaryExpr *E, BumpVectorContext &C)
Definition CFG.h:1174
const Stmt * getLoopTarget() const
Definition CFG.h:1104
AdjacentBlocks::const_iterator const_pred_iterator
Definition CFG.h:959
succ_const_range succs() const
Definition CFG.h:1004
unsigned pred_size() const
Definition CFG.h:1011
void appendBaseDtor(const CXXBaseSpecifier *BS, BumpVectorContext &C)
Definition CFG.h:1166
AdjacentBlocks::iterator succ_iterator
Definition CFG.h:965
void appendCXXRecordTypedCall(Expr *E, const ConstructionContext *CC, BumpVectorContext &C)
Definition CFG.h:1141
FilteredCFGBlockIterator< const_succ_iterator, false > filtered_succ_iterator
Definition CFG.h:1063
pred_const_range preds() const
Definition CFG.h:986
ElementList Elements
The set of statements in the basic block.
Definition CFG.h:800
llvm::iterator_range< const_reverse_ref_iterator > const_reverse_ref_iterator_range
Definition CFG.h:932
const_reverse_iterator rbegin() const
Definition CFG.h:917
ElementRefImpl< false > CFGElementRef
Definition CFG.h:920
ref_iterator ref_end()
Definition CFG.h:936
pred_reverse_iterator pred_rbegin()
Definition CFG.h:977
ElementRefIterator< true, true > const_reverse_ref_iterator
Definition CFG.h:931
pred_iterator pred_begin()
Definition CFG.h:972
const Stmt * LoopTarget
Some blocks are used to represent the "loop edge" to the start of a loop from within the loop body.
Definition CFG.h:814
reverse_ref_iterator rref_begin()
Definition CFG.h:940
iterator end()
Definition CFG.h:911
CFG * getParent() const
Definition CFG.h:1113
void appendCleanupFunction(const VarDecl *VD, BumpVectorContext &C)
Definition CFG.h:1182
pred_range preds()
Definition CFG.h:982
reverse_ref_iterator rref_end()
Definition CFG.h:941
const Stmt * getTerminatorStmt() const
Definition CFG.h:1088
const_ref_iterator_range refs() const
Definition CFG.h:946
const_iterator end() const
Definition CFG.h:913
const_ref_iterator ref_end() const
Definition CFG.h:938
void setLabel(Stmt *Statement)
Definition CFG.h:1077
unsigned getBlockID() const
Definition CFG.h:1111
const_succ_reverse_iterator succ_rbegin() const
Definition CFG.h:997
void appendStmt(Stmt *statement, BumpVectorContext &C)
Definition CFG.h:1132
llvm::iterator_range< const_ref_iterator > const_ref_iterator_range
Definition CFG.h:926
void setHasNoReturnElement()
Definition CFG.h:1079
const_pred_iterator pred_begin() const
Definition CFG.h:974
const Stmt * getTerminatorCondition(bool StripParens=true) const
Definition CFG.h:1100
const_succ_iterator succ_end() const
Definition CFG.h:993
const Expr * getLastCondition() const
const_pred_reverse_iterator pred_rend() const
Definition CFG.h:980
void appendConstructor(CXXConstructExpr *CE, const ConstructionContext *CC, BumpVectorContext &C)
Definition CFG.h:1136
AdjacentBlocks::reverse_iterator succ_reverse_iterator
Definition CFG.h:967
Stmt * getTerminatorCondition(bool StripParens=true)
AdjacentBlocks::const_reverse_iterator const_pred_reverse_iterator
Definition CFG.h:961
void addSuccessor(AdjacentBlock Succ, BumpVectorContext &C)
Adds a (potentially unreachable) successor block to the current block.
void appendLoopExit(const Stmt *LoopStmt, BumpVectorContext &C)
Definition CFG.h:1190
AdjacentBlocks::const_iterator const_succ_iterator
Definition CFG.h:966
reverse_ref_iterator_range rrefs()
Definition CFG.h:947
bool pred_empty() const
Definition CFG.h:1012
CFGTerminator Terminator
The terminator for a basic block that indicates the type of control-flow that occurs between a block ...
Definition CFG.h:809
llvm::iterator_range< succ_iterator > succ_range
Definition CFG.h:969
unsigned succ_size() const
Definition CFG.h:1008
bool succ_empty() const
Definition CFG.h:1009
const_reverse_ref_iterator rref_begin() const
Definition CFG.h:942
llvm::iterator_range< const_pred_iterator > pred_const_range
Definition CFG.h:963
Represents a function call that returns a C++ object by value.
Definition CFG.h:186
const ConstructionContext * getConstructionContext() const
Definition CFG.h:212
CFGCXXRecordTypedCall(const Expr *E, const ConstructionContext *C)
Definition CFG.h:199
friend class CFGElement
Definition CFG.h:217
static bool isCXXRecordTypedCall(const Expr *E)
Returns true when call expression CE needs to be represented by CFGCXXRecordTypedCall,...
Definition CFG.h:190
CFGCallback defines methods that should be called when a logical operator error is found when buildin...
Definition CFG.h:1203
virtual void compareBitwiseEquality(const BinaryOperator *B, bool isAlwaysTrue)
Definition CFG.h:1210
virtual void logicAlwaysTrue(const BinaryOperator *B, bool isAlwaysTrue)
Definition CFG.h:1208
virtual void compareAlwaysTrue(const BinaryOperator *B, bool isAlwaysTrue)
Definition CFG.h:1209
virtual void compareBitwiseOr(const BinaryOperator *B)
Definition CFG.h:1212
virtual ~CFGCallback()=default
CFGCleanupFunction(const VarDecl *VD)
Definition CFG.h:392
const VarDecl * getVarDecl() const
Definition CFG.h:397
const FunctionDecl * getFunctionDecl() const
Returns the function to be called when cleaning up the var decl.
Definition CFG.h:402
friend class CFGElement
Definition CFG.h:408
CFGCleanupFunction()=default
Represents C++ constructor call.
Definition CFG.h:157
const ConstructionContext * getConstructionContext() const
Definition CFG.h:166
friend class CFGElement
Definition CFG.h:171
CFGConstructor(const CXXConstructExpr *CE, const ConstructionContext *C)
Definition CFG.h:159
Represents C++ object destructor generated from a call to delete.
Definition CFG.h:443
CFGDeleteDtor(const CXXRecordDecl *RD, const CXXDeleteExpr *DE)
Definition CFG.h:445
friend class CFGElement
Definition CFG.h:458
const CXXDeleteExpr * getDeleteExpr() const
Definition CFG.h:453
const CXXRecordDecl * getCXXRecordDecl() const
Definition CFG.h:448
Represents a top-level expression in a basic block.
Definition CFG.h:55
@ Initializer
Definition CFG.h:59
@ BaseDtor
Definition CFG.h:74
@ CleanupFunction
Definition CFG.h:79
@ ScopeEnd
Definition CFG.h:61
@ STMT_END
Definition CFG.h:70
@ LifetimeEnds
Definition CFG.h:63
@ LoopExit
Definition CFG.h:64
@ Statement
Definition CFG.h:66
@ Constructor
Definition CFG.h:67
@ CXXRecordTypedCall
Definition CFG.h:68
@ MemberDtor
Definition CFG.h:75
@ AutomaticObjectDtor
Definition CFG.h:72
@ STMT_BEGIN
Definition CFG.h:69
@ DTOR_END
Definition CFG.h:78
@ TemporaryDtor
Definition CFG.h:76
@ NewAllocator
Definition CFG.h:62
@ DTOR_BEGIN
Definition CFG.h:77
@ ScopeBegin
Definition CFG.h:60
@ DeleteDtor
Definition CFG.h:73
T castAs() const
Convert to the specified CFGElement type, asserting that this CFGElement is of the desired type.
Definition CFG.h:99
void dumpToStream(llvm::raw_ostream &OS, bool TerminateWithNewLine=true) const
Kind getKind() const
Definition CFG.h:118
void dump() const
Definition CFG.h:128
llvm::PointerIntPair< void *, 2 > Data1
Definition CFG.h:84
llvm::PointerIntPair< void *, 2 > Data2
Definition CFG.h:85
std::optional< T > getAs() const
Convert to the specified CFGElement type, returning std::nullopt if this CFGElement is not of the des...
Definition CFG.h:109
CFGElement(Kind kind, const void *Ptr1, const void *Ptr2=nullptr)
Definition CFG.h:87
const CXXDestructorDecl * getDestructorDecl(ASTContext &astContext) const
CFGImplicitDtor(Kind kind, const void *data1, const void *data2=nullptr)
Definition CFG.h:371
CFGImplicitDtor()=default
friend class CFGElement
Definition CFG.h:381
bool isNoReturn(ASTContext &astContext) const
Represents C++ base or member initializer from constructor's initialization list.
Definition CFG.h:228
CXXCtorInitializer * getInitializer() const
Definition CFG.h:233
CFGInitializer(const CXXCtorInitializer *initializer)
Definition CFG.h:230
friend class CFGElement
Definition CFG.h:238
Represents the point where the lifetime of an automatic object ends.
Definition CFG.h:293
friend class CFGElement
Definition CFG.h:307
CFGLifetimeEnds(const VarDecl *var, const Stmt *stmt)
Definition CFG.h:295
const Stmt * getTriggerStmt() const
Definition CFG.h:302
const VarDecl * getVarDecl() const
Definition CFG.h:298
Represents the point where a loop ends.
Definition CFG.h:274
const Stmt * getLoopStmt() const
Definition CFG.h:278
friend class CFGElement
Definition CFG.h:283
CFGLoopExit(const Stmt *stmt)
Definition CFG.h:276
Represents C++ object destructor implicitly generated for member object in destructor.
Definition CFG.h:490
friend class CFGElement
Definition CFG.h:500
const FieldDecl * getFieldDecl() const
Definition CFG.h:495
CFGMemberDtor(const FieldDecl *field)
Definition CFG.h:492
Represents C++ allocator call.
Definition CFG.h:248
const CXXNewExpr * getAllocatorExpr() const
Definition CFG.h:254
friend class CFGElement
Definition CFG.h:259
CFGNewAllocator(const CXXNewExpr *S)
Definition CFG.h:250
Represents beginning of a scope implicitly generated by the compiler on encountering a CompoundStmt.
Definition CFG.h:318
friend class CFGElement
Definition CFG.h:335
const VarDecl * getVarDecl() const
Definition CFG.h:330
const Stmt * getTriggerStmt() const
Definition CFG.h:325
CFGScopeBegin()
Definition CFG.h:320
CFGScopeBegin(const VarDecl *VD, const Stmt *S)
Definition CFG.h:321
Represents end of a scope implicitly generated by the compiler after the last Stmt in a CompoundStmt'...
Definition CFG.h:344
CFGScopeEnd()
Definition CFG.h:346
CFGScopeEnd(const VarDecl *VD, const Stmt *S)
Definition CFG.h:347
friend class CFGElement
Definition CFG.h:358
const Stmt * getTriggerStmt() const
Definition CFG.h:353
const VarDecl * getVarDecl() const
Definition CFG.h:349
CFGStmt(const Stmt *S, Kind K=Statement)
Definition CFG.h:135
friend class CFGElement
Definition CFG.h:144
const Stmt * getStmt() const
Definition CFG.h:139
Represents C++ object destructor implicitly generated at the end of full expression for temporary obj...
Definition CFG.h:511
const CXXBindTemporaryExpr * getBindTemporaryExpr() const
Definition CFG.h:516
CFGTemporaryDtor(const CXXBindTemporaryExpr *expr)
Definition CFG.h:513
friend class CFGElement
Definition CFG.h:521
Represents CFGBlock terminator statement.
Definition CFG.h:532
Stmt * getStmt()
Definition CFG.h:564
bool isVirtualBaseBranch() const
Definition CFG.h:574
bool isTemporaryDtorsBranch() const
Definition CFG.h:571
CFGTerminator()
Definition CFG.h:560
bool isValid() const
Definition CFG.h:563
bool isStmtBranch() const
Definition CFG.h:568
Kind getKind() const
Definition CFG.h:566
CFGTerminator(Stmt *S, Kind K=StmtBranch)
Definition CFG.h:561
const Stmt * getStmt() const
Definition CFG.h:565
@ TemporaryDtorsBranch
A branch in control flow of destructors of temporaries.
Definition CFG.h:541
@ VirtualBaseBranch
A shortcut around virtual base initializers.
Definition CFG.h:545
@ StmtBranch
A branch that corresponds to a statement in the code, such as an if-statement.
Definition CFG.h:537
@ NumKindsMinusOne
Number of different kinds, for assertions.
Definition CFG.h:550
bool AddLoopExit
Definition CFG.h:1243
bool PruneTriviallyFalseEdges
Definition CFG.h:1238
bool AddLifetime
Definition CFG.h:1242
bool AddStaticInitBranches
Definition CFG.h:1246
bool OmitImplicitValueInitializers
Definition CFG.h:1253
ForcedBlkExprs ** forcedBlkExprs
Definition CFG.h:1236
bool AddTemporaryDtors
Definition CFG.h:1244
bool AddCXXDefaultInitExprInAggregates
Definition CFG.h:1249
bool AddCXXDefaultInitExprInCtors
Definition CFG.h:1248
bool AddImplicitDtors
Definition CFG.h:1241
bool AddCXXNewAllocator
Definition CFG.h:1247
BuildOptions & setAllAlwaysAdd()
Definition CFG.h:1267
BuildOptions & setAlwaysAdd(Stmt::StmtClass stmtClass, bool val=true)
Definition CFG.h:1262
bool AddEHEdges
Definition CFG.h:1239
bool AddInitializers
Definition CFG.h:1240
bool AssumeReachableDefaultInSwitchStatements
Definition CFG.h:1254
CFGCallback * Observer
Definition CFG.h:1237
bool alwaysAdd(const Stmt *stmt) const
Definition CFG.h:1258
bool AddRichCXXConstructors
Definition CFG.h:1250
bool AddVirtualBaseBranches
Definition CFG.h:1252
llvm::DenseMap< const Stmt *, const CFGBlock * > ForcedBlkExprs
Definition CFG.h:1234
bool AddScopes
Definition CFG.h:1245
bool MarkElidedCXXConstructors
Definition CFG.h:1251
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition CFG.h:1222
unsigned size() const
Return the total number of CFGBlocks within the CFG This is simply a renaming of the getNumBlockIDs()...
Definition CFG.h:1415
llvm::iterator_range< synthetic_stmt_iterator > synthetic_stmt_range
Definition CFG.h:1372
CFGBlockListTy::const_iterator const_iterator
Definition CFG.h:1296
const_iterator nodes_end() const
Definition CFG.h:1317
void print(raw_ostream &OS, const LangOptions &LO, bool ShowColors) const
print - A simple pretty printer of a CFG that outputs to an ostream.
std::reverse_iterator< const_iterator > const_reverse_iterator
Definition CFG.h:1298
try_block_range try_blocks() const
Definition CFG.h:1350
iterator end()
Definition CFG.h:1304
bool isLinear() const
Returns true if the CFG has no branches.
synthetic_stmt_range synthetic_stmts() const
Definition CFG.h:1389
void VisitBlockStmts(Callback &O) const
Definition CFG.h:1397
static std::unique_ptr< CFG > buildCFG(const Decl *D, Stmt *AST, ASTContext *C, const BuildOptions &BO)
Builds a CFG from an AST.
llvm::BumpPtrAllocator & getAllocator()
Definition CFG.h:1437
std::reverse_iterator< iterator > reverse_iterator
Definition CFG.h:1297
CFGBlockListTy::iterator iterator
Definition CFG.h:1295
const_reverse_iterator rbegin() const
Definition CFG.h:1321
const_iterator end() const
Definition CFG.h:1306
CFGBlock * createBlock()
Create a new block in the CFG.
void addSyntheticDeclStmt(const DeclStmt *Synthetic, const DeclStmt *Source)
Records a synthetic DeclStmt and the DeclStmt it was constructed from.
Definition CFG.h:1362
const CFGBlock * getIndirectGotoBlock() const
Definition CFG.h:1337
llvm::iterator_range< try_block_iterator > try_block_range
Definition CFG.h:1340
const_iterator begin() const
Definition CFG.h:1305
CFGBlock & getExit()
Definition CFG.h:1333
iterator begin()
Definition CFG.h:1303
void setIndirectGotoBlock(CFGBlock *B)
Set the block used for indirect goto jumps.
Definition CFG.h:1288
void addTryDispatchBlock(const CFGBlock *block)
Definition CFG.h:1354
try_block_iterator try_blocks_end() const
Definition CFG.h:1346
synthetic_stmt_iterator synthetic_stmt_end() const
Definition CFG.h:1384
void setEntry(CFGBlock *B)
Set the entry block of the CFG.
Definition CFG.h:1284
CFGBlock & getEntry()
Definition CFG.h:1331
llvm::iterator_range< const_iterator > const_nodes() const
Definition CFG.h:1312
const CFGBlock & getEntry() const
Definition CFG.h:1332
CFGBlock * getIndirectGotoBlock()
Definition CFG.h:1336
llvm::iterator_range< reverse_iterator > reverse_nodes()
Definition CFG.h:1324
std::vector< const CFGBlock * >::const_iterator try_block_iterator
Definition CFG.h:1339
CFGBlock & front()
Definition CFG.h:1300
const CFGBlock & getExit() const
Definition CFG.h:1334
llvm::iterator_range< const_reverse_iterator > const_reverse_nodes() const
Definition CFG.h:1327
const_reverse_iterator rend() const
Definition CFG.h:1322
void dump(const LangOptions &LO, bool ShowColors) const
dump - A simple pretty printer of a CFG that outputs to stderr.
iterator nodes_begin()
Definition CFG.h:1308
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
Definition CFG.h:1410
const_iterator nodes_begin() const
Definition CFG.h:1316
void viewCFG(const LangOptions &LO) const
try_block_iterator try_blocks_begin() const
Definition CFG.h:1342
CFG()
Definition CFG.h:1435
BumpVector< CFGBlock * > CFGBlockListTy
Definition CFG.h:1294
iterator nodes_end()
Definition CFG.h:1309
synthetic_stmt_iterator synthetic_stmt_begin() const
Iterates over synthetic DeclStmts in the CFG.
Definition CFG.h:1379
reverse_iterator rbegin()
Definition CFG.h:1319
reverse_iterator rend()
Definition CFG.h:1320
CFGBlock & back()
Definition CFG.h:1301
llvm::iterator_range< iterator > nodes()
Definition CFG.h:1311
llvm::DenseMap< const DeclStmt *, const DeclStmt * >::const_iterator synthetic_stmt_iterator
Definition CFG.h:1370
BumpVectorContext & getBumpVectorContext()
Definition CFG.h:1441
Represents a base class of a C++ class.
Represents binding an expression to a temporary.
Represents a call to a C++ constructor.
Represents a C++ base or member initializer.
Represents a delete expression for memory deallocation and destructor calls, e.g.
Represents a C++ destructor within a class.
Represents a new-expression for memory allocation and constructor calls, e.g: "new CXXNewExpr(foo)".
Represents a C++ struct/union/class.
ConstructionContext's subclasses describe different ways of constructing an object in C++.
DeclStmt - Adaptor class for mixing declarations with statements and expressions.
bool isSingleDecl() const
isSingleDecl - This method returns true if this DeclStmt refers to a single Decl.
Decl - This represents one declaration (or definition), e.g.
This represents one expression.
Represents a member of a struct/union/class.
Represents a function declaration or definition.
Keeps track of the various options that can be enabled, which controls the dialect of C or C++ that i...
QualType getCanonicalType() const
Stmt - This represents one statement.
CXXRecordDecl * getAsCXXRecordDecl() const
Retrieves the CXXRecordDecl that this type refers to, either because the type is a RecordType or beca...
Represents a variable declaration or definition.
const internal::VariadicAllOfMatcher< Stmt > stmt
Matches statements.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
The JSON file list parser is used to communicate input to InstallAPI.
bool isa(CodeGen::Address addr)
CFGBlock::ConstCFGElementRef ConstCFGElementRef
Definition CFG.h:1199
bool operator==(const CallGraphNode::CallRecord &LHS, const CallGraphNode::CallRecord &RHS)
nullptr
This class represents a compute construct, representing a 'Kind' of ‘parallel’, 'serial',...
bool operator<(DeclarationName LHS, DeclarationName RHS)
Ordering on two declaration names.
const FunctionProtoType * T
bool operator!=(CanQual< T > x, CanQual< U > y)
Expr * extractElementInitializerFromNestedAILE(const ArrayInitLoopExpr *AILE)
@ Other
Other implicit parameter.
Diagnostic wrappers for TextAPI types for error reporting.
::clang::CFGBlock * NodeRef
Definition CFG.h:1508
static ChildIteratorType child_end(NodeRef N)
Definition CFG.h:1516
static NodeRef getEntryNode(Inverse<::clang::CFGBlock * > G)
Definition CFG.h:1511
::clang::CFGBlock::const_pred_iterator ChildIteratorType
Definition CFG.h:1509
static ChildIteratorType child_begin(NodeRef N)
Definition CFG.h:1515
static nodes_iterator nodes_end(::clang::CFG *F)
Definition CFG.h:1568
::clang::CFG::iterator nodes_iterator
Definition CFG.h:1564
static NodeRef getEntryNode(::clang::CFG *F)
Definition CFG.h:1566
static nodes_iterator nodes_begin(::clang::CFG *F)
Definition CFG.h:1567
static NodeRef getEntryNode(Inverse< const ::clang::CFGBlock * > G)
Definition CFG.h:1523
const ::clang::CFGBlock * NodeRef
Definition CFG.h:1520
static ChildIteratorType child_begin(NodeRef N)
Definition CFG.h:1527
::clang::CFGBlock::const_pred_iterator ChildIteratorType
Definition CFG.h:1521
static ChildIteratorType child_end(NodeRef N)
Definition CFG.h:1528
static NodeRef getEntryNode(const ::clang::CFG *F)
Definition CFG.h:1575
static nodes_iterator nodes_begin(const ::clang::CFG *F)
Definition CFG.h:1577
static nodes_iterator nodes_end(const ::clang::CFG *F)
Definition CFG.h:1581
::clang::CFG::const_iterator nodes_iterator
Definition CFG.h:1573
::clang::CFGBlock * NodeRef
Definition CFG.h:1490
static ChildIteratorType child_begin(NodeRef N)
Definition CFG.h:1494
static ChildIteratorType child_end(NodeRef N)
Definition CFG.h:1495
static NodeRef getEntryNode(::clang::CFGBlock *BB)
Definition CFG.h:1493
::clang::CFGBlock::succ_iterator ChildIteratorType
Definition CFG.h:1491
static nodes_iterator nodes_end(::clang::CFG *F)
Definition CFG.h:1539
static NodeRef getEntryNode(::clang::CFG *F)
Definition CFG.h:1537
static unsigned size(::clang::CFG *F)
Definition CFG.h:1540
static nodes_iterator nodes_begin(::clang::CFG *F)
Definition CFG.h:1538
::clang::CFG::iterator nodes_iterator
Definition CFG.h:1535
::clang::CFGBlock::const_succ_iterator ChildIteratorType
Definition CFG.h:1500
static NodeRef getEntryNode(const clang::CFGBlock *BB)
Definition CFG.h:1502
const ::clang::CFGBlock * NodeRef
Definition CFG.h:1499
static ChildIteratorType child_begin(NodeRef N)
Definition CFG.h:1503
static ChildIteratorType child_end(NodeRef N)
Definition CFG.h:1504
::clang::CFG::const_iterator nodes_iterator
Definition CFG.h:1545
static nodes_iterator nodes_begin(const ::clang::CFG *F)
Definition CFG.h:1549
static unsigned size(const ::clang::CFG *F)
Definition CFG.h:1557
static nodes_iterator nodes_end(const ::clang::CFG *F)
Definition CFG.h:1553
static NodeRef getEntryNode(const ::clang::CFG *F)
Definition CFG.h:1547
static SimpleType getSimplifiedValue(::clang::CFGTerminator Val)
Definition CFG.h:1482
::clang::Stmt * SimpleType
Definition CFG.h:1480