Index: clang/include/clang/AST/ASTContext.h =================================================================== --- clang/include/clang/AST/ASTContext.h +++ clang/include/clang/AST/ASTContext.h @@ -407,7 +407,7 @@ /// \brief Mapping from each declaration context to its corresponding /// mangling numbering context (used for constructs like lambdas which /// need to be consistently numbered for the mangler). - llvm::DenseMap + llvm::DenseMap> MangleNumberingContexts; /// \brief Side-table of mangling numbers for declarations which rarely @@ -2470,7 +2470,7 @@ /// DeclContext. MangleNumberingContext &getManglingNumberContext(const DeclContext *DC); - MangleNumberingContext *createMangleNumberingContext() const; + std::unique_ptr createMangleNumberingContext() const; /// \brief Used by ParmVarDecl to store on the side the /// index of the parameter when it exceeds the size of the normal bitfield. Index: clang/include/clang/AST/MangleNumberingContext.h =================================================================== --- clang/include/clang/AST/MangleNumberingContext.h +++ clang/include/clang/AST/MangleNumberingContext.h @@ -29,7 +29,7 @@ /// \brief Keeps track of the mangled names of lambda expressions and block /// literals within a particular context. -class MangleNumberingContext : public RefCountedBase { +class MangleNumberingContext { public: virtual ~MangleNumberingContext() {} Index: clang/include/clang/Sema/Sema.h =================================================================== --- clang/include/clang/Sema/Sema.h +++ clang/include/clang/Sema/Sema.h @@ -876,7 +876,7 @@ /// /// This mangling information is allocated lazily, since most contexts /// do not have lambda expressions or block literals. - IntrusiveRefCntPtr MangleNumbering; + std::unique_ptr MangleNumbering; /// \brief If we are processing a decltype type, a set of call expressions /// for which we have deferred checking the completeness of the return type. Index: clang/lib/AST/ASTContext.cpp =================================================================== --- clang/lib/AST/ASTContext.cpp +++ clang/lib/AST/ASTContext.cpp @@ -794,8 +794,6 @@ for (const auto &Value : ModuleInitializers) Value.second->~PerModuleInitializers(); - - llvm::DeleteContainerSeconds(MangleNumberingContexts); } void ASTContext::ReleaseParentMapEntries() { @@ -8982,13 +8980,14 @@ MangleNumberingContext & ASTContext::getManglingNumberContext(const DeclContext *DC) { assert(LangOpts.CPlusPlus); // We don't need mangling numbers for plain C. - MangleNumberingContext *&MCtx = MangleNumberingContexts[DC]; + std::unique_ptr &MCtx = MangleNumberingContexts[DC]; if (!MCtx) MCtx = createMangleNumberingContext(); return *MCtx; } -MangleNumberingContext *ASTContext::createMangleNumberingContext() const { +std::unique_ptr +ASTContext::createMangleNumberingContext() const { return ABI->createMangleNumberingContext(); } Index: clang/lib/AST/CXXABI.h =================================================================== --- clang/lib/AST/CXXABI.h +++ clang/lib/AST/CXXABI.h @@ -43,7 +43,8 @@ virtual bool isNearlyEmpty(const CXXRecordDecl *RD) const = 0; /// Returns a new mangling number context for this C++ ABI. - virtual MangleNumberingContext *createMangleNumberingContext() const = 0; + virtual std::unique_ptr + createMangleNumberingContext() const = 0; /// Adds a mapping from class to copy constructor for this C++ ABI. virtual void addCopyConstructorForExceptionObject(CXXRecordDecl *, Index: clang/lib/AST/ItaniumCXXABI.cpp =================================================================== --- clang/lib/AST/ItaniumCXXABI.cpp +++ clang/lib/AST/ItaniumCXXABI.cpp @@ -163,8 +163,9 @@ return nullptr; } - MangleNumberingContext *createMangleNumberingContext() const override { - return new ItaniumNumberingContext(); + std::unique_ptr + createMangleNumberingContext() const override { + return llvm::make_unique(); } }; } Index: clang/lib/AST/MicrosoftCXXABI.cpp =================================================================== --- clang/lib/AST/MicrosoftCXXABI.cpp +++ clang/lib/AST/MicrosoftCXXABI.cpp @@ -143,8 +143,9 @@ const_cast(TD->getCanonicalDecl())); } - MangleNumberingContext *createMangleNumberingContext() const override { - return new MicrosoftNumberingContext(); + std::unique_ptr + createMangleNumberingContext() const override { + return llvm::make_unique(); } }; }