Handle the case where EmitBlock might be called multiple times for the same block. Fixes PR3536.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64252 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/CodeGen/CGStmt.cpp b/lib/CodeGen/CGStmt.cpp
index 85ea8c5..d23547f 100644
--- a/lib/CodeGen/CGStmt.cpp
+++ b/lib/CodeGen/CGStmt.cpp
@@ -182,8 +182,14 @@
 
   // If necessary, associate the block with the cleanup stack size.
   if (!CleanupEntries.empty()) {
-    BlockScopes[BB] = CleanupEntries.size() - 1;
-    CleanupEntries.back().Blocks.push_back(BB);
+    // Check if the basic block has already been inserted.
+    BlockScopeMap::iterator I = BlockScopes.find(BB);
+    if (I != BlockScopes.end()) {
+      assert(I->second == CleanupEntries.size() - 1);
+    } else {
+      BlockScopes[BB] = CleanupEntries.size() - 1;
+      CleanupEntries.back().Blocks.push_back(BB);
+    }
   }
   
   CurFn->getBasicBlockList().push_back(BB);