clang: lib/Analysis/LifetimeSafety/Origins.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
16
18
22
23
24
25
26
27
28
29
30
31
32
33
34
38
39
40
41
42
43
44
45
46
47
48
49
50
51
55
56OriginList *OriginManager::createNode(const ValueDecl *D, QualType QT) {
57 OriginID NewID = getNextOriginID();
59 return new (ListAllocator.Allocate()) OriginList(NewID);
60}
61
62OriginList *OriginManager::createNode(const Expr *E, QualType QT) {
63 OriginID NewID = getNextOriginID();
65 return new (ListAllocator.Allocate()) OriginList(NewID);
66}
67
68template
69OriginList *OriginManager::buildListForType(QualType QT, const T *Node) {
70 assert(hasOrigins(QT) && "buildListForType called for non-pointer type");
71 OriginList *Head = createNode(Node, QT);
72
73 if (QT->isPointerOrReferenceType()) {
74 QualType PointeeTy = QT->getPointeeType();
75
76
78 Head->setInnerOriginList(buildListForType(PointeeTy, Node));
79 }
80 return Head;
81}
82
85 return nullptr;
86 auto It = DeclToList.find(D);
87 if (It != DeclToList.end())
88 return It->second;
89 return DeclToList[D] = buildListForType(D->getType(), D);
90}
91
93 if (auto *ParenIgnored = E->IgnoreParens(); ParenIgnored != E)
95
97 return nullptr;
98
99 auto It = ExprToList.find(E);
100 if (It != ExprToList.end())
101 return It->second;
102
104
105
106 if (auto *DRE = dyn_cast(E)) {
108
109
110
111
112
114 Head = createNode(DRE, QualType{});
115
116
118 } else {
119
120
121
122
124 }
125 return ExprToList[E] = Head;
126 }
127
128
129
130
132 Type = AST.getLValueReferenceType(Type);
133 return ExprToList[E] = buildListForType(Type, E);
134}
135
137 OS << OID << " (";
140 OS << "Decl: " << VD->getNameAsString();
141 } else if (const Expr *E = O.getExpr()) {
143 if (auto *DRE = dyn_cast(E)) {
144 if (const ValueDecl *VD = DRE->getDecl())
145 OS << ", Decl: " << VD->getNameAsString();
146 }
147 } else {
148 OS << "Unknown";
149 }
150 if (O.Ty)
152 OS << ")";
153}
154
156 assert(ID.Value < AllOrigins.size());
157 return AllOrigins[ID.Value];
158}
159
160}
Defines the clang::ASTContext interface.
Defines the C++ Decl subclasses, other than those for templates (found in DeclTemplate....
Defines the C++ template declaration subclasses.
C Language Family Type Representation.
This represents one expression.
Expr * IgnoreParens() LLVM_READONLY
Skip past any parentheses which might surround this expression until reaching a fixed point.
A (possibly-)qualified type.
const Type * getTypePtrOrNull() const
static std::string getAsString(SplitQualType split, const PrintingPolicy &Policy)
const char * getStmtClassName() const
The base class of the type hierarchy.
bool isReferenceType() const
bool isPointerOrReferenceType() const
Represent the declaration of a variable (in which case it is an lvalue) a function (in which case it ...
A list of origins representing levels of indirection for pointer-like types.
void setInnerOriginList(OriginList *Inner)
OriginList * getOrCreateList(const ValueDecl *D)
Gets or creates the OriginList for a given ValueDecl.
Definition Origins.cpp:83
const Origin & getOrigin(OriginID ID) const
Definition Origins.cpp:155
void dump(OriginID OID, llvm::raw_ostream &OS) const
Definition Origins.cpp:136
utils::ID< struct OriginTag > OriginID
bool doesDeclHaveStorage(const ValueDecl *D)
Returns true if the declaration has its own storage that can be borrowed.
Definition Origins.cpp:52
bool hasOrigins(QualType QT)
Definition Origins.cpp:19
bool isGslPointerType(QualType QT)
An Origin is a symbolic identifier that represents the set of possible loans a pointer-like object co...
const clang::Expr * getExpr() const
const clang::ValueDecl * getDecl() const
const Type * Ty
The type at this indirection level.