[llvm-branch-commits] [clang] Backport "[analyzer] Restore recognition of mutex methods" (PR #101651)

2024-08-02 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.

LGTM, makes sense to backport.

https://github.com/llvm/llvm-project/pull/101651
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] Backport "[analyzer] Fix crash on using `bitcast(, )` as array subscript" (PR #101684)

2024-08-02 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.

LGTM, it makes sense to me to backport this crash fix.

https://github.com/llvm/llvm-project/pull/101684
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][docs] Admit that the cleanup attribute is not supported (PR #81834)

2024-02-15 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/81834
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer] Backport performace regression fix (PR #89725)

2024-04-23 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/89725
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] PR for llvm/llvm-project#79992 (PR #79997)

2024-01-30 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/79997
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] Backport taint analysis slowdown regression fix (PR #105516)

2024-08-27 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.

LGTM! We should avoid performance regressions and for some projects this could 
be a serious one. I agree with backporting the workaround. 

https://github.com/llvm/llvm-project/pull/105516
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] Backport "[clang][analyzer] Fix #embed crash (#107764)" (PR #107841)

2024-09-09 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.

LGTM!

https://github.com/llvm/llvm-project/pull/107841
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][docs] CSA release notes for clang-20 (PR #124798)

2025-01-29 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/124798
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][docs] CSA release notes for clang-20 (PR #124798)

2025-01-29 Thread Gábor Horváth via llvm-branch-commits

Xazax-hun wrote:

I think there might have been some changes to the CFG that could potentially 
effect CSA. But I don't think those are that important to mention here. 

https://github.com/llvm/llvm-project/pull/124798
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][NFC] Migrate nonloc::ConcreteInt to use APSIntPtr (2/4) (PR #120436)

2024-12-18 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/120436
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][NFC] Migrate loc::ConcreteInt to use APSIntPtr (3/4) (PR #120437)

2024-12-18 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/120437
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][NFC] Migrate nonloc::ConcreteInt to use APSIntPtr (2/4) (PR #120436)

2024-12-18 Thread Gábor Horváth via llvm-branch-commits


@@ -298,9 +299,12 @@ class SymbolVal : public NonLoc {
 /// Value representing integer constant.
 class ConcreteInt : public NonLoc {
 public:
-  explicit ConcreteInt(const llvm::APSInt &V) : NonLoc(ConcreteIntKind, &V) {}
+  explicit ConcreteInt(APSIntPtr V) : NonLoc(ConcreteIntKind, V.get()) {}
 
-  const llvm::APSInt &getValue() const { return *castDataAs(); }
+  APSIntPtr getValue() const {
+// This is safe because in the ctor we take a safe APSIntPtr.
+return APSIntPtr::unsafeConstructor(castDataAs());

Xazax-hun wrote:

> Currently the infrastructure is set up for holding raw-pointers.

Could you elaborate on what preventing us from changing this?

https://github.com/llvm/llvm-project/pull/120436
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][NFC] Migrate nonloc::ConcreteInt to use APSIntPtr (2/4) (PR #120436)

2024-12-18 Thread Gábor Horváth via llvm-branch-commits


@@ -298,9 +299,12 @@ class SymbolVal : public NonLoc {
 /// Value representing integer constant.
 class ConcreteInt : public NonLoc {
 public:
-  explicit ConcreteInt(const llvm::APSInt &V) : NonLoc(ConcreteIntKind, &V) {}
+  explicit ConcreteInt(APSIntPtr V) : NonLoc(ConcreteIntKind, V.get()) {}
 
-  const llvm::APSInt &getValue() const { return *castDataAs(); }
+  APSIntPtr getValue() const {
+// This is safe because in the ctor we take a safe APSIntPtr.
+return APSIntPtr::unsafeConstructor(castDataAs());

Xazax-hun wrote:

Ah, never mind. This does not help us because here we would want to cast the 
struct itself. 

https://github.com/llvm/llvm-project/pull/120436
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][NFC] Migrate nonloc::ConcreteInt to use APSIntPtr (2/4) (PR #120436)

2024-12-18 Thread Gábor Horváth via llvm-branch-commits


@@ -298,9 +299,12 @@ class SymbolVal : public NonLoc {
 /// Value representing integer constant.
 class ConcreteInt : public NonLoc {
 public:
-  explicit ConcreteInt(const llvm::APSInt &V) : NonLoc(ConcreteIntKind, &V) {}
+  explicit ConcreteInt(APSIntPtr V) : NonLoc(ConcreteIntKind, V.get()) {}
 
-  const llvm::APSInt &getValue() const { return *castDataAs(); }
+  APSIntPtr getValue() const {
+// This is safe because in the ctor we take a safe APSIntPtr.
+return APSIntPtr::unsafeConstructor(castDataAs());

Xazax-hun wrote:

According to [CppReference](https://en.cppreference.com/w/c/language/struct):
> A pointer to a struct can be cast to a pointer to its first member (or, if 
> the member is a bit-field, to its allocation unit). Likewise, a pointer to 
> the first member of a struct can be cast to a pointer to the enclosing struct.



https://github.com/llvm/llvm-project/pull/120436
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][NFC] Migrate {SymInt, IntSym}Expr to use APSIntPtr (4/4) (PR #120438)

2024-12-18 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/120438
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][NFC] Migrate nonloc::ConcreteInt to use APSIntPtr (2/4) (PR #120436)

2024-12-18 Thread Gábor Horváth via llvm-branch-commits


@@ -298,9 +299,12 @@ class SymbolVal : public NonLoc {
 /// Value representing integer constant.
 class ConcreteInt : public NonLoc {
 public:
-  explicit ConcreteInt(const llvm::APSInt &V) : NonLoc(ConcreteIntKind, &V) {}
+  explicit ConcreteInt(APSIntPtr V) : NonLoc(ConcreteIntKind, V.get()) {}
 
-  const llvm::APSInt &getValue() const { return *castDataAs(); }
+  APSIntPtr getValue() const {
+// This is safe because in the ctor we take a safe APSIntPtr.
+return APSIntPtr::unsafeConstructor(castDataAs());

Xazax-hun wrote:

 Is it possible to store `ApsIntPtr` in `NonLoc`?

https://github.com/llvm/llvm-project/pull/120436
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [analyzer][NFC] Migrate loc::ConcreteInt to use APSIntPtr (3/4) (PR #120437)

2024-12-18 Thread Gábor Horváth via llvm-branch-commits


@@ -514,9 +514,12 @@ class MemRegionVal : public Loc {
 
 class ConcreteInt : public Loc {
 public:
-  explicit ConcreteInt(const llvm::APSInt &V) : Loc(ConcreteIntKind, &V) {}
+  explicit ConcreteInt(APSIntPtr V) : Loc(ConcreteIntKind, V.get()) {}

Xazax-hun wrote:

Is it possible to store `APSIntPtr` in `Loc`?

https://github.com/llvm/llvm-project/pull/120437
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] Backport to 20.x "[clang][analyzer] Fix error path of builtin overflow (#136345)" (PR #136589)

2025-04-23 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/136589
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][analysis] Fix flaky clang/test/Analysis/live-stmts.cpp test (2nd attempt) (#127406) (PR #139591)

2025-05-13 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/139591
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [clang][analyzer] Handle CXXParenInitListExpr alongside InitListExpr (PR #139909)

2025-05-14 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/139909
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Add script for performance benchmarking (PR #147315)

2025-07-09 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.

It is great to have these tools checked in, thanks! 

https://github.com/llvm/llvm-project/pull/147315
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Support bidirectional dataflow analysis (PR #148967)

2025-07-16 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.


https://github.com/llvm/llvm-project/pull/148967
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Add loan expiry analysis (PR #148712)

2025-07-16 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun approved this pull request.

Once the testing story is figured out this looks good to me. 

https://github.com/llvm/llvm-project/pull/148712
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Add loan expiry analysis (PR #148712)

2025-07-16 Thread Gábor Horváth via llvm-branch-commits


@@ -778,6 +778,65 @@ class LoanPropagationAnalysis
   }
 };
 
+// = //
+// Expired Loans Analysis
+// = //
+
+/// The dataflow lattice for tracking the set of expired loans.
+struct ExpiredLattice {
+  LoanSet Expired;
+
+  ExpiredLattice() : Expired(nullptr) {};
+  explicit ExpiredLattice(LoanSet S) : Expired(S) {}
+
+  bool operator==(const ExpiredLattice &Other) const {
+return Expired == Other.Expired;
+  }
+  bool operator!=(const ExpiredLattice &Other) const {
+return !(*this == Other);
+  }
+
+  void dump(llvm::raw_ostream &OS) const {
+OS << "ExpiredLattice State:\n";
+if (Expired.isEmpty())
+  OS << "  \n";
+for (const LoanID &LID : Expired)
+  OS << "  Loan " << LID << " is expired\n";
+  }
+};
+
+/// The analysis that tracks which loans have expired.
+class ExpiredLoansAnalysis

Xazax-hun wrote:

So we have the expectation that we have a tight bound on this analysis. I 
wonder if there is a way to somehow add an assert to verify that the reality 
matches our expectations. Not super important but if it is not too complicated 
it could be nice.

We can also defer this to a later PR since we want to be able to add strict 
bounds to the number of iterations in the future and that might be required for 
us to easily assert on this. 

https://github.com/llvm/llvm-project/pull/148712
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Add loan expiry analysis (PR #148712)

2025-07-16 Thread Gábor Horváth via llvm-branch-commits

https://github.com/Xazax-hun edited 
https://github.com/llvm/llvm-project/pull/148712
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Revamp test suite using unittests (PR #149158)

2025-07-17 Thread Gábor Horváth via llvm-branch-commits


@@ -17,14 +17,87 @@
 
//===--===//
 #ifndef LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_H
 #define LLVM_CLANG_ANALYSIS_ANALYSES_LIFETIMESAFETY_H
-#include "clang/AST/DeclBase.h"
 #include "clang/Analysis/AnalysisDeclContext.h"
 #include "clang/Analysis/CFG.h"
-namespace clang {
+#include "llvm/ADT/ImmutableSet.h"
+#include "llvm/ADT/StringMap.h"
+#include 
 
-void runLifetimeSafetyAnalysis(const DeclContext &DC, const CFG &Cfg,
-   AnalysisDeclContext &AC);
+namespace clang::lifetimes {
+namespace internal {
+// Forward declarations of internal types.
+class Fact;
+class FactManager;
+class LoanPropagationAnalysis;
+struct LifetimeFactory;
 
-} // namespace clang
+/// A generic, type-safe wrapper for an ID, distinguished by its `Tag` type.
+/// Used for giving ID to loans and origins.
+template  struct ID {
+  uint32_t Value = 0;
+
+  bool operator==(const ID &Other) const { return Value == Other.Value; }
+  bool operator!=(const ID &Other) const { return !(*this == Other); }
+  bool operator<(const ID &Other) const { return Value < Other.Value; }
+  ID operator++(int) {
+ID Tmp = *this;
+++Value;
+return Tmp;
+  }
+  void Profile(llvm::FoldingSetNodeID &IDBuilder) const {
+IDBuilder.AddInteger(Value);
+  }
+};
+
+using LoanID = ID;
+using OriginID = ID;
+
+// Using LLVM's immutable collections is efficient for dataflow analysis
+// as it avoids deep copies during state transitions.
+// TODO(opt): Consider using a bitset to represent the set of loans.
+using LoanSet = llvm::ImmutableSet;
+using OriginSet = llvm::ImmutableSet;
+
+/// A `ProgramPoint` identifies a location in the CFG by pointing to a specific
+/// `Fact`. identified by a lifetime-related event (`Fact`).
+///
+/// A `ProgramPoint` has "after" semantics: it represents the location
+/// immediately after its corresponding `Fact`.
+using ProgramPoint = const Fact *;
+
+/// Running the lifetime safety analysis and querying its results. It
+/// encapsulates the various dataflow analyses.
+class LifetimeSafetyAnalysis {
+public:
+  LifetimeSafetyAnalysis(AnalysisDeclContext &AC);
+  ~LifetimeSafetyAnalysis();
+
+  void run();
+
+  /// Returns the set of loans an origin holds at a specific program point.
+  LoanSet getLoansAtPoint(OriginID OID, ProgramPoint PP) const;
+
+  /// Finds the OriginID for a given declaration.
+  /// Returns a null optional if not found.
+  std::optional getOriginIDForDecl(const ValueDecl *D) const;
+
+  /// Finds the LoanID's for the loan created with the specific variable as
+  /// their Path.
+  std::vector getLoanIDForVar(const VarDecl *VD) const;
+
+  llvm::StringMap getTestPoints() const;
+
+private:
+  AnalysisDeclContext &AC;
+  std::unique_ptr Factory;
+  std::unique_ptr FactMgr;
+  std::unique_ptr LoanPropagation;
+};
+} // namespace internal
+
+/// The main entry point for the analysis.
+void runLifetimeSafetyAnalysis(AnalysisDeclContext &AC);

Xazax-hun wrote:

Nit: I think we should move the public interface to the top of the file and 
push internal details to the end. 

https://github.com/llvm/llvm-project/pull/149158
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Revamp test suite using unittests (PR #149158)

2025-07-17 Thread Gábor Horváth via llvm-branch-commits


@@ -828,9 +869,49 @@ void runLifetimeSafetyAnalysis(const DeclContext &DC, 
const CFG &Cfg,
   ///blocks; only Decls are visible.  Therefore, loans in a block that
   ///never reach an Origin associated with a Decl can be safely dropped by
   ///the analysis.
-  LifetimeFactory Factory;
-  LoanPropagationAnalysis LoanPropagation(Cfg, AC, FactMgr, Factory);
-  LoanPropagation.run();
-  DEBUG_WITH_TYPE("LifetimeLoanPropagation", LoanPropagation.dump());
+  LoanPropagation =
+  std::make_unique(Cfg, AC, *FactMgr, *Factory);
+  LoanPropagation->run();
+}
+
+LoanSet LifetimeSafetyAnalysis::getLoansAtPoint(OriginID OID,
+ProgramPoint PP) const {
+  assert(LoanPropagation && "Analysis has not been run.");
+  return LoanPropagation->getLoans(OID, PP);
+}
+
+std::optional
+LifetimeSafetyAnalysis::getOriginIDForDecl(const ValueDecl *D) const {
+  assert(FactMgr && "FactManager not initialized");
+  // This assumes the OriginManager's `get` can find an existing origin.
+  // We might need a `find` method on OriginManager to avoid `getOrCreate` 
logic
+  // in a const-query context if that becomes an issue.
+  return FactMgr->getOriginMgr().get(*D);
+}
+
+std::vector
+LifetimeSafetyAnalysis::getLoanIDForVar(const VarDecl *VD) const {
+  assert(FactMgr && "FactManager not initialized");
+  std::vector Result;
+  for (const Loan &L : FactMgr->getLoanMgr().getLoans())
+if (L.Path.D == VD)
+  Result.push_back(L.ID);
+  return Result;
+}
+
+llvm::StringMap LifetimeSafetyAnalysis::getTestPoints() const {
+  assert(FactMgr && "FactManager not initialized");

Xazax-hun wrote:

I wonder if this is something that we want to have in debug/assert builds only. 

https://github.com/llvm/llvm-project/pull/149158
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Revamp test suite using unittests (PR #149158)

2025-07-17 Thread Gábor Horváth via llvm-branch-commits


@@ -807,17 +838,27 @@ class LoanPropagationAnalysis
 // - Modify origin liveness analysis to answer `bool isLive(Origin O, Point P)`
 // - Using the above three to perform the final error reporting.
 // = //
-} // anonymous namespace
 
-void runLifetimeSafetyAnalysis(const DeclContext &DC, const CFG &Cfg,
-   AnalysisDeclContext &AC) {
+// = //
+//  LifetimeSafetyAnalysis Class Implementation
+// = //
+
+LifetimeSafetyAnalysis::~LifetimeSafetyAnalysis() = default;

Xazax-hun wrote:

I think it is usually better to have defaulted special member functions in the 
header. 

https://github.com/llvm/llvm-project/pull/149158
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Revamp test suite using unittests (PR #149158)

2025-07-17 Thread Gábor Horváth via llvm-branch-commits


@@ -828,9 +869,49 @@ void runLifetimeSafetyAnalysis(const DeclContext &DC, 
const CFG &Cfg,
   ///blocks; only Decls are visible.  Therefore, loans in a block that
   ///never reach an Origin associated with a Decl can be safely dropped by
   ///the analysis.
-  LifetimeFactory Factory;
-  LoanPropagationAnalysis LoanPropagation(Cfg, AC, FactMgr, Factory);
-  LoanPropagation.run();
-  DEBUG_WITH_TYPE("LifetimeLoanPropagation", LoanPropagation.dump());
+  LoanPropagation =
+  std::make_unique(Cfg, AC, *FactMgr, *Factory);
+  LoanPropagation->run();
+}
+
+LoanSet LifetimeSafetyAnalysis::getLoansAtPoint(OriginID OID,
+ProgramPoint PP) const {
+  assert(LoanPropagation && "Analysis has not been run.");
+  return LoanPropagation->getLoans(OID, PP);
+}
+
+std::optional
+LifetimeSafetyAnalysis::getOriginIDForDecl(const ValueDecl *D) const {
+  assert(FactMgr && "FactManager not initialized");
+  // This assumes the OriginManager's `get` can find an existing origin.
+  // We might need a `find` method on OriginManager to avoid `getOrCreate` 
logic
+  // in a const-query context if that becomes an issue.
+  return FactMgr->getOriginMgr().get(*D);
+}
+
+std::vector
+LifetimeSafetyAnalysis::getLoanIDForVar(const VarDecl *VD) const {
+  assert(FactMgr && "FactManager not initialized");
+  std::vector Result;
+  for (const Loan &L : FactMgr->getLoanMgr().getLoans())
+if (L.Path.D == VD)
+  Result.push_back(L.ID);
+  return Result;
+}
+
+llvm::StringMap LifetimeSafetyAnalysis::getTestPoints() const {
+  assert(FactMgr && "FactManager not initialized");
+  llvm::StringMap AnnotationToPointMap;
+  for (const CFGBlock *Block : *AC.getCFG())
+for (const Fact *F : FactMgr->getFacts(Block))
+  if (const auto *TPF = F->getAs())
+AnnotationToPointMap[TPF->getAnnotation()] = F;

Xazax-hun wrote:

Should we have some protection against having multiple test points with the 
same annotation somewhere?

https://github.com/llvm/llvm-project/pull/149158
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Revamp test suite using unittests (PR #149158)

2025-07-18 Thread Gábor Horváth via llvm-branch-commits


@@ -828,9 +869,49 @@ void runLifetimeSafetyAnalysis(const DeclContext &DC, 
const CFG &Cfg,
   ///blocks; only Decls are visible.  Therefore, loans in a block that
   ///never reach an Origin associated with a Decl can be safely dropped by
   ///the analysis.
-  LifetimeFactory Factory;
-  LoanPropagationAnalysis LoanPropagation(Cfg, AC, FactMgr, Factory);
-  LoanPropagation.run();
-  DEBUG_WITH_TYPE("LifetimeLoanPropagation", LoanPropagation.dump());
+  LoanPropagation =
+  std::make_unique(Cfg, AC, *FactMgr, *Factory);
+  LoanPropagation->run();
+}
+
+LoanSet LifetimeSafetyAnalysis::getLoansAtPoint(OriginID OID,
+ProgramPoint PP) const {
+  assert(LoanPropagation && "Analysis has not been run.");
+  return LoanPropagation->getLoans(OID, PP);
+}
+
+std::optional
+LifetimeSafetyAnalysis::getOriginIDForDecl(const ValueDecl *D) const {
+  assert(FactMgr && "FactManager not initialized");
+  // This assumes the OriginManager's `get` can find an existing origin.
+  // We might need a `find` method on OriginManager to avoid `getOrCreate` 
logic
+  // in a const-query context if that becomes an issue.
+  return FactMgr->getOriginMgr().get(*D);
+}
+
+std::vector
+LifetimeSafetyAnalysis::getLoanIDForVar(const VarDecl *VD) const {
+  assert(FactMgr && "FactManager not initialized");
+  std::vector Result;
+  for (const Loan &L : FactMgr->getLoanMgr().getLoans())
+if (L.Path.D == VD)
+  Result.push_back(L.ID);
+  return Result;
+}
+
+llvm::StringMap LifetimeSafetyAnalysis::getTestPoints() const {
+  assert(FactMgr && "FactManager not initialized");

Xazax-hun wrote:

I see, feel free to leave it as is. Hopefully the linker would garbage collect 
this outside of tests anyway :)

https://github.com/llvm/llvm-project/pull/149158
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits


[llvm-branch-commits] [clang] [LifetimeSafety] Revamp test suite using unittests (PR #149158)

2025-07-17 Thread Gábor Horváth via llvm-branch-commits


@@ -828,9 +869,49 @@ void runLifetimeSafetyAnalysis(const DeclContext &DC, 
const CFG &Cfg,
   ///blocks; only Decls are visible.  Therefore, loans in a block that
   ///never reach an Origin associated with a Decl can be safely dropped by
   ///the analysis.
-  LifetimeFactory Factory;
-  LoanPropagationAnalysis LoanPropagation(Cfg, AC, FactMgr, Factory);
-  LoanPropagation.run();
-  DEBUG_WITH_TYPE("LifetimeLoanPropagation", LoanPropagation.dump());
+  LoanPropagation =
+  std::make_unique(Cfg, AC, *FactMgr, *Factory);
+  LoanPropagation->run();
+}
+
+LoanSet LifetimeSafetyAnalysis::getLoansAtPoint(OriginID OID,
+ProgramPoint PP) const {
+  assert(LoanPropagation && "Analysis has not been run.");
+  return LoanPropagation->getLoans(OID, PP);
+}
+
+std::optional
+LifetimeSafetyAnalysis::getOriginIDForDecl(const ValueDecl *D) const {
+  assert(FactMgr && "FactManager not initialized");
+  // This assumes the OriginManager's `get` can find an existing origin.
+  // We might need a `find` method on OriginManager to avoid `getOrCreate` 
logic
+  // in a const-query context if that becomes an issue.
+  return FactMgr->getOriginMgr().get(*D);
+}
+
+std::vector
+LifetimeSafetyAnalysis::getLoanIDForVar(const VarDecl *VD) const {
+  assert(FactMgr && "FactManager not initialized");
+  std::vector Result;
+  for (const Loan &L : FactMgr->getLoanMgr().getLoans())
+if (L.Path.D == VD)
+  Result.push_back(L.ID);
+  return Result;
+}
+
+llvm::StringMap LifetimeSafetyAnalysis::getTestPoints() const {
+  assert(FactMgr && "FactManager not initialized");

Xazax-hun wrote:

Oh, my bad! The latter. 

https://github.com/llvm/llvm-project/pull/149158
___
llvm-branch-commits mailing list
llvm-branch-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits