[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
Fri Mar 1 11:47:56 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:

Since this is a property of the CFG, can we compute this just once per block (rather than every time we visit the block)?

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


More information about the cfe-commits mailing list