diff --git a/clang/include/clang/AST/Mangle.h b/clang/include/clang/AST/Mangle.h --- a/clang/include/clang/AST/Mangle.h +++ b/clang/include/clang/AST/Mangle.h @@ -123,7 +123,10 @@ void mangleBlock(const DeclContext *DC, const BlockDecl *BD, raw_ostream &Out); - void mangleObjCMethodNameWithoutSize(const ObjCMethodDecl *MD, raw_ostream &); + void mangleObjCMethodNameWithoutSize(const ObjCMethodDecl *MD, + raw_ostream &OS, + bool includePrefixByte = true, + bool includeCategoryNamespace = true); void mangleObjCMethodName(const ObjCMethodDecl *MD, raw_ostream &); virtual void mangleStaticGuardVariable(const VarDecl *D, raw_ostream &) = 0; diff --git a/clang/lib/AST/Mangle.cpp b/clang/lib/AST/Mangle.cpp --- a/clang/lib/AST/Mangle.cpp +++ b/clang/lib/AST/Mangle.cpp @@ -304,17 +304,23 @@ mangleFunctionBlock(*this, Buffer, BD, Out); } -void MangleContext::mangleObjCMethodNameWithoutSize(const ObjCMethodDecl *MD, - raw_ostream &OS) { - const ObjCContainerDecl *CD = - dyn_cast(MD->getDeclContext()); - assert (CD && "Missing container decl in GetNameForMethod"); +void MangleContext::mangleObjCMethodNameWithoutSize( + const ObjCMethodDecl *MD, raw_ostream &OS, bool includePrefixByte, + bool includeCategoryNamespace) { + // \01+[ContainerName(CategoryName) SelectorName] + if (includePrefixByte) { + OS << '\01'; + } OS << (MD->isInstanceMethod() ? '-' : '+') << '['; - if (const ObjCCategoryImplDecl *CID = dyn_cast(CD)) { + if (auto *CID = dyn_cast(MD->getDeclContext())) { OS << CID->getClassInterface()->getName(); - OS << '(' << *CID << ')'; - } else { + if (includeCategoryNamespace) { + OS << '(' << *CID << ')'; + } + } else if (auto *CD = dyn_cast(MD->getDeclContext())) { OS << CD->getName(); + } else { + assert(false && "Unexpected ObjC method decl context"); } OS << ' '; MD->getSelector().print(OS); @@ -326,7 +332,8 @@ SmallString<64> Name; llvm::raw_svector_ostream OS(Name); - mangleObjCMethodNameWithoutSize(MD, OS); + mangleObjCMethodNameWithoutSize(MD, OS, /*includePrefixByte=*/false, + /*includeCategoryNamespace=*/true); Out << OS.str().size() << OS.str(); } @@ -352,7 +359,8 @@ if (writeFuncOrVarName(VD, FrontendBufOS)) return true; } else if (auto *MD = dyn_cast(D)) { - MC->mangleObjCMethodNameWithoutSize(MD, OS); + MC->mangleObjCMethodNameWithoutSize(MD, OS, /*includePrefixByte=*/false, + /*includeCategoryNamespace=*/true); return false; } else if (auto *ID = dyn_cast(D)) { writeObjCClassName(ID, FrontendBufOS); diff --git a/clang/lib/CodeGen/CGObjCMac.cpp b/clang/lib/CodeGen/CGObjCMac.cpp --- a/clang/lib/CodeGen/CGObjCMac.cpp +++ b/clang/lib/CodeGen/CGObjCMac.cpp @@ -20,6 +20,7 @@ #include "clang/AST/Attr.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclObjC.h" +#include "clang/AST/Mangle.h" #include "clang/AST/RecordLayout.h" #include "clang/AST/StmtObjC.h" #include "clang/Basic/CodeGenOptions.h" @@ -924,13 +925,6 @@ llvm::StringMap NSConstantStringMap; - /// GetNameForMethod - Return a name for the given method. - /// \param[out] NameOut - The return value. - void GetNameForMethod(const ObjCMethodDecl *OMD, - const ObjCContainerDecl *CD, - SmallVectorImpl &NameOut, - bool ignoreCategoryNamespace = false); - /// GetMethodVarName - Return a unique constant for the given /// selector's name. The return value has type char *. llvm::Constant *GetMethodVarName(Selector Sel); @@ -4008,7 +4002,10 @@ Method = GenerateDirectMethod(OMD, CD); } else { SmallString<256> Name; - GetNameForMethod(OMD, CD, Name); + llvm::raw_svector_ostream OS(Name); + const auto &MC = CGM.getContext().createMangleContext(); + MC->mangleObjCMethodNameWithoutSize(OMD, OS, /*includePrefixByte=*/true, + /*includeCategoryNamespace=*/true); CodeGenTypes &Types = CGM.getTypes(); llvm::FunctionType *MethodTy = @@ -4061,7 +4058,10 @@ I->second = Fn; } else { SmallString<256> Name; - GetNameForMethod(OMD, CD, Name, /*ignoreCategoryNamespace*/ true); + llvm::raw_svector_ostream OS(Name); + const auto &MC = CGM.getContext().createMangleContext(); + MC->mangleObjCMethodNameWithoutSize(OMD, OS, /*includePrefixByte=*/true, + /*includeCategoryNamespace=*/false); Fn = llvm::Function::Create(MethodTy, llvm::GlobalValue::ExternalLinkage, Name.str(), &CGM.getModule()); @@ -5715,21 +5715,6 @@ return GetPropertyName(&CGM.getContext().Idents.get(TypeStr)); } -void CGObjCCommonMac::GetNameForMethod(const ObjCMethodDecl *D, - const ObjCContainerDecl *CD, - SmallVectorImpl &Name, - bool ignoreCategoryNamespace) { - llvm::raw_svector_ostream OS(Name); - assert (CD && "Missing container decl in GetNameForMethod"); - OS << '\01' << (D->isInstanceMethod() ? '-' : '+') - << '[' << CD->getName(); - if (!ignoreCategoryNamespace) - if (const ObjCCategoryImplDecl *CID = - dyn_cast(D->getDeclContext())) - OS << '(' << *CID << ')'; - OS << ' ' << D->getSelector().getAsString() << ']'; -} - void CGObjCMac::FinishModule() { EmitModuleInfo();