Fix CFGBuilder crash reported in PR 8141.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113826 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Analysis/CFG.cpp b/lib/Analysis/CFG.cpp
index 02ff218..15699db 100644
--- a/lib/Analysis/CFG.cpp
+++ b/lib/Analysis/CFG.cpp
@@ -525,8 +525,12 @@
       AppendStmt(Block, B, asc);
     }
 
-    Visit(B->getRHS());
-    return Visit(B->getLHS(), AddStmtChoice::AsLValueNotAlwaysAdd);
+    // If visiting RHS causes us to finish 'Block' and the LHS doesn't
+    // create a new block, then we should return RBlock.  Otherwise
+    // we'll incorrectly return NULL.
+    CFGBlock *RBlock = Visit(B->getRHS());
+    CFGBlock *LBlock = Visit(B->getLHS(), AddStmtChoice::AsLValueNotAlwaysAdd);
+    return LBlock ? LBlock : RBlock;
   }
 
   return VisitStmt(B, asc);