clang 24.0.0git
Facts.h
Go to the documentation of this file.
1//===- Facts.h - Lifetime Analysis Facts and Fact Manager ------*- C++ -*-===//
2//
3// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4// See https://llvm.org/LICENSE.txt for license information.
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6//
7//===----------------------------------------------------------------------===//
8//
9// This file defines Facts, which are atomic lifetime-relevant events (such as
10// loan issuance, loan expiration, origin flow, and use), and the FactManager,
11// which manages the storage and retrieval of facts for each CFG block.
12//
13//===----------------------------------------------------------------------===//
14#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_FACTS_H
15#define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_FACTS_H
16
17#include "clang/AST/Decl.h"
22#include "clang/Analysis/CFG.h"
23#include "llvm/ADT/BitVector.h"
24#include "llvm/ADT/DenseSet.h"
25#include "llvm/ADT/PointerUnion.h"
26#include "llvm/ADT/STLFunctionalExtras.h"
27#include "llvm/ADT/SmallVector.h"
28#include "llvm/Support/Debug.h"
29#include "llvm/Support/raw_ostream.h"
30#include <cstdint>
31#include <optional>
32#include <type_traits>
33
34namespace clang::lifetimes {
35
36/// How an origin is used: by an expression, or implicitly at scope exit by a
37/// destructor or a cleanup callback that may read the borrows it holds.
39
40/// Where and how an origin is used, for diagnostics.
41class UseSite {
42 /// The use expression for an explicit use, or the variable destroyed or
43 /// cleaned up for an implicit one. Null for an explicit use known only by
44 /// its location.
45 llvm::PointerUnion<const Expr *, const VarDecl *> ExprOrVD;
46 /// Used when there is no expression.
49
50 UseSite(llvm::PointerUnion<const Expr *, const VarDecl *> ExprOrVD,
51 SourceLocation Loc, UseKind Kind)
52 : ExprOrVD(ExprOrVD), Loc(Loc), Kind(Kind) {}
53
54public:
55 static UseSite fromExpr(const Expr &E) {
56 return UseSite(&E, SourceLocation(), UseKind::Explicit);
57 }
58 static UseSite at(SourceLocation Loc) {
59 return UseSite(nullptr, Loc, UseKind::Explicit);
60 }
61 static UseSite scopeExit(SourceLocation Loc, const VarDecl &VD,
62 UseKind Kind) {
63 assert((Kind == UseKind::Destructor || Kind == UseKind::Cleanup) &&
64 "scope-exit uses are destructor or cleanup uses");
65 return UseSite(&VD, Loc, Kind);
66 }
67
68 UseKind getKind() const { return Kind; }
69 /// Null for an implicit use or one known only by its location.
70 const Expr *getExpr() const {
71 return dyn_cast_if_present<const Expr *>(ExprOrVD);
72 }
73 /// The variable destroyed or cleaned up, for implicit uses.
74 const VarDecl *getScopeExitVD() const {
75 return dyn_cast_if_present<const VarDecl *>(ExprOrVD);
76 }
78 if (const Expr *E = getExpr())
79 return E->getExprLoc();
80 return Loc;
81 }
82 /// Empty unless there is a use expression.
84 if (const Expr *E = getExpr())
85 return E->getSourceRange();
86 return SourceRange();
87 }
88};
89
90} // namespace clang::lifetimes
91
93
94class FactsGenerator;
95class LoanPropagationAnalysis;
96
98
99/// An abstract base class for a single, atomic lifetime-relevant event.
100class Fact {
101
102public:
103 enum class Kind : uint8_t {
104 /// A new loan is issued from a borrow expression (e.g., &x).
106 /// A loan expires as its underlying storage is freed (e.g., variable goes
107 /// out of scope).
109 /// An origin is propagated from a source to a destination (e.g., p = q).
110 /// This can also optionally kill the destination origin before flowing into
111 /// it. Otherwise, the source's loan set is merged into the destination's
112 /// loan set.
114 /// An origin is used (eg. appears as l-value expression like DeclRefExpr).
116 /// An origin that is moved (e.g., passed to an rvalue reference parameter).
118 /// A marker for a specific point in the code, for testing.
120 /// An origin that escapes the function scope (e.g., via return).
122 /// An origin is invalidated (e.g. vector resized, `delete` called).
124 /// All loans of an origin are cleared.
126 };
127
128private:
129 Kind K;
130 FactID ID;
131
132protected:
133 Fact(Kind K) : K(K) {}
134
135public:
136 virtual ~Fact() = default;
137 Kind getKind() const { return K; }
138
139 void setID(FactID ID) { this->ID = ID; }
140 FactID getID() const { return ID; }
141
142 template <typename T> const T *getAs() const {
143 if (T::classof(this))
144 return static_cast<const T *>(this);
145 return nullptr;
146 }
147
148 virtual void dump(llvm::raw_ostream &OS, const LoanManager &,
149 const OriginManager &,
150 const LoanPropagationAnalysis *LPA = nullptr) const;
151};
152
153/// A `ProgramPoint` identifies a location in the CFG by pointing to a specific
154/// `Fact`. identified by a lifetime-related event (`Fact`).
155///
156/// A `ProgramPoint` has "after" semantics: it represents the location
157/// immediately after its corresponding `Fact`.
158using ProgramPoint = const Fact *;
159
160class IssueFact : public Fact {
161 LoanID LID;
162 OriginID OID;
163
164public:
165 static bool classof(const Fact *F) { return F->getKind() == Kind::Issue; }
166
167 IssueFact(LoanID LID, OriginID OID) : Fact(Kind::Issue), LID(LID), OID(OID) {}
168 LoanID getLoanID() const { return LID; }
169 OriginID getOriginID() const { return OID; }
170 void dump(llvm::raw_ostream &OS, const LoanManager &LM,
171 const OriginManager &OM,
172 const LoanPropagationAnalysis *LPA = nullptr) const override;
173};
174
175/// When an AccessPath expires (e.g., a variable goes out of scope), all loans
176/// that are associated with this path expire. For example, if `x` expires, then
177/// the loan to `x` expires.
178class ExpireFact : public Fact {
179 // The access path that expires.
180 AccessPath AP;
181
182 // Expired origin (e.g., its variable goes out of scope).
183 std::optional<OriginID> OID;
184 SourceLocation ExpiryLoc;
185
186public:
187 static bool classof(const Fact *F) { return F->getKind() == Kind::Expire; }
188
190 std::optional<OriginID> OID = std::nullopt)
191 : Fact(Kind::Expire), AP(AP), OID(OID), ExpiryLoc(ExpiryLoc) {}
192
193 const AccessPath &getAccessPath() const { return AP; }
194 std::optional<OriginID> getOriginID() const { return OID; }
195 SourceLocation getExpiryLoc() const { return ExpiryLoc; }
196
197 void dump(llvm::raw_ostream &OS, const LoanManager &LM,
198 const OriginManager &OM,
199 const LoanPropagationAnalysis *LPA = nullptr) const override;
200};
201
202class OriginFlowFact : public Fact {
203 OriginID OIDDest;
204 OriginID OIDSrc;
205 // True if the destination origin should be killed (i.e., its current loans
206 // cleared) before the source origin's loans are flowed into it.
207 bool KillDest;
208
209public:
210 static bool classof(const Fact *F) {
211 return F->getKind() == Kind::OriginFlow;
212 }
213
214 OriginFlowFact(OriginID OIDDest, OriginID OIDSrc, bool KillDest)
215 : Fact(Kind::OriginFlow), OIDDest(OIDDest), OIDSrc(OIDSrc),
216 KillDest(KillDest) {}
217
218 OriginID getDestOriginID() const { return OIDDest; }
219 OriginID getSrcOriginID() const { return OIDSrc; }
220 bool getKillDest() const { return KillDest; }
221
222 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM,
223 const LoanPropagationAnalysis *LPA = nullptr) const override;
224};
225
226/// Represents that an origin escapes the current scope through various means.
227/// This is the base class for different escape scenarios.
228class OriginEscapesFact : public Fact {
229 OriginID OID;
230
231public:
232 /// The way an origin can escape the current scope.
233 enum class EscapeKind : uint8_t {
234 Return, /// Escapes via return statement.
235 Field, /// Escapes via assignment to a field.
236 Global, /// Escapes via assignment to global storage.
237 This, /// Escapes via the enclosing object `this`, which outlives the
238 /// method.
239 Param, /// Escapes via storage reachable through a reference parameter.
241
242 static bool classof(const Fact *F) {
243 return F->getKind() == Kind::OriginEscapes;
244 }
245
248 OriginID getEscapedOriginID() const { return OID; }
249 EscapeKind getEscapeKind() const { return EscKind; }
250};
251
252/// Represents that an origin escapes via a return statement.
254 const Expr *ReturnExpr;
255
256public:
257 ReturnEscapeFact(OriginID OID, const Expr *ReturnExpr)
258 : OriginEscapesFact(OID, EscapeKind::Return), ReturnExpr(ReturnExpr) {}
259
260 static bool classof(const Fact *F) {
261 return F->getKind() == Kind::OriginEscapes &&
262 static_cast<const OriginEscapesFact *>(F)->getEscapeKind() ==
264 }
265 const Expr *getReturnExpr() const { return ReturnExpr; };
266 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM,
267 const LoanPropagationAnalysis *LPA = nullptr) const override;
268};
269
270/// Represents that an origin escapes via assignment to a field.
271/// Example: `this->view = local_var;` where local_var outlives the assignment
272/// but not the object containing the field.
274 const FieldDecl *FDecl;
275
276public:
278 : OriginEscapesFact(OID, EscapeKind::Field), FDecl(FDecl) {}
279
280 static bool classof(const Fact *F) {
281 return F->getKind() == Kind::OriginEscapes &&
282 static_cast<const OriginEscapesFact *>(F)->getEscapeKind() ==
284 }
285 const FieldDecl *getFieldDecl() const { return FDecl; };
286 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM,
287 const LoanPropagationAnalysis *LPA = nullptr) const override;
288};
289
290/// Represents that an origin escapes via assignment to global or static
291/// storage. Example: `global_storage = local_var;`
293 const VarDecl *Global;
294
295public:
297 : OriginEscapesFact(OID, EscapeKind::Global), Global(VDecl) {}
298
299 static bool classof(const Fact *F) {
300 return F->getKind() == Kind::OriginEscapes &&
301 static_cast<const OriginEscapesFact *>(F)->getEscapeKind() ==
303 }
304 const VarDecl *getGlobal() const { return Global; };
305 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM,
306 const LoanPropagationAnalysis *LPA = nullptr) const override;
307};
308
309/// Represents an origin escaping through the enclosing object `this`, which
310/// outlives the current method. Emitted for `this` at function exit so a borrow
311/// still held by the object there is seen as escaping -- e.g. a borrow captured
312/// via [[clang::lifetime_capture_by_this]] that outlived the captured local is
313/// reported as a use-after-scope.
315 SourceLocation Loc;
316
317public:
320
321 static bool classof(const Fact *F) {
322 return F->getKind() == Kind::OriginEscapes &&
323 static_cast<const OriginEscapesFact *>(F)->getEscapeKind() ==
325 }
326 SourceLocation getLoc() const { return Loc; }
327 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM,
328 const LoanPropagationAnalysis *LPA = nullptr) const override;
329};
330
331/// Represents an origin escaping through storage reachable from a reference
332/// parameter, which the caller can observe after the function returns.
333/// Example: `out = local_view;` for a parameter `std::string_view &out`.
334/// Emitted at function exit; only used to verify annotations, so it does not
335/// keep the origin live.
337 const ParmVarDecl *Param;
338
339public:
341 : OriginEscapesFact(OID, EscapeKind::Param), Param(Param) {}
342
343 static bool classof(const Fact *F) {
344 return F->getKind() == Kind::OriginEscapes &&
345 static_cast<const OriginEscapesFact *>(F)->getEscapeKind() ==
347 }
348 const ParmVarDecl *getParam() const { return Param; }
349 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM,
350 const LoanPropagationAnalysis *LPA = nullptr) const override;
351};
352
353class UseFact : public Fact {
354 UseSite Site;
355 const OriginList *OList;
356
357public:
358 static bool classof(const Fact *F) { return F->getKind() == Kind::Use; }
359
360 UseFact(const Expr &UseExpr, const OriginList *OList)
361 : Fact(Kind::Use), Site(UseSite::fromExpr(UseExpr)), OList(OList) {}
362 UseFact(const UseSite &ImplicitSite, const OriginList *OList)
363 : Fact(Kind::Use), Site(ImplicitSite), OList(OList) {
364 assert(Site.getKind() != UseKind::Explicit);
365 }
366
367 const OriginList *getUsedOrigins() const { return OList; }
368 /// Null for an implicit use.
369 const Expr *getUseExpr() const { return Site.getExpr(); }
370 const UseSite &getUseSite() const { return Site; }
371
372 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM,
373 const LoanPropagationAnalysis *LPA = nullptr) const override;
374};
375
376/// Represents that an origin's storage has been invalidated by a container
377/// operation (e.g., vector::push_back may reallocate, invalidating iterators).
378/// Created when a container method that may invalidate references/iterators
379/// is called on the container.
381 OriginID OID;
382 const Expr *InvalidationExpr;
383
384public:
385 static bool classof(const Fact *F) {
386 return F->getKind() == Kind::InvalidateOrigin;
387 }
388
389 InvalidateOriginFact(OriginID OID, const Expr *InvalidationExpr)
390 : Fact(Kind::InvalidateOrigin), OID(OID),
391 InvalidationExpr(InvalidationExpr) {}
392
393 OriginID getInvalidatedOrigin() const { return OID; }
394 const Expr *getInvalidationExpr() const { return InvalidationExpr; }
395 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM,
396 const LoanPropagationAnalysis *LPA = nullptr) const override;
397};
398
399/// Top-level origin of the expression which was found to be moved, e.g, when
400/// being used as an argument to an r-value reference parameter.
401class MovedOriginFact : public Fact {
402 const OriginID MovedOrigin;
403 const Expr *MoveExpr;
404
405public:
406 static bool classof(const Fact *F) {
407 return F->getKind() == Kind::MovedOrigin;
408 }
409
410 MovedOriginFact(const Expr *MoveExpr, OriginID MovedOrigin)
411 : Fact(Kind::MovedOrigin), MovedOrigin(MovedOrigin), MoveExpr(MoveExpr) {}
412
413 OriginID getMovedOrigin() const { return MovedOrigin; }
414 const Expr *getMoveExpr() const { return MoveExpr; }
415
416 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM,
417 const LoanPropagationAnalysis *LPA = nullptr) const override;
418};
419
420/// A dummy-fact used to mark a specific point in the code for testing.
421/// It is generated by recognizing a `void("__lifetime_test_point_...")` cast.
422class TestPointFact : public Fact {
423 StringRef Annotation;
424
425public:
426 static bool classof(const Fact *F) { return F->getKind() == Kind::TestPoint; }
427
428 explicit TestPointFact(StringRef Annotation)
429 : Fact(Kind::TestPoint), Annotation(Annotation) {}
430
431 StringRef getAnnotation() const { return Annotation; }
432
433 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &,
434 const LoanPropagationAnalysis *LPA = nullptr) const override;
435};
436
437/// All loans are cleared from an origin (e.g., assigning a callable without
438/// tracked origins to std::function).
439class KillOriginFact : public Fact {
440 OriginID OID;
441
442public:
443 static bool classof(const Fact *F) {
444 return F->getKind() == Kind::KillOrigin;
445 }
446
448
449 OriginID getKilledOrigin() const { return OID; }
450
451 void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM,
452 const LoanPropagationAnalysis *LPA = nullptr) const override;
453};
454
456public:
457 FactManager(const AnalysisDeclContext &AC, const CFG &Cfg,
458 llvm::BumpPtrAllocator &Alloc)
459 : LoanMgr(Alloc), OriginMgr(AC, Alloc), FactAllocator(Alloc) {
460 BlockToFacts.resize(Cfg.getNumBlockIDs());
461 }
462
464 return BlockToFacts[B->getBlockID()];
465 }
466
468 if (!NewFacts.empty())
469 BlockToFacts[B->getBlockID()].assign(NewFacts.begin(), NewFacts.end());
470 }
471
472 void appendBlockFact(const CFGBlock *B, const Fact *F) {
473 BlockToFacts[B->getBlockID()].push_back(F);
474 }
475
476 template <typename FactType, typename... Args>
477 FactType *createFact(Args &&...args) {
478 FactType *Res = new (FactAllocator) FactType(std::forward<Args>(args)...);
479 Res->setID(NextFactID++);
480 if constexpr (std::is_same_v<FactType, MovedOriginFact>)
481 HasMovedOriginFacts = true;
482 return Res;
483 }
484
485 /// Whether any MovedOriginFact was created.
486 bool hasMovedOriginFacts() const { return HasMovedOriginFacts; }
487
488 void dump(const CFG &Cfg, AnalysisDeclContext &AC,
489 const LoanPropagationAnalysis *LPA = nullptr) const;
490
491 /// Retrieves program points that were specially marked in the source code
492 /// for testing.
493 ///
494 /// The analysis recognizes special function calls of the form
495 /// `void("__lifetime_test_point_<name>")` as test points. This method returns
496 /// a map from the annotation string (<name>) to the corresponding
497 /// `ProgramPoint`. This allows test harnesses to query the analysis state at
498 /// user-defined locations in the code.
499 /// \note This is intended for testing only.
500 llvm::StringMap<ProgramPoint> getTestPoints() const;
501 /// Retrieves all the facts in the block containing Program Point P.
502 /// \note This is intended for testing only.
504 size_t getBlockID(ProgramPoint P) const;
505
506 unsigned getNumFacts() const { return NextFactID.Value; }
507
508 /// Returns the origins that are referenced from more than one basic block.
509 /// Only those need to survive block boundaries in the dataflow analyses; the
510 /// rest are block-local.
511 const llvm::BitVector &getPersistentOrigins() const {
512 assert(PersistentOrigins.size() == OriginMgr.getNumOrigins() &&
513 "persistent origins have not been computed");
514 return PersistentOrigins;
515 }
516
517 LoanManager &getLoanMgr() { return LoanMgr; }
518 const LoanManager &getLoanMgr() const { return LoanMgr; }
519 OriginManager &getOriginMgr() { return OriginMgr; }
520 const OriginManager &getOriginMgr() const { return OriginMgr; }
521
522 void addCapturedField(const FieldDecl *FD) { CapturedFields.insert(FD); }
523 bool isFieldCapturedByLambda(const FieldDecl *FD) const {
524 return IsThisCapturedByLambda || CapturedFields.contains(FD);
525 }
526 void setThisCapturedByLambda() { IsThisCapturedByLambda = true; }
527
528private:
529 /// Classifies every origin as persistent or block-local. Called by
530 /// `FactsGenerator` once all facts and origins have been created.
531 void computePersistentOrigins(const CFG &Cfg);
532
533 friend class FactsGenerator;
534
535 FactID NextFactID{0};
536 bool HasMovedOriginFacts = false;
537 LoanManager LoanMgr;
538 OriginManager OriginMgr;
539 /// Facts for each CFG block, indexed by block ID.
541 llvm::BumpPtrAllocator &FactAllocator;
542 /// Bit vector indexed by origin ID. If set, the origin is referenced from
543 /// more than one basic block and must participate in join operations. If
544 /// unset, the origin is block-local and can be discarded at block
545 /// boundaries.
546 ///
547 /// Shared by every analysis so that they all agree on which origins cross
548 /// block boundaries.
549 llvm::BitVector PersistentOrigins;
550
551 /// Set of field declarations that are explicitly or init-captured in any
552 /// lambda within the analyzed function.
553 llvm::DenseSet<const FieldDecl *> CapturedFields;
554 /// Whether the 'this' pointer is captured by any lambda within the analyzed
555 /// function. When true, any field of 'this' is considered captured.
556 bool IsThisCapturedByLambda = false;
557};
558} // namespace clang::lifetimes::internal
559
560#endif // LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_FACTS_H
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.
Represents a single basic block in a source-level CFG.
Definition CFG.h:651
unsigned getBlockID() const
Definition CFG.h:1177
Represents a source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition CFG.h:1294
unsigned getNumBlockIDs() const
Returns the total number of BlockIDs allocated (which start at 0).
Definition CFG.h:1487
This represents one expression.
Definition Expr.h:114
Represents a member of a struct/union/class.
Definition Decl.h:3341
Represents a parameter to a function.
Definition Decl.h:1832
Encodes a location in the source.
A trivial tuple used to represent a source range.
Represents a variable declaration or definition.
Definition Decl.h:934
Where and how an origin is used, for diagnostics.
Definition Facts.h:41
static UseSite scopeExit(SourceLocation Loc, const VarDecl &VD, UseKind Kind)
Definition Facts.h:61
UseKind getKind() const
Definition Facts.h:68
const Expr * getExpr() const
Null for an implicit use or one known only by its location.
Definition Facts.h:70
SourceRange getRange() const
Empty unless there is a use expression.
Definition Facts.h:83
SourceLocation getLoc() const
Definition Facts.h:77
const VarDecl * getScopeExitVD() const
The variable destroyed or cleaned up, for implicit uses.
Definition Facts.h:74
static UseSite at(SourceLocation Loc)
Definition Facts.h:58
static UseSite fromExpr(const Expr &E)
Definition Facts.h:55
Represents the storage location being borrowed, e.g., a specific stack variable or a field within it:...
Definition Loans.h:128
const AccessPath & getAccessPath() const
Definition Facts.h:193
SourceLocation getExpiryLoc() const
Definition Facts.h:195
static bool classof(const Fact *F)
Definition Facts.h:187
ExpireFact(AccessPath AP, SourceLocation ExpiryLoc, std::optional< OriginID > OID=std::nullopt)
Definition Facts.h:189
std::optional< OriginID > getOriginID() const
Definition Facts.h:194
void dump(llvm::raw_ostream &OS, const LoanManager &LM, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:88
bool hasMovedOriginFacts() const
Whether any MovedOriginFact was created.
Definition Facts.h:486
llvm::ArrayRef< const Fact * > getFacts(const CFGBlock *B) const
Definition Facts.h:463
FactType * createFact(Args &&...args)
Definition Facts.h:477
bool isFieldCapturedByLambda(const FieldDecl *FD) const
Definition Facts.h:523
llvm::StringMap< ProgramPoint > getTestPoints() const
Retrieves program points that were specially marked in the source code for testing.
Definition Facts.cpp:211
FactManager(const AnalysisDeclContext &AC, const CFG &Cfg, llvm::BumpPtrAllocator &Alloc)
Definition Facts.h:457
void dump(const CFG &Cfg, AnalysisDeclContext &AC, const LoanPropagationAnalysis *LPA=nullptr) const
Definition Facts.cpp:226
void addBlockFacts(const CFGBlock *B, llvm::ArrayRef< Fact * > NewFacts)
Definition Facts.h:467
const OriginManager & getOriginMgr() const
Definition Facts.h:520
size_t getBlockID(ProgramPoint P) const
Definition Facts.cpp:250
void appendBlockFact(const CFGBlock *B, const Fact *F)
Definition Facts.h:472
const LoanManager & getLoanMgr() const
Definition Facts.h:518
llvm::ArrayRef< const Fact * > getBlockContaining(ProgramPoint P) const
Retrieves all the facts in the block containing Program Point P.
Definition Facts.cpp:246
const llvm::BitVector & getPersistentOrigins() const
Returns the origins that are referenced from more than one basic block.
Definition Facts.h:511
void addCapturedField(const FieldDecl *FD)
Definition Facts.h:522
An abstract base class for a single, atomic lifetime-relevant event.
Definition Facts.h:100
virtual void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &, const LoanPropagationAnalysis *LPA=nullptr) const
Definition Facts.cpp:73
@ InvalidateOrigin
An origin is invalidated (e.g. vector resized, delete called).
Definition Facts.h:123
@ TestPoint
A marker for a specific point in the code, for testing.
Definition Facts.h:119
@ Expire
A loan expires as its underlying storage is freed (e.g., variable goes out of scope).
Definition Facts.h:108
@ Issue
A new loan is issued from a borrow expression (e.g., &x).
Definition Facts.h:105
@ OriginFlow
An origin is propagated from a source to a destination (e.g., p = q).
Definition Facts.h:113
@ MovedOrigin
An origin that is moved (e.g., passed to an rvalue reference parameter).
Definition Facts.h:117
@ Use
An origin is used (eg. appears as l-value expression like DeclRefExpr).
Definition Facts.h:115
@ OriginEscapes
An origin that escapes the function scope (e.g., via return).
Definition Facts.h:121
@ KillOrigin
All loans of an origin are cleared.
Definition Facts.h:125
const T * getAs() const
Definition Facts.h:142
FieldEscapeFact(OriginID OID, const FieldDecl *FDecl)
Definition Facts.h:277
const FieldDecl * getFieldDecl() const
Definition Facts.h:285
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:142
static bool classof(const Fact *F)
Definition Facts.h:280
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:150
GlobalEscapeFact(OriginID OID, const VarDecl *VDecl)
Definition Facts.h:296
static bool classof(const Fact *F)
Definition Facts.h:299
const VarDecl * getGlobal() const
Definition Facts.h:304
InvalidateOriginFact(OriginID OID, const Expr *InvalidationExpr)
Definition Facts.h:389
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:189
void dump(llvm::raw_ostream &OS, const LoanManager &LM, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:78
IssueFact(LoanID LID, OriginID OID)
Definition Facts.h:167
static bool classof(const Fact *F)
Definition Facts.h:165
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:203
static bool classof(const Fact *F)
Definition Facts.h:443
Manages the creation, storage and retrieval of loans.
Definition Loans.h:234
static bool classof(const Fact *F)
Definition Facts.h:406
MovedOriginFact(const Expr *MoveExpr, OriginID MovedOrigin)
Definition Facts.h:410
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:126
enum clang::lifetimes::internal::OriginEscapesFact::EscapeKind EscKind
EscapeKind
The way an origin can escape the current scope.
Definition Facts.h:233
@ Global
Escapes via assignment to a field.
Definition Facts.h:236
@ This
Escapes via assignment to global storage.
Definition Facts.h:237
@ Param
Escapes via the enclosing object this, which outlives the method.
Definition Facts.h:239
static bool classof(const Fact *F)
Definition Facts.h:242
OriginEscapesFact(OriginID OID, EscapeKind EscKind)
Definition Facts.h:246
static bool classof(const Fact *F)
Definition Facts.h:210
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:100
OriginFlowFact(OriginID OIDDest, OriginID OIDSrc, bool KillDest)
Definition Facts.h:214
A list of origins representing levels of indirection for pointer-like types.
Definition Origins.h:106
Manages the creation, storage, and retrieval of origins for pointer-like variables and expressions.
Definition Origins.h:136
ParamEscapeFact(OriginID OID, const ParmVarDecl *Param)
Definition Facts.h:340
const ParmVarDecl * getParam() const
Definition Facts.h:348
static bool classof(const Fact *F)
Definition Facts.h:343
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:166
static bool classof(const Fact *F)
Definition Facts.h:260
ReturnEscapeFact(OriginID OID, const Expr *ReturnExpr)
Definition Facts.h:257
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:134
static bool classof(const Fact *F)
Definition Facts.h:426
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:197
TestPointFact(StringRef Annotation)
Definition Facts.h:428
ThisEscapeFact(OriginID OID, SourceLocation Loc)
Definition Facts.h:318
static bool classof(const Fact *F)
Definition Facts.h:321
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:158
UseFact(const UseSite &ImplicitSite, const OriginList *OList)
Definition Facts.h:362
const Expr * getUseExpr() const
Null for an implicit use.
Definition Facts.h:369
void dump(llvm::raw_ostream &OS, const LoanManager &, const OriginManager &OM, const LoanPropagationAnalysis *LPA=nullptr) const override
Definition Facts.cpp:174
static bool classof(const Fact *F)
Definition Facts.h:358
UseFact(const Expr &UseExpr, const OriginList *OList)
Definition Facts.h:360
const UseSite & getUseSite() const
Definition Facts.h:370
const OriginList * getUsedOrigins() const
Definition Facts.h:367
const Fact * ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition Facts.h:158
utils::ID< struct LoanTag > LoanID
Definition Loans.h:28
utils::ID< struct OriginTag > OriginID
Definition Origins.h:29
utils::ID< struct FactTag > FactID
Definition Facts.h:97
UseKind
How an origin is used: by an expression, or implicitly at scope exit by a destructor or a cleanup cal...
Definition Facts.h:38
int32_t uint32_t uint32_t __builtin_riscv_mhracc_i32 __builtin_riscv_mhraccu_u32 __builtin_riscv_mhraccsu_i32 __builtin_riscv_mhacc_h1_i32 __builtin_riscv_mhaccsu_h1_i32 __builtin_riscv_mulqr_i32 __builtin_riscv_mqrwacc_i64 __packed_splat4 __packed_splat2 __packed_splat8 __packed_splat4 __packed_splat2 uint8_t
A generic, type-safe wrapper for an ID, distinguished by its Tag type.
Definition Utils.h:21