Change mangling of objects inside block literals.

This changes the mangling of local static variables/etc. inside blocks
to do something simple and sane.  This avoids depending on the way we mangle
blocks, which isn't really appropriate here.

John, please take a look at this to make sure the mangling I chose is sane.

Fixes <rdar://problem/14074423>.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@184780 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp
index 7102bf3..cf1e512 100644
--- a/lib/AST/ItaniumMangle.cpp
+++ b/lib/AST/ItaniumMangle.cpp
@@ -1416,12 +1416,15 @@
     return;
 
   if (const BlockDecl *Block = dyn_cast<BlockDecl>(DC)) {
-    manglePrefix(getEffectiveParentContext(DC), NoFunction);    
-    SmallString<64> Name;
-    llvm::raw_svector_ostream NameStream(Name);
-    Context.mangleBlock(Block, NameStream);
-    NameStream.flush();
-    Out << Name.size() << Name;
+    // The symbol we're adding a prefix for isn't externally
+    // visible; make up something sane.
+    // FIXME: This isn't always true!
+    SmallString<16> BlockPrefix;
+    BlockPrefix += "__block_prefix_internal";
+    unsigned Number = Context.getBlockId(Block, false);
+    if (Number > 1)
+      BlockPrefix += llvm::utostr_32(Number - 2);
+    Out << BlockPrefix.size() << BlockPrefix;
     return;
   } else if (isa<CapturedDecl>(DC)) {
     // Skip CapturedDecl context.