================ @@ -0,0 +1,728 @@ +#include "clang/Analysis/Analyses/LifetimeSafety.h" +#include "clang/AST/Decl.h" +#include "clang/AST/Expr.h" +#include "clang/AST/StmtVisitor.h" +#include "clang/AST/Type.h" +#include "clang/Analysis/AnalysisDeclContext.h" +#include "clang/Analysis/CFG.h" +#include "clang/Analysis/FlowSensitive/DataflowWorklist.h" +#include "llvm/ADT/ImmutableMap.h" +#include "llvm/ADT/ImmutableSet.h" +#include "llvm/ADT/PointerUnion.h" +#include "llvm/ADT/SmallVector.h" +#include "llvm/Support/Debug.h" +#include "llvm/Support/TimeProfiler.h" +#include <vector> + +namespace clang { +namespace { + +struct Point { + const clang::CFGBlock *Block; + /// Index into Block->Elements(). + unsigned ElementIndex; + + Point(const clang::CFGBlock *B = nullptr, unsigned Idx = 0) + : Block(B), ElementIndex(Idx) {} + + bool operator==(const Point &Other) const { + return Block == Other.Block && ElementIndex == Other.ElementIndex; + } +}; + +/// Represents the storage location being borrowed, e.g., a specific stack +/// variable. +/// TODO: Handle member accesseslike `s.y`. +struct Path { + const clang::ValueDecl *D; + + enum class Kind : uint8_t { ---------------- usx95 wrote:
> Do we plan to have Unknown kinds? Yes. I have a `TODO` to represent `Opaque` loans in `LoanInfo` where the `AccessPath` is not known. > But I am wondering what is this information used for? The Path is primarily used to generate 2 facts: IssueLoan and Expireloan. When we see a destructor/lifetime end, we find the loans with paths which just got destroyed. These loans should not expire. Each of the entities like stack variable, temporaries, fields (of stack variables) would need to be handled slightly differently and this is only where this PathKind would be used. > Also, sometimes we might learn more about a location during analysis. E.g., > in a branch if (p == q), the two pointers must have the same Kind. Or if we > see delete p; we learned that p must be a heap location. I do not have plans to modify the loans and facts based on the control flow or the path. I would prefer to not consider path-sensitive information to keep the analysis simple. Once the facts are generated, the dataflow would not generate new facts. https://github.com/llvm/llvm-project/pull/142313 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits