[CodeGen] Use the mangle context owned by CodeGenModule to correctly
mangle types of lambda objects captured by a block instead of creating a
new mangle context everytime a captured field type is mangled.
This fixes a bug in IRGen's block helper merging code that was
introduced in r339438 where two blocks capturing two distinct lambdas
would end up sharing helper functions and the block descriptor. This
happened because the ID number used to distinguish lambdas defined
in the same context is reset everytime a mangled context is created.
rdar://problem/45314494
llvm-svn: 344833
diff --git a/clang/lib/CodeGen/CGBlocks.cpp b/clang/lib/CodeGen/CGBlocks.cpp
index c2e5f1a..b7ad920 100644
--- a/clang/lib/CodeGen/CGBlocks.cpp
+++ b/clang/lib/CodeGen/CGBlocks.cpp
@@ -1817,8 +1817,6 @@
CodeGenModule &CGM) {
std::string Str;
ASTContext &Ctx = CGM.getContext();
- std::unique_ptr<ItaniumMangleContext> MC(
- ItaniumMangleContext::create(Ctx, Ctx.getDiagnostics()));
const BlockDecl::Capture &CI = *E.CI;
QualType CaptureTy = CI.getVariable()->getType();
@@ -1844,7 +1842,7 @@
Str += "c";
SmallString<256> TyStr;
llvm::raw_svector_ostream Out(TyStr);
- MC->mangleTypeName(CaptureTy, Out);
+ CGM.getCXXABI().getMangleContext().mangleTypeName(CaptureTy, Out);
Str += llvm::to_string(TyStr.size()) + TyStr.c_str();
break;
}