pacxx created this revision. pacxx added reviewers: rnk, rsmith. Herald added a subscriber: cfe-commits.
The ASTContext is only used to create a Mangling Context and forwards ownership to everyone who requests a ManglingContext. The problem fixed by this commit is located in the handling of the __FUNCDNAME__ generation. Every time a __FUNCDNAME__ expression is handled a new ManglingContext is created. The MC and its cached manglings are thrown away every time the __FUNCDNAME__ was handled which results in wrong numbering of lambda expressions in name manglings (every lambda gets id 0) what again leads to inconsistencies between __FUNCDNAME__ and the name manglings in the generated code. Repository: rC Clang https://reviews.llvm.org/D43547 Files: include/clang/AST/ASTContext.h lib/AST/ASTContext.cpp lib/Index/CodegenNameGenerator.cpp 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<MangleContext> 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<NamedDecl>(D); ASTContext &Ctx = ND->getASTContext(); - std::unique_ptr<MangleContext> M(Ctx.createMangleContext()); std::vector<std::string> Manglings; 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: 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<const ObjCIvarDecl*> &Ivars) const; @@ -2828,6 +2829,7 @@ std::unique_ptr<ParentMapOtherNodes> OtherParents; std::unique_ptr<VTableContextBase> VTContext; + std::unique_ptr<MangleContext> MContext; void ReleaseDeclContextMaps(); void ReleaseParentMapEntries();
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<MangleContext> 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<NamedDecl>(D); ASTContext &Ctx = ND->getASTContext(); - std::unique_ptr<MangleContext> M(Ctx.createMangleContext()); std::vector<std::string> Manglings; 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: 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<const ObjCIvarDecl*> &Ivars) const; @@ -2828,6 +2829,7 @@ std::unique_ptr<ParentMapOtherNodes> OtherParents; std::unique_ptr<VTableContextBase> VTContext; + std::unique_ptr<MangleContext> MContext; void ReleaseDeclContextMaps(); void ReleaseParentMapEntries();
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits