[clang] [clang][dataflow] Don't crash when BlockToState is called from unreachable path (PR #65732)

Kinuko Yasuda via cfe-commits cfe-commits at lists.llvm.org
Fri Sep 8 02:32:45 PDT 2023


================
@@ -43,7 +43,20 @@ const Environment *StmtToEnvMap::getEnvironment(const Stmt &S) const {
   if (!CFCtx.isBlockReachable(*BlockIt->getSecond()))
     return nullptr;
   const auto &State = BlockToState[BlockIt->getSecond()->getBlockID()];
-  assert(State);
+  if (!(State)) {
+    LLVM_DEBUG({
+      // State can be null when this block is unreachable from the block that
+      // called this method.
+      bool hasUnreachableEdgeFromPred = false;
+      for (auto B : BlockIt->getSecond()->preds())
+        if (!B) {
+          hasUnreachableEdgeFromPred = true;
+          break;
+        }
+      assert(hasUnreachableEdgeFromPred);
----------------
kinu wrote:

This check can be done more thoroughly (maybe with some pre-processing) if we want, but can be a bit costly. We won't hit this very often though

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


More information about the cfe-commits mailing list