Index: include/clang/AST/ASTContext.h =================================================================== --- include/clang/AST/ASTContext.h +++ include/clang/AST/ASTContext.h @@ -2158,6 +2158,7 @@ VTableContextBase *getVTableContext(); MangleContext *createMangleContext(); + MangleContext &getMangleContext(); void DeepCollectObjCIvars(const ObjCInterfaceDecl *OI, bool leafClass, SmallVectorImpl &Ivars) const; @@ -2828,6 +2829,7 @@ std::unique_ptr OtherParents; std::unique_ptr VTContext; + std::unique_ptr MContext; void ReleaseDeclContextMaps(); void ReleaseParentMapEntries(); Index: lib/AST/ASTContext.cpp =================================================================== --- lib/AST/ASTContext.cpp +++ lib/AST/ASTContext.cpp @@ -9570,6 +9570,12 @@ llvm_unreachable("Unsupported ABI"); } +MangleContext &ASTContext::getMangleContext() { + if (!MContext) + MContext.reset(createMangleContext()); + return *MContext.get(); +} + CXXABI::~CXXABI() = default; size_t ASTContext::getSideTableAllocatedMemory() const { Index: lib/Index/CodegenNameGenerator.cpp =================================================================== --- lib/Index/CodegenNameGenerator.cpp +++ lib/Index/CodegenNameGenerator.cpp @@ -26,11 +26,11 @@ using namespace clang::index; struct CodegenNameGenerator::Implementation { - std::unique_ptr MC; + MangleContext& MC; llvm::DataLayout DL; Implementation(ASTContext &Ctx) - : MC(Ctx.createMangleContext()), + : MC(Ctx.getMangleContext()), DL(Ctx.getTargetInfo().getDataLayout()) {} bool writeName(const Decl *D, raw_ostream &OS) { @@ -106,7 +106,6 @@ const NamedDecl *ND = cast(D); ASTContext &Ctx = ND->getASTContext(); - std::unique_ptr M(Ctx.createMangleContext()); std::vector Manglings;