[clang] [clang][dataflow] Clear `ExprToLoc` and `ExprToVal` at the start of a block. (PR #72985)

via cfe-commits cfe-commits at lists.llvm.org
Tue Nov 21 06:50:59 PST 2023


================
@@ -257,7 +257,12 @@ class JoinedStateBuilder {
       // initialize the state of each basic block differently.
       return {AC.Analysis.typeErasedInitialElement(), AC.InitEnv.fork()};
     if (All.size() == 1)
-      return Owned.empty() ? All.front()->fork() : std::move(Owned.front());
+      // Join the environment with itself so that we discard the entries from
+      // `ExprToLoc` and `ExprToVal`.
+      // FIXME: We could consider writing special-case code for this that only
+      // does the discarding, but it's not clear if this is worth it.
+      return {All[0]->Lattice,
+              Environment::join(All[0]->Env, All[0]->Env, AC.Analysis)};
----------------
martinboehme wrote:

On an equivalent change in #72850, @ymand commented:

> This change may obviate the value of JoinedStateBuilder altogether, since a key point was to save on copies. Once we always build a fresh one, I'm not sure the complexity is doing much anymore. Please double check this.

I think there's still value in keeping the `JoinedStateBuilder` as it abstracts away the logic of what to do for different sizes of `All`. This logic would otherwise need to go in `computeBlockInputState()`, which is already large as it is.

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


More information about the cfe-commits mailing list