[clang] [clang][dataflow] Refactor processing of terminator element (PR #84499)

via cfe-commits cfe-commits at lists.llvm.org
Fri Mar 8 07:25:03 PST 2024


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 cb6f657a70f7a8d6ecd4fcc2101550a7400f94a7 210a2b83d3647c97ad4fc5eab9e0d9c68a5711a4 -- clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
``````````

</details>

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

``````````diff
diff --git a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
index 3acd6be874..c6522f1569 100644
--- a/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
+++ b/clang/lib/Analysis/FlowSensitive/TypeErasedDataflowAnalysis.cpp
@@ -258,29 +258,29 @@ computeBlockInputState(const CFGBlock &Block, AnalysisContext &AC) {
       continue;
     const TypeErasedDataflowAnalysisState &PredState = *MaybePredState;
 
-      if (const Stmt *PredTerminatorStmt = Pred->getTerminatorStmt()) {
-        bool BranchVal = blockIndexInPredecessor(*Pred, Block) == 0;
-        const Expr *Cond = TerminatorVisitor().Visit(PredTerminatorStmt);
-        if (Cond != nullptr) {
-          // `transferBranch` may need to mutate the environment to describe the
-          // dynamic effect of the terminator for a given branch.  Copy now.
-          TypeErasedDataflowAnalysisState Copy = MaybePredState->fork();
-          if (AC.Analysis.builtinOptions()) {
-            auto *CondVal = Copy.Env.get<BoolValue>(*Cond);
-            // In transferCFGBlock(), we ensure that we always have a `Value`
-            // for the terminator condition, so assert this. We consciously
-            // assert ourselves instead of asserting via `cast()` so that we get
-            // a more meaningful line number if the assertion fails.
-            assert(CondVal != nullptr);
-            BoolValue *AssertedVal =
-                BranchVal ? CondVal : &Copy.Env.makeNot(*CondVal);
-            Copy.Env.assume(AssertedVal->formula());
-          }
-          AC.Analysis.transferBranchTypeErased(BranchVal, Cond, Copy.Lattice,
-                                               Copy.Env);
-          Builder.addOwned(std::move(Copy));
-          continue;
+    if (const Stmt *PredTerminatorStmt = Pred->getTerminatorStmt()) {
+      bool BranchVal = blockIndexInPredecessor(*Pred, Block) == 0;
+      const Expr *Cond = TerminatorVisitor().Visit(PredTerminatorStmt);
+      if (Cond != nullptr) {
+        // `transferBranch` may need to mutate the environment to describe the
+        // dynamic effect of the terminator for a given branch.  Copy now.
+        TypeErasedDataflowAnalysisState Copy = MaybePredState->fork();
+        if (AC.Analysis.builtinOptions()) {
+          auto *CondVal = Copy.Env.get<BoolValue>(*Cond);
+          // In transferCFGBlock(), we ensure that we always have a `Value`
+          // for the terminator condition, so assert this. We consciously
+          // assert ourselves instead of asserting via `cast()` so that we get
+          // a more meaningful line number if the assertion fails.
+          assert(CondVal != nullptr);
+          BoolValue *AssertedVal =
+              BranchVal ? CondVal : &Copy.Env.makeNot(*CondVal);
+          Copy.Env.assume(AssertedVal->formula());
         }
+        AC.Analysis.transferBranchTypeErased(BranchVal, Cond, Copy.Lattice,
+                                             Copy.Env);
+        Builder.addOwned(std::move(Copy));
+        continue;
+      }
       }
       Builder.addUnowned(PredState);
   }

``````````

</details>


https://github.com/llvm/llvm-project/pull/84499


More information about the cfe-commits mailing list