github-actions[bot] wrote:

<!--LLVM CODE FORMAT COMMENT: {clang-format}-->


:warning: C/C++ code formatter, clang-format found issues in your code. 
:warning:

<details>
<summary>
You can test this locally with the following command:
</summary>

``````````bash
git-clang-format --diff origin/main HEAD --extensions cpp,h -- 
clang/include/clang/Analysis/Analyses/LifetimeSafety/Facts.h 
clang/include/clang/Analysis/Analyses/LifetimeSafety/LiveOrigins.h 
clang/include/clang/Analysis/Analyses/LifetimeSafety/LoanPropagation.h 
clang/include/clang/Analysis/Analyses/LifetimeSafety/MovedLoans.h 
clang/include/clang/Analysis/Analyses/LifetimeSafety/Utils.h 
clang/lib/Analysis/LifetimeSafety/Checker.cpp 
clang/lib/Analysis/LifetimeSafety/Dataflow.h 
clang/lib/Analysis/LifetimeSafety/Facts.cpp 
clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp 
clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp 
clang/lib/Analysis/LifetimeSafety/MovedLoans.cpp 
clang/unittests/Analysis/LifetimeSafetyTest.cpp 
llvm/include/llvm/ADT/ImmutableSet.h --diff_from_common_commit
``````````

:warning:
The reproduction instructions above might return results for more than one PR
in a stack if you are using a stacked PR workflow. You can limit the results by
changing `origin/main` to the base branch/commit you want to compare against.
:warning:

</details>

<details>
<summary>
View the diff from clang-format here.
</summary>

``````````diff
diff --git a/clang/include/clang/Analysis/Analyses/LifetimeSafety/Utils.h 
b/clang/include/clang/Analysis/Analyses/LifetimeSafety/Utils.h
index 0ac028ff0..2f59d504e 100644
--- a/clang/include/clang/Analysis/Analyses/LifetimeSafety/Utils.h
+++ b/clang/include/clang/Analysis/Analyses/LifetimeSafety/Utils.h
@@ -46,7 +46,8 @@ using MapTy = llvm::ImmutableMap<KeyT, ValT, 
llvm::ImutKeyValueInfo<KeyT, ValT>,
 
 /// Computes the union of two ImmutableSets.
 template <typename T>
-SetTy<T> join(const SetTy<T> &A_ref, const SetTy<T> &B_ref, typename 
SetTy<T>::Factory &F) {
+SetTy<T> join(const SetTy<T> &A_ref, const SetTy<T> &B_ref,
+              typename SetTy<T>::Factory &F) {
   if (A_ref.getRootWithoutRetain() == B_ref.getRootWithoutRetain())
     return A_ref;
   SetTy<T> A = A_ref;
@@ -81,9 +82,9 @@ enum class JoinKind {
 /// JoinValues is commutative with a left identity, which holds for the
 /// lifetime lattices.
 template <typename KeyT, typename ValT, typename Joiner>
-MapTy<KeyT, ValT> join(const MapTy<KeyT, ValT> &A_ref, const MapTy<KeyT, ValT> 
&B_ref,
-                       typename MapTy<KeyT, ValT>::Factory &F,
-                       Joiner JoinValues, JoinKind Kind) {
+MapTy<KeyT, ValT>
+join(const MapTy<KeyT, ValT> &A_ref, const MapTy<KeyT, ValT> &B_ref,
+     typename MapTy<KeyT, ValT>::Factory &F, Joiner JoinValues, JoinKind Kind) 
{
   if (A_ref.getRootWithoutRetain() == B_ref.getRootWithoutRetain())
     return A_ref;
 
@@ -97,8 +98,9 @@ MapTy<KeyT, ValT> join(const MapTy<KeyT, ValT> &A_ref, const 
MapTy<KeyT, ValT> &
   }
 
   using ValueTy = typename MapTy<KeyT, ValT>::value_type;
-  auto Combine = [&JoinValues, Swapped](const ValueTy *AElem,
-                               const ValueTy *BElem) -> std::pair<KeyT, ValT> {
+  auto Combine = [&JoinValues,
+                  Swapped](const ValueTy *AElem,
+                           const ValueTy *BElem) -> std::pair<KeyT, ValT> {
     const ValueTy *OrigA = Swapped ? BElem : AElem;
     const ValueTy *OrigB = Swapped ? AElem : BElem;
     const KeyT &Key = AElem ? AElem->first : BElem->first;
@@ -110,9 +112,10 @@ MapTy<KeyT, ValT> join(const MapTy<KeyT, ValT> &A_ref, 
const MapTy<KeyT, ValT> &
   // has a left identity); symmetric passes unmatched keys through JoinValues.
   // The lifetime joins are idempotent lattice joins, so pointer-identical
   // subtrees (common once one state is derived from the other) can be shared.
-  MapTy<KeyT, ValT> Result = F.mergeWith(A, B, Combine,
-                                         /*KeepUnmatched=*/Kind == 
JoinKind::Asymmetric,
-                                         /*SkipShared=*/true);
+  MapTy<KeyT, ValT> Result =
+      F.mergeWith(A, B, Combine,
+                  /*KeepUnmatched=*/Kind == JoinKind::Asymmetric,
+                  /*SkipShared=*/true);
   if (Result.getRootWithoutRetain() == A_ref.getRootWithoutRetain())
     return A_ref;
   if (Result.getRootWithoutRetain() == B_ref.getRootWithoutRetain())
diff --git a/clang/lib/Analysis/LifetimeSafety/Checker.cpp 
b/clang/lib/Analysis/LifetimeSafety/Checker.cpp
index 678c32c98..a83d5dc0c 100644
--- a/clang/lib/Analysis/LifetimeSafety/Checker.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/Checker.cpp
@@ -128,10 +128,9 @@ public:
         break;
       }
       PathKey Key = {RootVal, static_cast<unsigned>(Path.getKind())};
-      auto It = std::lower_bound(LoansByPath.begin(), LoansByPath.end(), Key,
-                                 [](const auto &X, const PathKey &K) {
-                                   return X.first < K;
-                                 });
+      auto It = std::lower_bound(
+          LoansByPath.begin(), LoansByPath.end(), Key,
+          [](const auto &X, const PathKey &K) { return X.first < K; });
       if (It != LoansByPath.end() && It->first == Key) {
         It->second.push_back(Loan->getID());
       } else {
@@ -221,7 +220,8 @@ public:
     }
   }
 
-  /// Returns the corresponding loan IDs for an AccessPath using the 
precomputed map.
+  /// Returns the corresponding loan IDs for an AccessPath using the 
precomputed
+  /// map.
   llvm::ArrayRef<LoanID> getLoansForPath(const AccessPath &Path) const {
     const void *RootVal = nullptr;
     switch (Path.getKind()) {
@@ -242,10 +242,9 @@ public:
       break;
     }
     PathKey Key = {RootVal, static_cast<unsigned>(Path.getKind())};
-    auto It = std::lower_bound(LoansByPath.begin(), LoansByPath.end(), Key,
-                               [](const auto &X, const PathKey &K) {
-                                 return X.first < K;
-                               });
+    auto It = std::lower_bound(
+        LoansByPath.begin(), LoansByPath.end(), Key,
+        [](const auto &X, const PathKey &K) { return X.first < K; });
     if (It != LoansByPath.end() && It->first == Key)
       return It->second;
     return {};
@@ -259,7 +258,7 @@ public:
   /// hold that are prefixed by the expired path.
   void checkExpiry(const ExpireFact *EF) {
     const AccessPath &ExpiredPath = EF->getAccessPath();
-    
+
     llvm::ArrayRef<LoanID> ExpiredLoanIDs = getLoansForPath(ExpiredPath);
     if (ExpiredLoanIDs.empty())
       return;
@@ -267,21 +266,27 @@ public:
     const LivenessMap &Origins = LiveOrigins.getLiveOriginsAt(EF);
 
     auto CheckLoans = [&](OriginID OID, const LoanSet &HeldLoans) {
-        for (LoanID HeldLoanID : ExpiredLoanIDs) {
-            if (!HeldLoans.contains(HeldLoanID)) continue;
-            const LivenessInfo *LiveInfo = Origins.lookup(OID);
-            if (!LiveInfo) continue;
-            
-            const Loan *HeldLoan = FactMgr.getLoanMgr().getLoan(HeldLoanID);
-            PendingWarning &CurWarning = FinalWarningsMap[HeldLoan->getID()];
-            if (CurWarning.CausingFactDominatesExpiry) continue;
-            if (causingFactDominatesExpiry(LiveInfo->Kind))
-                CurWarning.CausingFactDominatesExpiry = true;
-            CurWarning.CausingFact = LiveInfo->CausingFact;
-            CurWarning.ExpiryLoc = EF->getExpiryLoc();
-            CurWarning.MovedExpr = 
MovedLoans.getMovedLoans(EF).lookup(HeldLoanID) ? 
*MovedLoans.getMovedLoans(EF).lookup(HeldLoanID) : nullptr;
-            CurWarning.InvalidatedByExpr = nullptr;
-        }
+      for (LoanID HeldLoanID : ExpiredLoanIDs) {
+        if (!HeldLoans.contains(HeldLoanID))
+          continue;
+        const LivenessInfo *LiveInfo = Origins.lookup(OID);
+        if (!LiveInfo)
+          continue;
+
+        const Loan *HeldLoan = FactMgr.getLoanMgr().getLoan(HeldLoanID);
+        PendingWarning &CurWarning = FinalWarningsMap[HeldLoan->getID()];
+        if (CurWarning.CausingFactDominatesExpiry)
+          continue;
+        if (causingFactDominatesExpiry(LiveInfo->Kind))
+          CurWarning.CausingFactDominatesExpiry = true;
+        CurWarning.CausingFact = LiveInfo->CausingFact;
+        CurWarning.ExpiryLoc = EF->getExpiryLoc();
+        CurWarning.MovedExpr =
+            MovedLoans.getMovedLoans(EF).lookup(HeldLoanID)
+                ? *MovedLoans.getMovedLoans(EF).lookup(HeldLoanID)
+                : nullptr;
+        CurWarning.InvalidatedByExpr = nullptr;
+      }
     };
 
     LoanPropagation.forEachOriginWithLoansAt(EF, CheckLoans);
@@ -303,7 +308,8 @@ public:
     llvm::SmallVector<LoanID, 4> InvalidatedLoanIDs;
     for (const Loan *L : FactMgr.getLoanMgr().getLoans()) {
       for (LoanID InvalidID : *DirectlyInvalidatedLoans) {
-        if (FactMgr.getLoanMgr().getLoan(InvalidID)->getAccessPath() == 
L->getAccessPath()) {
+        if (FactMgr.getLoanMgr().getLoan(InvalidID)->getAccessPath() ==
+            L->getAccessPath()) {
           InvalidatedLoanIDs.push_back(L->getID());
           break;
         }
@@ -316,23 +322,25 @@ public:
     const LivenessMap &Origins = LiveOrigins.getLiveOriginsAt(IOF);
 
     auto CheckLoans = [&](OriginID OID, const LoanSet &HeldLoans) {
-        for (LoanID LiveLoanID : InvalidatedLoanIDs) {
-            if (!HeldLoans.contains(LiveLoanID)) continue;
-            const LivenessInfo *LiveInfo = Origins.lookup(OID);
-            if (!LiveInfo) continue;
-            
-            bool CurDomination = causingFactDominatesExpiry(LiveInfo->Kind);
-            bool LastDomination =
-                FinalWarningsMap.lookup(LiveLoanID).CausingFactDominatesExpiry;
-            if (!LastDomination) {
-                FinalWarningsMap[LiveLoanID] = {
-                    /*ExpiryLoc=*/{},
-                    /*CausingFact=*/LiveInfo->CausingFact,
-                    /*MovedExpr=*/nullptr,
-                    /*InvalidatedByExpr=*/IOF->getInvalidationExpr(),
-                    /*CausingFactDominatesExpiry=*/CurDomination};
-            }
+      for (LoanID LiveLoanID : InvalidatedLoanIDs) {
+        if (!HeldLoans.contains(LiveLoanID))
+          continue;
+        const LivenessInfo *LiveInfo = Origins.lookup(OID);
+        if (!LiveInfo)
+          continue;
+
+        bool CurDomination = causingFactDominatesExpiry(LiveInfo->Kind);
+        bool LastDomination =
+            FinalWarningsMap.lookup(LiveLoanID).CausingFactDominatesExpiry;
+        if (!LastDomination) {
+          FinalWarningsMap[LiveLoanID] = {
+              /*ExpiryLoc=*/{},
+              /*CausingFact=*/LiveInfo->CausingFact,
+              /*MovedExpr=*/nullptr,
+              /*InvalidatedByExpr=*/IOF->getInvalidationExpr(),
+              /*CausingFactDominatesExpiry=*/CurDomination};
         }
+      }
     };
 
     LoanPropagation.forEachOriginWithLoansAt(IOF, CheckLoans);
diff --git a/clang/lib/Analysis/LifetimeSafety/Dataflow.h 
b/clang/lib/Analysis/LifetimeSafety/Dataflow.h
index 4f4d01db3..2a92482db 100644
--- a/clang/lib/Analysis/LifetimeSafety/Dataflow.h
+++ b/clang/lib/Analysis/LifetimeSafety/Dataflow.h
@@ -109,11 +109,12 @@ public:
     while (const CFGBlock *B = W.dequeue()) {
       Lattice StateIn = *getInState(B);
       std::optional<Lattice> StateOut = transferBlock(B, std::move(StateIn));
-      // If none of the facts inside the block changed state, and the final 
state
-      // is unchanged, transferBlock returns std::nullopt. We don't need to 
propagate.
+      // If none of the facts inside the block changed state, and the final
+      // state is unchanged, transferBlock returns std::nullopt. We don't need
+      // to propagate.
       if (!StateOut)
         continue;
-      
+
       const std::optional<Lattice> &OldOutState = getOutState(B);
       if (OldOutState && *OldOutState == *StateOut)
         continue;
@@ -136,7 +137,8 @@ public:
 
 protected:
   const Lattice &getState(ProgramPoint P) const {
-    assert(PointInitialized.test(P->getID().Value) && "Queried uninitialized 
state!");
+    assert(PointInitialized.test(P->getID().Value) &&
+           "Queried uninitialized state!");
     return PointToState[P->getID().Value];
   }
 
diff --git a/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp 
b/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
index 05da33a83..d992b4327 100644
--- a/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/LiveOrigins.cpp
@@ -169,7 +169,8 @@ public:
   /// Issuing a new loan to an origin kills its liveness.
   Lattice transfer(Lattice In, const IssueFact &IF) {
     if (In.LiveOrigins.lookup(IF.getOriginID()))
-      return Lattice(Factory.remove(std::move(In.LiveOrigins), 
IF.getOriginID()));
+      return Lattice(
+          Factory.remove(std::move(In.LiveOrigins), IF.getOriginID()));
     return In;
   }
 
@@ -198,7 +199,8 @@ public:
 
   Lattice transfer(Lattice In, const KillOriginFact &F) {
     if (In.LiveOrigins.lookup(F.getKilledOrigin()))
-      return Lattice(Factory.remove(std::move(In.LiveOrigins), 
F.getKilledOrigin()));
+      return Lattice(
+          Factory.remove(std::move(In.LiveOrigins), F.getKilledOrigin()));
     return In;
   }
 
diff --git a/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp 
b/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
index d90a6f043..fac01bb5e 100644
--- a/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/LoanPropagation.cpp
@@ -195,9 +195,11 @@ public:
     LoanSet DestLoans =
         Existing ? (F.getKillDest() ? LoanSetFactory.getEmptySet() : *Existing)
                  : LoanSetFactory.getEmptySet();
-                 
+
     const LoanSet *SrcLoans = getLoans(In, SrcOID);
-    LoanSet MergedLoans = SrcLoans ? utils::join(DestLoans, *SrcLoans, 
LoanSetFactory) : DestLoans;
+    LoanSet MergedLoans =
+        SrcLoans ? utils::join(DestLoans, *SrcLoans, LoanSetFactory)
+                 : DestLoans;
 
     return setLoans(std::move(In), DestOID, MergedLoans, Existing);
   }
@@ -215,7 +217,8 @@ public:
       const LoanSet *Existing = isPersistent(*OID)
                                     ? In.PersistentOrigins.lookup(*OID)
                                     : In.BlockLocalOrigins.lookup(*OID);
-      return setLoans(std::move(In), *OID, LoanSetFactory.getEmptySet(), 
Existing);
+      return setLoans(std::move(In), *OID, LoanSetFactory.getEmptySet(),
+                      Existing);
     }
     return In;
   }
@@ -224,8 +227,10 @@ public:
     return getLoans(getState(P), OID);
   }
 
-  void forEachOriginWithLoansAt(ProgramPoint P,
-                                
clang::lifetimes::internal::LoanPropagationAnalysis::LoanMatchCallback CB) 
const {
+  void forEachOriginWithLoansAt(
+      ProgramPoint P,
+      clang::lifetimes::internal::LoanPropagationAnalysis::LoanMatchCallback 
CB)
+      const {
     const auto &PState = getState(P);
     for (const auto &[OID, Loans] : PState.PersistentOrigins)
       CB(OID, Loans);
@@ -319,10 +324,11 @@ private:
     return PersistentOrigins.test(OID.Value);
   }
 
-  Lattice setLoans(Lattice L, OriginID OID, LoanSet Loans, const LoanSet 
*Existing) {
+  Lattice setLoans(Lattice L, OriginID OID, LoanSet Loans,
+                   const LoanSet *Existing) {
     if (Existing && *Existing == Loans)
       return L;
-      
+
     if (Loans.isEmpty()) {
       if (!Existing)
         return L;
@@ -404,12 +410,14 @@ LoanPropagationAnalysis::LoanPropagationAnalysis(
 
 LoanPropagationAnalysis::~LoanPropagationAnalysis() = default;
 
-const LoanSet *LoanPropagationAnalysis::getLoans(OriginID OID, ProgramPoint P) 
const {
+const LoanSet *LoanPropagationAnalysis::getLoans(OriginID OID,
+                                                 ProgramPoint P) const {
   return PImpl->getLoans(OID, P);
 }
 
-void LoanPropagationAnalysis::forEachOriginWithLoansAt(ProgramPoint P, 
LoanPropagationAnalysis::LoanMatchCallback CB) const {
-    PImpl->forEachOriginWithLoansAt(P, CB);
+void LoanPropagationAnalysis::forEachOriginWithLoansAt(
+    ProgramPoint P, LoanPropagationAnalysis::LoanMatchCallback CB) const {
+  PImpl->forEachOriginWithLoansAt(P, CB);
 }
 
 llvm::SmallVector<OriginID> LoanPropagationAnalysis::buildOriginFlowChain(
diff --git a/clang/lib/Analysis/LifetimeSafety/MovedLoans.cpp 
b/clang/lib/Analysis/LifetimeSafety/MovedLoans.cpp
index 83b60d6d2..9fb40a50e 100644
--- a/clang/lib/Analysis/LifetimeSafety/MovedLoans.cpp
+++ b/clang/lib/Analysis/LifetimeSafety/MovedLoans.cpp
@@ -25,7 +25,8 @@ namespace {
 struct Lattice {
   MovedLoansMap MovedLoans = MovedLoansMap(nullptr);
 
-  explicit Lattice(MovedLoansMap MovedLoans) : 
MovedLoans(std::move(MovedLoans)) {}
+  explicit Lattice(MovedLoansMap MovedLoans)
+      : MovedLoans(std::move(MovedLoans)) {}
 
   Lattice() = default;
 
@@ -78,7 +79,8 @@ public:
   /// potentially moved.
   Lattice transfer(Lattice In, const MovedOriginFact &F) {
     OriginID MovedOrigin = F.getMovedOrigin();
-    const LoanSet *ImmediatelyMovedLoans = 
LoanPropagation.getLoans(MovedOrigin, &F);
+    const LoanSet *ImmediatelyMovedLoans =
+        LoanPropagation.getLoans(MovedOrigin, &F);
     if (!ImmediatelyMovedLoans || ImmediatelyMovedLoans->isEmpty())
       return In;
 
@@ -91,25 +93,29 @@ public:
       return false;
     };
     const auto &Origins = LiveOrigins.getLiveOriginsAt(&F);
-    
+
     auto CheckLoans = [&](OriginID O, const LoanSet &Loans) {
-        if (!Origins.lookup(O)) return;
-        for (LoanID LiveLoan : Loans) {
-            const Loan *LiveLoanPtr = LoanMgr.getLoan(LiveLoan);
-            if (IsInvalidated(LiveLoanPtr->getAccessPath())) {
-                if (const Expr *const *Existing = 
In.MovedLoans.lookup(LiveLoan))
-                    if (*Existing == F.getMoveExpr())
-                        continue;
-                In = 
Lattice(MovedLoansMapFactory.add(std::move(In.MovedLoans), LiveLoan, 
F.getMoveExpr()));
-            }
+      if (!Origins.lookup(O))
+        return;
+      for (LoanID LiveLoan : Loans) {
+        const Loan *LiveLoanPtr = LoanMgr.getLoan(LiveLoan);
+        if (IsInvalidated(LiveLoanPtr->getAccessPath())) {
+          if (const Expr *const *Existing = In.MovedLoans.lookup(LiveLoan))
+            if (*Existing == F.getMoveExpr())
+              continue;
+          In = Lattice(MovedLoansMapFactory.add(std::move(In.MovedLoans),
+                                                LiveLoan, F.getMoveExpr()));
         }
+      }
     };
-    
+
     LoanPropagation.forEachOriginWithLoansAt(&F, CheckLoans);
     return In;
   }
 
-  const MovedLoansMap &getMovedLoans(ProgramPoint P) { return 
getState(P).MovedLoans; }
+  const MovedLoansMap &getMovedLoans(ProgramPoint P) {
+    return getState(P).MovedLoans;
+  }
 
 private:
   const LoanPropagationAnalysis &LoanPropagation;

``````````

</details>


https://github.com/llvm/llvm-project/pull/211225
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to