diff --git a/include/clang/AST/Mangle.h b/include/clang/AST/Mangle.h
index 8dbca8d..a35f1d0 100644
--- a/include/clang/AST/Mangle.h
+++ b/include/clang/AST/Mangle.h
@@ -95,7 +95,7 @@ public:
   /// @{
 
   virtual bool shouldMangleDeclName(const NamedDecl *D) = 0;
-  virtual void mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &)=0;
+  virtual void mangleName(const NamedDecl *D, llvm::raw_svector_ostream &)=0;
   virtual void mangleThunk(const CXXMethodDecl *MD,
                           const ThunkInfo &Thunk,
                           llvm::SmallVectorImpl<char> &) = 0;
@@ -114,20 +114,20 @@ public:
   virtual void mangleCXXRTTI(QualType T, llvm::SmallVectorImpl<char> &) = 0;
   virtual void mangleCXXRTTIName(QualType T, llvm::SmallVectorImpl<char> &) = 0;
   virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
-                             llvm::SmallVectorImpl<char> &) = 0;
+                             llvm::raw_svector_ostream &) = 0;
   virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
-                             llvm::SmallVectorImpl<char> &) = 0;
+                             llvm::raw_svector_ostream &) = 0;
 
   void mangleGlobalBlock(const BlockDecl *BD,
-                         llvm::SmallVectorImpl<char> &Res);
+                         llvm::raw_svector_ostream &Out);
   void mangleCtorBlock(const CXXConstructorDecl *CD, CXXCtorType CT,
-                       const BlockDecl *BD, llvm::SmallVectorImpl<char> &Res);
+                       const BlockDecl *BD, llvm::raw_svector_ostream &Out);
   void mangleDtorBlock(const CXXDestructorDecl *CD, CXXDtorType DT,
-                       const BlockDecl *BD, llvm::SmallVectorImpl<char> &Res);
+                       const BlockDecl *BD, llvm::raw_svector_ostream &Out);
   void mangleBlock(const DeclContext *DC, const BlockDecl *BD,
-                   llvm::SmallVectorImpl<char> &Res);
+                   llvm::raw_svector_ostream &Out);
   // Do the right thing.
-  void mangleBlock(const BlockDecl *BD, llvm::SmallVectorImpl<char> &Res);
+  void mangleBlock(const BlockDecl *BD, llvm::raw_svector_ostream &Out);
 
   void mangleObjCMethodName(const ObjCMethodDecl *MD,
                             llvm::SmallVectorImpl<char> &);
diff --git a/lib/AST/ItaniumMangle.cpp b/lib/AST/ItaniumMangle.cpp
index 6608571..1a3bf65 100644
--- a/lib/AST/ItaniumMangle.cpp
+++ b/lib/AST/ItaniumMangle.cpp
@@ -91,7 +91,7 @@ public:
   /// @{
 
   bool shouldMangleDeclName(const NamedDecl *D);
-  void mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &);
+  void mangleName(const NamedDecl *D, llvm::raw_svector_ostream &);
   void mangleThunk(const CXXMethodDecl *MD,
                    const ThunkInfo &Thunk,
                    llvm::SmallVectorImpl<char> &);
@@ -110,9 +110,9 @@ public:
   void mangleCXXRTTI(QualType T, llvm::SmallVectorImpl<char> &);
   void mangleCXXRTTIName(QualType T, llvm::SmallVectorImpl<char> &);
   void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
-                     llvm::SmallVectorImpl<char> &);
+                     llvm::raw_svector_ostream &);
   void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
-                     llvm::SmallVectorImpl<char> &);
+                     llvm::raw_svector_ostream &);
 
   void mangleItaniumGuardVariable(const VarDecl *D,
                                   llvm::SmallVectorImpl<char> &);
@@ -136,7 +136,7 @@ public:
 /// CXXNameMangler - Manage the mangling of a single name.
 class CXXNameMangler {
   ItaniumMangleContext &Context;
-  llvm::raw_svector_ostream Out;
+  llvm::raw_svector_ostream &Out;
 
   const CXXMethodDecl *Structor;
   unsigned StructorType;
@@ -149,15 +149,15 @@ class CXXNameMangler {
   ASTContext &getASTContext() const { return Context.getASTContext(); }
 
 public:
-  CXXNameMangler(ItaniumMangleContext &C, llvm::SmallVectorImpl<char> &Res)
-    : Context(C), Out(Res), Structor(0), StructorType(0), SeqID(0) { }
-  CXXNameMangler(ItaniumMangleContext &C, llvm::SmallVectorImpl<char> &Res,
+  CXXNameMangler(ItaniumMangleContext &C, llvm::raw_svector_ostream &Out_)
+    : Context(C), Out(Out_), Structor(0), StructorType(0), SeqID(0) { }
+  CXXNameMangler(ItaniumMangleContext &C, llvm::raw_svector_ostream &Out_,
                  const CXXConstructorDecl *D, CXXCtorType Type)
-    : Context(C), Out(Res), Structor(getStructor(D)), StructorType(Type),
+    : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type),
     SeqID(0) { }
-  CXXNameMangler(ItaniumMangleContext &C, llvm::SmallVectorImpl<char> &Res,
+  CXXNameMangler(ItaniumMangleContext &C, llvm::raw_svector_ostream &Out_,
                  const CXXDestructorDecl *D, CXXDtorType Type)
-    : Context(C), Out(Res), Structor(getStructor(D)), StructorType(Type),
+    : Context(C), Out(Out_), Structor(getStructor(D)), StructorType(Type),
     SeqID(0) { }
 
 #if MANGLE_CHECKER
@@ -909,7 +909,9 @@ void CXXNameMangler::manglePrefix(const DeclContext *DC, bool NoFunction) {
   if (const BlockDecl *Block = dyn_cast<BlockDecl>(DC)) {
     manglePrefix(DC->getParent(), NoFunction);    
     llvm::SmallString<64> Name;
-    Context.mangleBlock(Block, Name);
+    llvm::raw_svector_ostream NameStream(Name);
+    Context.mangleBlock(Block, NameStream);
+    NameStream.flush();
     Out << Name.size() << Name;
     return;
   }
@@ -2535,7 +2537,7 @@ void CXXNameMangler::addSubstitution(uintptr_t Ptr) {
 /// emit the identifier of the declaration (\c D->getIdentifier()) as its
 /// name.
 void ItaniumMangleContext::mangleName(const NamedDecl *D,
-                                      llvm::SmallVectorImpl<char> &Res) {
+                                      llvm::raw_svector_ostream &Out) {
   assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
           "Invalid mangleName() call, argument is not a variable or function!");
   assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) &&
@@ -2545,21 +2547,21 @@ void ItaniumMangleContext::mangleName(const NamedDecl *D,
                                  getASTContext().getSourceManager(),
                                  "Mangling declaration");
 
-  CXXNameMangler Mangler(*this, Res);
+  CXXNameMangler Mangler(*this, Out);
   return Mangler.mangle(D);
 }
 
 void ItaniumMangleContext::mangleCXXCtor(const CXXConstructorDecl *D,
                                          CXXCtorType Type,
-                                         llvm::SmallVectorImpl<char> &Res) {
-  CXXNameMangler Mangler(*this, Res, D, Type);
+                                         llvm::raw_svector_ostream &Out) {
+  CXXNameMangler Mangler(*this, Out, D, Type);
   Mangler.mangle(D);
 }
 
 void ItaniumMangleContext::mangleCXXDtor(const CXXDestructorDecl *D,
                                          CXXDtorType Type,
-                                         llvm::SmallVectorImpl<char> &Res) {
-  CXXNameMangler Mangler(*this, Res, D, Type);
+                                         llvm::raw_svector_ostream &Out) {
+  CXXNameMangler Mangler(*this, Out, D, Type);
   Mangler.mangle(D);
 }
 
@@ -2575,8 +2577,8 @@ void ItaniumMangleContext::mangleThunk(const CXXMethodDecl *MD,
   
   assert(!isa<CXXDestructorDecl>(MD) &&
          "Use mangleCXXDtor for destructor decls!");
-  
-  CXXNameMangler Mangler(*this, Res);
+  llvm::raw_svector_ostream Out(Res);
+  CXXNameMangler Mangler(*this, Out);
   Mangler.getStream() << "_ZT";
   if (!Thunk.Return.isEmpty())
     Mangler.getStream() << 'c';
@@ -2600,7 +2602,8 @@ ItaniumMangleContext::mangleCXXDtorThunk(const CXXDestructorDecl *DD,
   //  <special-name> ::= T <call-offset> <base encoding>
   //                      # base is the nominal target function of thunk
   
-  CXXNameMangler Mangler(*this, Res, DD, Type);
+  llvm::raw_svector_ostream Out(Res);
+  CXXNameMangler Mangler(*this, Out, DD, Type);
   Mangler.getStream() << "_ZT";
 
   // Mangle the 'this' pointer adjustment.
@@ -2616,7 +2619,8 @@ void ItaniumMangleContext::mangleItaniumGuardVariable(const VarDecl *D,
                                              llvm::SmallVectorImpl<char> &Res) {
   //  <special-name> ::= GV <object name>       # Guard variable for one-time
   //                                            # initialization
-  CXXNameMangler Mangler(*this, Res);
+  llvm::raw_svector_ostream Out(Res);
+  CXXNameMangler Mangler(*this, Out);
   Mangler.getStream() << "_ZGV";
   Mangler.mangleName(D);
 }
@@ -2625,7 +2629,8 @@ void ItaniumMangleContext::mangleReferenceTemporary(const VarDecl *D,
                                              llvm::SmallVectorImpl<char> &Res) {
   // We match the GCC mangling here.
   //  <special-name> ::= GR <object name>
-  CXXNameMangler Mangler(*this, Res);
+  llvm::raw_svector_ostream Out(Res);
+  CXXNameMangler Mangler(*this, Out);
   Mangler.getStream() << "_ZGR";
   Mangler.mangleName(D);
 }
@@ -2633,7 +2638,8 @@ void ItaniumMangleContext::mangleReferenceTemporary(const VarDecl *D,
 void ItaniumMangleContext::mangleCXXVTable(const CXXRecordDecl *RD,
                                            llvm::SmallVectorImpl<char> &Res) {
   // <special-name> ::= TV <type>  # virtual table
-  CXXNameMangler Mangler(*this, Res);
+  llvm::raw_svector_ostream Out(Res);
+  CXXNameMangler Mangler(*this, Out);
   Mangler.getStream() << "_ZTV";
   Mangler.mangleNameOrStandardSubstitution(RD);
 }
@@ -2641,7 +2647,8 @@ void ItaniumMangleContext::mangleCXXVTable(const CXXRecordDecl *RD,
 void ItaniumMangleContext::mangleCXXVTT(const CXXRecordDecl *RD,
                                         llvm::SmallVectorImpl<char> &Res) {
   // <special-name> ::= TT <type>  # VTT structure
-  CXXNameMangler Mangler(*this, Res);
+  llvm::raw_svector_ostream Out(Res);
+  CXXNameMangler Mangler(*this, Out);
   Mangler.getStream() << "_ZTT";
   Mangler.mangleNameOrStandardSubstitution(RD);
 }
@@ -2651,7 +2658,8 @@ void ItaniumMangleContext::mangleCXXCtorVTable(const CXXRecordDecl *RD,
                                                const CXXRecordDecl *Type,
                                              llvm::SmallVectorImpl<char> &Res) {
   // <special-name> ::= TC <type> <offset number> _ <base type>
-  CXXNameMangler Mangler(*this, Res);
+  llvm::raw_svector_ostream Out(Res);
+  CXXNameMangler Mangler(*this, Out);
   Mangler.getStream() << "_ZTC";
   Mangler.mangleNameOrStandardSubstitution(RD);
   Mangler.getStream() << Offset;
@@ -2663,7 +2671,8 @@ void ItaniumMangleContext::mangleCXXRTTI(QualType Ty,
                                          llvm::SmallVectorImpl<char> &Res) {
   // <special-name> ::= TI <type>  # typeinfo structure
   assert(!Ty.hasQualifiers() && "RTTI info cannot have top-level qualifiers");
-  CXXNameMangler Mangler(*this, Res);
+  llvm::raw_svector_ostream Out(Res);
+  CXXNameMangler Mangler(*this, Out);
   Mangler.getStream() << "_ZTI";
   Mangler.mangleType(Ty);
 }
@@ -2671,7 +2680,8 @@ void ItaniumMangleContext::mangleCXXRTTI(QualType Ty,
 void ItaniumMangleContext::mangleCXXRTTIName(QualType Ty,
                                              llvm::SmallVectorImpl<char> &Res) {
   // <special-name> ::= TS <type>  # typeinfo name (null terminated byte string)
-  CXXNameMangler Mangler(*this, Res);
+  llvm::raw_svector_ostream Out(Res);
+  CXXNameMangler Mangler(*this, Out);
   Mangler.getStream() << "_ZTS";
   Mangler.mangleType(Ty);
 }
diff --git a/lib/AST/Mangle.cpp b/lib/AST/Mangle.cpp
index 83d9ed6..51d4be3 100644
--- a/lib/AST/Mangle.cpp
+++ b/lib/AST/Mangle.cpp
@@ -39,8 +39,7 @@ namespace {
 static void mangleFunctionBlock(MangleContext &Context,
                                 llvm::StringRef Outer,
                                 const BlockDecl *BD,
-                                llvm::SmallVectorImpl<char> &Res) {
-  llvm::raw_svector_ostream Out(Res);
+                                llvm::raw_svector_ostream &Out) {
   Out << "__" << Outer << "_block_invoke_" << Context.getBlockId(BD, true);
 }
 
@@ -56,31 +55,34 @@ static void checkMangleDC(const DeclContext *DC, const BlockDecl *BD) {
 }
 
 void MangleContext::mangleGlobalBlock(const BlockDecl *BD,
-                                      llvm::SmallVectorImpl<char> &Res) {
-  llvm::raw_svector_ostream Out(Res);
+                                      llvm::raw_svector_ostream &Out) {
   Out << "__block_global_" << getBlockId(BD, false);
 }
 
 void MangleContext::mangleCtorBlock(const CXXConstructorDecl *CD,
                                     CXXCtorType CT, const BlockDecl *BD,
-                                    llvm::SmallVectorImpl<char> &Res) {
+                                    llvm::raw_svector_ostream &ResStream) {
   checkMangleDC(CD, BD);
   llvm::SmallString<64> Buffer;
-  mangleCXXCtor(CD, CT, Buffer);
-  mangleFunctionBlock(*this, Buffer, BD, Res);
+  llvm::raw_svector_ostream Out(Buffer);
+  mangleCXXCtor(CD, CT, Out);
+  Out.flush();
+  mangleFunctionBlock(*this, Buffer, BD, ResStream);
 }
 
 void MangleContext::mangleDtorBlock(const CXXDestructorDecl *DD,
                                     CXXDtorType DT, const BlockDecl *BD,
-                                    llvm::SmallVectorImpl<char> &Res) {
+                                    llvm::raw_svector_ostream &ResStream) {
   checkMangleDC(DD, BD);
   llvm::SmallString<64> Buffer;
-  mangleCXXDtor(DD, DT, Buffer);
-  mangleFunctionBlock(*this, Buffer, BD, Res);
+  llvm::raw_svector_ostream Out(Buffer);
+  mangleCXXDtor(DD, DT, Out);
+  Out.flush();
+  mangleFunctionBlock(*this, Buffer, BD, ResStream);
 }
 
 void MangleContext::mangleBlock(const DeclContext *DC, const BlockDecl *BD,
-                                llvm::SmallVectorImpl<char> &Res) {
+                                llvm::raw_svector_ostream &Out) {
   assert(!isa<CXXConstructorDecl>(DC) && !isa<CXXDestructorDecl>(DC));
   checkMangleDC(DC, BD);
 
@@ -97,11 +99,12 @@ void MangleContext::mangleBlock(const DeclContext *DC, const BlockDecl *BD,
       // Itanium C++ ABI object. What should we do now? Right now, I'm just
       // calling the mangleName() method on the MangleContext; is there a
       // better way?
-      mangleName(ND, Buffer);
+      llvm::raw_svector_ostream Out(Buffer);
+      mangleName(ND, Out);
     }
   }
 
-  mangleFunctionBlock(*this, Buffer, BD, Res);
+  mangleFunctionBlock(*this, Buffer, BD, Out);
 }
 
 void MangleContext::mangleObjCMethodName(const ObjCMethodDecl *MD,
@@ -121,12 +124,12 @@ void MangleContext::mangleObjCMethodName(const ObjCMethodDecl *MD,
 }
 
 void MangleContext::mangleBlock(const BlockDecl *BD,
-                                llvm::SmallVectorImpl<char> &Res) {
+                                llvm::raw_svector_ostream &Out) {
   const DeclContext *DC = BD->getDeclContext();
   while (isa<BlockDecl>(DC) || isa<EnumDecl>(DC))
     DC = DC->getParent();
   if (DC->isFunctionOrMethod())
-    mangleBlock(DC, BD, Res);
+    mangleBlock(DC, BD, Out);
   else
-    mangleGlobalBlock(BD, Res);
+    mangleGlobalBlock(BD, Out);
 }
diff --git a/lib/AST/MicrosoftMangle.cpp b/lib/AST/MicrosoftMangle.cpp
index a8f9ed2..a2300ee 100644
--- a/lib/AST/MicrosoftMangle.cpp
+++ b/lib/AST/MicrosoftMangle.cpp
@@ -29,13 +29,13 @@ namespace {
 /// Microsoft Visual C++ ABI.
 class MicrosoftCXXNameMangler {
   MangleContext &Context;
-  llvm::raw_svector_ostream Out;
+  llvm::raw_svector_ostream &Out;
 
   ASTContext &getASTContext() const { return Context.getASTContext(); }
 
 public:
-  MicrosoftCXXNameMangler(MangleContext &C, llvm::SmallVectorImpl<char> &Res)
-  : Context(C), Out(Res) { }
+  MicrosoftCXXNameMangler(MangleContext &C, llvm::raw_svector_ostream &Out_)
+  : Context(C), Out(Out_) { }
 
   void mangle(const NamedDecl *D, llvm::StringRef Prefix = "?");
   void mangleName(const NamedDecl *ND);
@@ -80,7 +80,7 @@ public:
   MicrosoftMangleContext(ASTContext &Context,
                          Diagnostic &Diags) : MangleContext(Context, Diags) { }
   virtual bool shouldMangleDeclName(const NamedDecl *D);
-  virtual void mangleName(const NamedDecl *D, llvm::SmallVectorImpl<char> &);
+  virtual void mangleName(const NamedDecl *D, llvm::raw_svector_ostream &Out);
   virtual void mangleThunk(const CXXMethodDecl *MD,
                            const ThunkInfo &Thunk,
                            llvm::SmallVectorImpl<char> &);
@@ -97,9 +97,9 @@ public:
   virtual void mangleCXXRTTI(QualType T, llvm::SmallVectorImpl<char> &);
   virtual void mangleCXXRTTIName(QualType T, llvm::SmallVectorImpl<char> &);
   virtual void mangleCXXCtor(const CXXConstructorDecl *D, CXXCtorType Type,
-                             llvm::SmallVectorImpl<char> &);
+                             llvm::raw_svector_ostream &);
   virtual void mangleCXXDtor(const CXXDestructorDecl *D, CXXDtorType Type,
-                             llvm::SmallVectorImpl<char> &);
+                             llvm::raw_svector_ostream &);
   virtual void mangleReferenceTemporary(const clang::VarDecl *,
                                         llvm::SmallVectorImpl<char> &);
 };
@@ -380,9 +380,8 @@ void MicrosoftCXXNameMangler::manglePostfix(const DeclContext *DC,
     return;
 
   if (const BlockDecl *BD = dyn_cast<BlockDecl>(DC)) {
-    llvm::SmallString<64> Name;
-    Context.mangleBlock(BD, Name);
-    Out << Name << '@';
+    Context.mangleBlock(BD, Out);
+    Out << '@';
     return manglePostfix(DC->getParent(), NoFunction);
   }
 
@@ -1123,7 +1122,7 @@ void MicrosoftCXXNameMangler::mangleType(const DecltypeType *T) {
 }
 
 void MicrosoftMangleContext::mangleName(const NamedDecl *D,
-                                        llvm::SmallVectorImpl<char> &Name) {
+                                        llvm::raw_svector_ostream &Out) {
   assert((isa<FunctionDecl>(D) || isa<VarDecl>(D)) &&
          "Invalid mangleName() call, argument is not a variable or function!");
   assert(!isa<CXXConstructorDecl>(D) && !isa<CXXDestructorDecl>(D) &&
@@ -1133,7 +1132,7 @@ void MicrosoftMangleContext::mangleName(const NamedDecl *D,
                                  getASTContext().getSourceManager(),
                                  "Mangling declaration");
 
-  MicrosoftCXXNameMangler Mangler(*this, Name);
+  MicrosoftCXXNameMangler Mangler(*this, Out);
   return Mangler.mangle(D);
 }
 void MicrosoftMangleContext::mangleThunk(const CXXMethodDecl *MD,
@@ -1171,12 +1170,12 @@ void MicrosoftMangleContext::mangleCXXRTTIName(QualType T,
 }
 void MicrosoftMangleContext::mangleCXXCtor(const CXXConstructorDecl *D,
                                            CXXCtorType Type,
-                                           llvm::SmallVectorImpl<char> &) {
+                                           llvm::raw_svector_ostream &) {
   assert(false && "Can't yet mangle constructors!");
 }
 void MicrosoftMangleContext::mangleCXXDtor(const CXXDestructorDecl *D,
                                            CXXDtorType Type,
-                                           llvm::SmallVectorImpl<char> &) {
+                                           llvm::raw_svector_ostream &) {
   assert(false && "Can't yet mangle destructors!");
 }
 void MicrosoftMangleContext::mangleReferenceTemporary(const clang::VarDecl *,
diff --git a/lib/CodeGen/CodeGenModule.cpp b/lib/CodeGen/CodeGenModule.cpp
index 56bc31a..2a057a1 100644
--- a/lib/CodeGen/CodeGenModule.cpp
+++ b/lib/CodeGen/CodeGenModule.cpp
@@ -37,6 +37,7 @@
 #include "llvm/Intrinsics.h"
 #include "llvm/LLVMContext.h"
 #include "llvm/ADT/Triple.h"
+#include "llvm/Target/Mangler.h"
 #include "llvm/Target/TargetData.h"
 #include "llvm/Support/CallSite.h"
 #include "llvm/Support/ErrorHandling.h"
@@ -263,16 +264,18 @@ llvm::StringRef CodeGenModule::getMangledName(GlobalDecl GD) {
   }
   
   llvm::SmallString<256> Buffer;
+  llvm::raw_svector_ostream Out(Buffer);
   if (const CXXConstructorDecl *D = dyn_cast<CXXConstructorDecl>(ND))
-    getCXXABI().getMangleContext().mangleCXXCtor(D, GD.getCtorType(), Buffer);
+    getCXXABI().getMangleContext().mangleCXXCtor(D, GD.getCtorType(), Out);
   else if (const CXXDestructorDecl *D = dyn_cast<CXXDestructorDecl>(ND))
-    getCXXABI().getMangleContext().mangleCXXDtor(D, GD.getDtorType(), Buffer);
+    getCXXABI().getMangleContext().mangleCXXDtor(D, GD.getDtorType(), Out);
   else if (const BlockDecl *BD = dyn_cast<BlockDecl>(ND))
-    getCXXABI().getMangleContext().mangleBlock(BD, Buffer);
+    getCXXABI().getMangleContext().mangleBlock(BD, Out);
   else
-    getCXXABI().getMangleContext().mangleName(ND, Buffer);
+    getCXXABI().getMangleContext().mangleName(ND, Out);
 
   // Allocate space for the mangled name.
+  Out.flush();
   size_t Length = Buffer.size();
   char *Name = MangledNamesAllocator.Allocate<char>(Length);
   std::copy(Buffer.begin(), Buffer.end(), Name);
@@ -286,14 +289,15 @@ void CodeGenModule::getBlockMangledName(GlobalDecl GD, MangleBuffer &Buffer,
                                         const BlockDecl *BD) {
   MangleContext &MangleCtx = getCXXABI().getMangleContext();
   const Decl *D = GD.getDecl();
+  llvm::raw_svector_ostream Out(Buffer.getBuffer());
   if (D == 0)
-    MangleCtx.mangleGlobalBlock(BD, Buffer.getBuffer());
+    MangleCtx.mangleGlobalBlock(BD, Out);
   else if (const CXXConstructorDecl *CD = dyn_cast<CXXConstructorDecl>(D))
-    MangleCtx.mangleCtorBlock(CD, GD.getCtorType(), BD, Buffer.getBuffer());
+    MangleCtx.mangleCtorBlock(CD, GD.getCtorType(), BD, Out);
   else if (const CXXDestructorDecl *DD = dyn_cast<CXXDestructorDecl>(D))
-    MangleCtx.mangleDtorBlock(DD, GD.getDtorType(), BD, Buffer.getBuffer());
+    MangleCtx.mangleDtorBlock(DD, GD.getDtorType(), BD, Out);
   else
-    MangleCtx.mangleBlock(cast<DeclContext>(D), BD, Buffer.getBuffer());
+    MangleCtx.mangleBlock(cast<DeclContext>(D), BD, Out);
 }
 
 llvm::GlobalValue *CodeGenModule::GetGlobalValue(llvm::StringRef Name) {
