clang 24.0.0git
LoanPropagation.h
Go to the documentation of this file.
1//===- LoanPropagation.h - Loan Propagation Analysis -----------*- 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 the LoanPropagationAnalysis, a forward dataflow analysis
10// that tracks which loans each origin holds at each program point. Loans
11// represent borrows of storage locations and are propagated through the
12// program as pointers are copied or assigned.
13//
14//===----------------------------------------------------------------------===//
15#ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOAN_PROPAGATION_H
16#define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOAN_PROPAGATION_H
17
21#include "clang/Analysis/CFG.h"
22
24
25// Using LLVM's immutable collections is efficient for dataflow analysis
26// as it avoids deep copies during state transitions.
27// TODO(opt): Consider using a bitset to represent the set of loans.
30
32public:
34 OriginLoanMap::Factory &OriginLoanMapFactory,
35 LoanSet::Factory &LoanSetFactory);
37
39
40 /// Builds the chain of origins through which a loan has propagated.
41 ///
42 /// Starting from the last fact of the block containing StartPoint, this
43 /// function performs a DFS over CFG blocks to explore all reachable blocks.
44 /// Within each block, facts are processed in reverse order.
45 ///
46 /// The traversal follows OriginFlowFacts backwards to reconstruct the
47 /// sequence of origins through which the loan flowed, ending at the origin
48 /// where the loan was originally issued.
50 const OriginID StartOID,
51 const LoanID TargetLoan,
52 const CFG *Cfg) const;
53
55 const LoanID TargetLoan,
56 const CFG *Cfg) const;
57
58private:
59 class Impl;
60 std::unique_ptr<Impl> PImpl;
61};
62
63} // namespace clang::lifetimes::internal
64
65#endif // LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_LOAN_PROPAGATION_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 source-level, intra-procedural CFG that represents the control-flow of a Stmt.
Definition CFG.h:1271
llvm::SmallVector< OriginID > buildOriginFlowChain(ProgramPoint StartPoint, const OriginID StartOID, const LoanID TargetLoan, const CFG *Cfg) const
Builds the chain of origins through which a loan has propagated.
LoanSet getLoans(OriginID OID, ProgramPoint P) const
LoanPropagationAnalysis(const CFG &C, AnalysisDeclContext &AC, FactManager &F, OriginLoanMap::Factory &OriginLoanMapFactory, LoanSet::Factory &LoanSetFactory)
llvm::ImmutableSet< T, llvm::ImutContainerInfo< T >, false > SetTy
The lifetime analyses do not benefit from canonicalizing their immutable collections,...
Definition Utils.h:40
llvm::ImmutableMap< KeyT, ValT, llvm::ImutKeyValueInfo< KeyT, ValT >, false > MapTy
Definition Utils.h:44
const Fact * ProgramPoint
A ProgramPoint identifies a location in the CFG by pointing to a specific Fact.
Definition Facts.h:95
utils::ID< struct LoanTag > LoanID
Definition Loans.h:27
utils::ID< struct OriginTag > OriginID
Definition Origins.h:28
utils::SetTy< LoanID > LoanSet
utils::MapTy< OriginID, LoanSet > OriginLoanMap