[clang] [clang][nullability] Don't discard expression state before end of full-expression. (PR #82611)

Yitzhak Mandelbaum via cfe-commits cfe-commits at lists.llvm.org
Wed Mar 6 07:22:02 PST 2024


================
@@ -307,7 +310,22 @@ computeBlockInputState(const CFGBlock &Block, AnalysisContext &AC) {
     }
   }
 
-  JoinedStateBuilder Builder(AC);
+  // If any of the predecessor blocks contains an expression consumed in a
+  // different block, we need to keep expression state.
+  // Note that in this case, we keep expression state for all predecessors,
+  // rather than only those predecessors that actually contain an expression
+  // consumed in a different block. While this is potentially suboptimal, it's
+  // actually likely, if we have control flow within a full expression, that
+  // all predecessors have expression state consumed in a different block.
+  Environment::ExprJoinBehavior ExprBehavior = Environment::DiscardExprState;
+  for (const CFGBlock *Pred : Preds) {
+    if (Pred && AC.CFCtx.containsExprConsumedInDifferentBlock(*Pred)) {
+      ExprBehavior = Environment::KeepExprState;
+      break;
+    }
+  }
----------------
ymand wrote:

re: EmbellishedCFG -- sure.

Ok, I'm fine leaving as is, given the benchmarks. But, I would think there's a simple compromise of just computing it locally in this file (as now), but caching it in `AnalysisContext` (which is local to that file), since its a fixed property of the block.

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


More information about the cfe-commits mailing list