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

via cfe-commits cfe-commits at lists.llvm.org
Thu Mar 7 04:05:37 PST 2024


================
@@ -94,6 +94,38 @@ static llvm::BitVector findReachableBlocks(const CFG &Cfg) {
   return BlockReachable;
 }
 
+static llvm::DenseSet<const CFGBlock *>
+buildContainsExprConsumedInDifferentBlock(
+    const CFG &Cfg,
+    const llvm::DenseMap<const Stmt *, const CFGBlock *> &StmtToBlock) {
+  llvm::DenseSet<const CFGBlock *> Result;
+
+  auto CheckChildExprs = [&Result, &StmtToBlock](const Stmt *S,
+                                                 const CFGBlock *Block) {
+    for (const Stmt *Child : S->children()) {
+      if (!isa<Expr>(Child))
+        continue;
+      const CFGBlock *ChildBlock = StmtToBlock.lookup(Child);
+      if (ChildBlock != Block)
+        Result.insert(ChildBlock);
+    }
+  };
+
+  for (const CFGBlock *Block : Cfg) {
+    if (Block == nullptr)
+      continue;
+
+    for (const CFGElement &Element : *Block)
----------------
martinboehme wrote:

> Could we early terminate as soon as we found an expression that is consumed in a different block?

That doesn't work, because we insert `ChildBlock`, not `Block`. This block might contain expressions from various other blocks, and we want to insert all of those blocks into `Result`, so we can't terminate the loop early.

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


More information about the cfe-commits mailing list