llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Balázs Benics (steakhal) <details> <summary>Changes</summary> Split from #<!-- -->185499 --- Patch is 26.25 KiB, truncated to 20.00 KiB below, full version: https://github.com/llvm/llvm-project/pull/185601.diff 2 Files Affected: - (modified) clang/include/clang/Index/USRGeneration.h (+3-6) - (modified) clang/lib/Index/USRGeneration.cpp (+291-223) ``````````diff diff --git a/clang/include/clang/Index/USRGeneration.h b/clang/include/clang/Index/USRGeneration.h index 61d267f3545a7..66fede3603899 100644 --- a/clang/include/clang/Index/USRGeneration.h +++ b/clang/include/clang/Index/USRGeneration.h @@ -24,9 +24,7 @@ class QualType; namespace index { -static inline StringRef getUSRSpacePrefix() { - return "c:"; -} +static inline StringRef getUSRSpacePrefix() { return "c:"; } /// Generate a USR for a Decl, including the USR prefix. /// \returns true if the results should be ignored, false otherwise. @@ -54,7 +52,8 @@ void generateUSRForObjCMethod(StringRef Sel, bool IsInstanceMethod, raw_ostream &OS); /// Generate a USR fragment for an Objective-C property. -void generateUSRForObjCProperty(StringRef Prop, bool isClassProp, raw_ostream &OS); +void generateUSRForObjCProperty(StringRef Prop, bool isClassProp, + raw_ostream &OS); /// Generate a USR fragment for an Objective-C protocol. void generateUSRForObjCProtocol(StringRef Prot, raw_ostream &OS, @@ -99,9 +98,7 @@ bool generateUSRFragmentForModule(const Module *Mod, raw_ostream &OS); /// \returns true on error, false on success. bool generateUSRFragmentForModuleName(StringRef ModName, raw_ostream &OS); - } // namespace index } // namespace clang #endif // LLVM_CLANG_INDEX_USRGENERATION_H - diff --git a/clang/lib/Index/USRGeneration.cpp b/clang/lib/Index/USRGeneration.cpp index e3649631ac8d3..1831cc9ca8643 100644 --- a/clang/lib/Index/USRGeneration.cpp +++ b/clang/lib/Index/USRGeneration.cpp @@ -146,8 +146,8 @@ class USRGenerator : public ConstDeclVisitor<USRGenerator> { } /// Generate a USR for an Objective-C class category. - void GenObjCCategory(StringRef cls, StringRef cat, - StringRef clsExt, StringRef catExt) { + void GenObjCCategory(StringRef cls, StringRef cat, StringRef clsExt, + StringRef catExt) { generateUSRForObjCCategory(cls, cat, Out, clsExt, catExt); } @@ -297,9 +297,14 @@ void USRGenerator::VisitFunctionDecl(const FunctionDecl *D) { if (unsigned quals = MD->getMethodQualifiers().getCVRUQualifiers()) Out << (char)('0' + quals); switch (MD->getRefQualifier()) { - case RQ_None: break; - case RQ_LValue: Out << '&'; break; - case RQ_RValue: Out << "&&"; break; + case RQ_None: + break; + case RQ_LValue: + Out << '&'; + break; + case RQ_RValue: + Out << "&&"; + break; } } } @@ -329,8 +334,8 @@ void USRGenerator::VisitVarDecl(const VarDecl *D) { if (VarTemplateDecl *VarTmpl = D->getDescribedVarTemplate()) { Out << "@VT"; VisitTemplateParameterList(VarTmpl->getTemplateParameters()); - } else if (const VarTemplatePartialSpecializationDecl *PartialSpec - = dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { + } else if (const VarTemplatePartialSpecializationDecl *PartialSpec = + dyn_cast<VarTemplatePartialSpecializationDecl>(D)) { Out << "@VP"; VisitTemplateParameterList(PartialSpec->getTemplateParameters()); } @@ -348,8 +353,8 @@ void USRGenerator::VisitVarDecl(const VarDecl *D) { Out << '@' << s; // For a template specialization, mangle the template arguments. - if (const VarTemplateSpecializationDecl *Spec - = dyn_cast<VarTemplateSpecializationDecl>(D)) { + if (const VarTemplateSpecializationDecl *Spec = + dyn_cast<VarTemplateSpecializationDecl>(D)) { const TemplateArgumentList &Args = Spec->getTemplateArgs(); Out << '>'; for (unsigned I = 0, N = Args.size(); I != N; ++I) { @@ -366,12 +371,12 @@ void USRGenerator::VisitBindingDecl(const BindingDecl *D) { } void USRGenerator::VisitNonTypeTemplateParmDecl( - const NonTypeTemplateParmDecl *D) { + const NonTypeTemplateParmDecl *D) { GenLoc(D, /*IncludeOffset=*/true); } void USRGenerator::VisitTemplateTemplateParmDecl( - const TemplateTemplateParmDecl *D) { + const TemplateTemplateParmDecl *D) { GenLoc(D, /*IncludeOffset=*/true); } @@ -412,10 +417,9 @@ void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) { const DeclContext *container = D->getDeclContext(); if (const ObjCProtocolDecl *pd = dyn_cast<ObjCProtocolDecl>(container)) { Visit(pd); - } - else { - // The USR for a method declared in a class extension or category is based on - // the ObjCInterfaceDecl, not the ObjCCategoryDecl. + } else { + // The USR for a method declared in a class extension or category is based + // on the ObjCInterfaceDecl, not the ObjCCategoryDecl. const ObjCInterfaceDecl *ID = D->getClassInterface(); if (!ID) { IgnoreResults = true; @@ -434,58 +438,57 @@ void USRGenerator::VisitObjCMethodDecl(const ObjCMethodDecl *D) { void USRGenerator::VisitObjCContainerDecl(const ObjCContainerDecl *D, const ObjCCategoryDecl *CatD) { switch (D->getKind()) { - default: - llvm_unreachable("Invalid ObjC container."); - case Decl::ObjCInterface: - case Decl::ObjCImplementation: - GenObjCClass(D->getName(), GetExternalSourceContainer(D), - GetExternalSourceContainer(CatD)); - break; - case Decl::ObjCCategory: { - const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D); - const ObjCInterfaceDecl *ID = CD->getClassInterface(); - if (!ID) { - // Handle invalid code where the @interface might not - // have been specified. - // FIXME: We should be able to generate this USR even if the - // @interface isn't available. - IgnoreResults = true; - return; - } - // Specially handle class extensions, which are anonymous categories. - // We want to mangle in the location to uniquely distinguish them. - if (CD->IsClassExtension()) { - Out << "objc(ext)" << ID->getName() << '@'; - GenLoc(CD, /*IncludeOffset=*/true); - } - else - GenObjCCategory(ID->getName(), CD->getName(), - GetExternalSourceContainer(ID), - GetExternalSourceContainer(CD)); - - break; + default: + llvm_unreachable("Invalid ObjC container."); + case Decl::ObjCInterface: + case Decl::ObjCImplementation: + GenObjCClass(D->getName(), GetExternalSourceContainer(D), + GetExternalSourceContainer(CatD)); + break; + case Decl::ObjCCategory: { + const ObjCCategoryDecl *CD = cast<ObjCCategoryDecl>(D); + const ObjCInterfaceDecl *ID = CD->getClassInterface(); + if (!ID) { + // Handle invalid code where the @interface might not + // have been specified. + // FIXME: We should be able to generate this USR even if the + // @interface isn't available. + IgnoreResults = true; + return; } - case Decl::ObjCCategoryImpl: { - const ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D); - const ObjCInterfaceDecl *ID = CD->getClassInterface(); - if (!ID) { - // Handle invalid code where the @interface might not - // have been specified. - // FIXME: We should be able to generate this USR even if the - // @interface isn't available. - IgnoreResults = true; - return; - } + // Specially handle class extensions, which are anonymous categories. + // We want to mangle in the location to uniquely distinguish them. + if (CD->IsClassExtension()) { + Out << "objc(ext)" << ID->getName() << '@'; + GenLoc(CD, /*IncludeOffset=*/true); + } else GenObjCCategory(ID->getName(), CD->getName(), GetExternalSourceContainer(ID), GetExternalSourceContainer(CD)); - break; - } - case Decl::ObjCProtocol: { - const ObjCProtocolDecl *PD = cast<ObjCProtocolDecl>(D); - GenObjCProtocol(PD->getName(), GetExternalSourceContainer(PD)); - break; + + break; + } + case Decl::ObjCCategoryImpl: { + const ObjCCategoryImplDecl *CD = cast<ObjCCategoryImplDecl>(D); + const ObjCInterfaceDecl *ID = CD->getClassInterface(); + if (!ID) { + // Handle invalid code where the @interface might not + // have been specified. + // FIXME: We should be able to generate this USR even if the + // @interface isn't available. + IgnoreResults = true; + return; } + GenObjCCategory(ID->getName(), CD->getName(), + GetExternalSourceContainer(ID), + GetExternalSourceContainer(CD)); + break; + } + case Decl::ObjCProtocol: { + const ObjCProtocolDecl *PD = cast<ObjCProtocolDecl>(D); + GenObjCProtocol(PD->getName(), GetExternalSourceContainer(PD)); + break; + } } } @@ -511,8 +514,8 @@ void USRGenerator::VisitObjCPropertyImplDecl(const ObjCPropertyImplDecl *D) { void USRGenerator::VisitTagDecl(const TagDecl *D) { // Add the location of the tag decl to handle resolution across // translation units. - if (!isa<EnumDecl>(D) && - ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D))) + if (!isa<EnumDecl>(D) && ShouldGenerateLocation(D) && + GenLoc(D, /*IncludeOffset=*/isLocal(D))) return; GenExtSymbolContainer(D); @@ -538,8 +541,9 @@ void USRGenerator::VisitTagDecl(const TagDecl *D) { llvm_unreachable("enum template"); } VisitTemplateParameterList(ClassTmpl->getTemplateParameters()); - } else if (const ClassTemplatePartialSpecializationDecl *PartialSpec - = dyn_cast<ClassTemplatePartialSpecializationDecl>(CXXRecord)) { + } else if (const ClassTemplatePartialSpecializationDecl *PartialSpec = + dyn_cast<ClassTemplatePartialSpecializationDecl>( + CXXRecord)) { AlreadyStarted = true; switch (D->getTagKind()) { @@ -600,8 +604,8 @@ void USRGenerator::VisitTagDecl(const TagDecl *D) { } // For a class template specialization, mangle the template arguments. - if (const ClassTemplateSpecializationDecl *Spec - = dyn_cast<ClassTemplateSpecializationDecl>(D)) { + if (const ClassTemplateSpecializationDecl *Spec = + dyn_cast<ClassTemplateSpecializationDecl>(D)) { const TemplateArgumentList &Args = Spec->getTemplateArgs(); Out << '>'; for (unsigned I = 0, N = Args.size(); I != N; ++I) { @@ -680,8 +684,8 @@ void USRGenerator::VisitType(QualType T) { qVal |= 0x2; if (Q.hasRestrict()) qVal |= 0x4; - if(qVal) - Out << ((char) ('0' + qVal)); + if (qVal) + Out << ((char)('0' + qVal)); // Mangle in ObjC GC qualifiers? @@ -692,89 +696,123 @@ void USRGenerator::VisitType(QualType T) { if (const BuiltinType *BT = T->getAs<BuiltinType>()) { switch (BT->getKind()) { - case BuiltinType::Void: - Out << 'v'; break; - case BuiltinType::Bool: - Out << 'b'; break; - case BuiltinType::UChar: - Out << 'c'; break; - case BuiltinType::Char8: - Out << 'u'; break; - case BuiltinType::Char16: - Out << 'q'; break; - case BuiltinType::Char32: - Out << 'w'; break; - case BuiltinType::UShort: - Out << 's'; break; - case BuiltinType::UInt: - Out << 'i'; break; - case BuiltinType::ULong: - Out << 'l'; break; - case BuiltinType::ULongLong: - Out << 'k'; break; - case BuiltinType::UInt128: - Out << 'j'; break; - case BuiltinType::Char_U: - case BuiltinType::Char_S: - Out << 'C'; break; - case BuiltinType::SChar: - Out << 'r'; break; - case BuiltinType::WChar_S: - case BuiltinType::WChar_U: - Out << 'W'; break; - case BuiltinType::Short: - Out << 'S'; break; - case BuiltinType::Int: - Out << 'I'; break; - case BuiltinType::Long: - Out << 'L'; break; - case BuiltinType::LongLong: - Out << 'K'; break; - case BuiltinType::Int128: - Out << 'J'; break; - case BuiltinType::Float16: - case BuiltinType::Half: - Out << 'h'; break; - case BuiltinType::Float: - Out << 'f'; break; - case BuiltinType::Double: - Out << 'd'; break; - case BuiltinType::LongDouble: - Out << 'D'; break; - case BuiltinType::Float128: - Out << 'Q'; break; - case BuiltinType::NullPtr: - Out << 'n'; break; -#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ - case BuiltinType::Id: \ - Out << "@BT@" << #Suffix << "_" << #ImgType; break; + case BuiltinType::Void: + Out << 'v'; + break; + case BuiltinType::Bool: + Out << 'b'; + break; + case BuiltinType::UChar: + Out << 'c'; + break; + case BuiltinType::Char8: + Out << 'u'; + break; + case BuiltinType::Char16: + Out << 'q'; + break; + case BuiltinType::Char32: + Out << 'w'; + break; + case BuiltinType::UShort: + Out << 's'; + break; + case BuiltinType::UInt: + Out << 'i'; + break; + case BuiltinType::ULong: + Out << 'l'; + break; + case BuiltinType::ULongLong: + Out << 'k'; + break; + case BuiltinType::UInt128: + Out << 'j'; + break; + case BuiltinType::Char_U: + case BuiltinType::Char_S: + Out << 'C'; + break; + case BuiltinType::SChar: + Out << 'r'; + break; + case BuiltinType::WChar_S: + case BuiltinType::WChar_U: + Out << 'W'; + break; + case BuiltinType::Short: + Out << 'S'; + break; + case BuiltinType::Int: + Out << 'I'; + break; + case BuiltinType::Long: + Out << 'L'; + break; + case BuiltinType::LongLong: + Out << 'K'; + break; + case BuiltinType::Int128: + Out << 'J'; + break; + case BuiltinType::Float16: + case BuiltinType::Half: + Out << 'h'; + break; + case BuiltinType::Float: + Out << 'f'; + break; + case BuiltinType::Double: + Out << 'd'; + break; + case BuiltinType::LongDouble: + Out << 'D'; + break; + case BuiltinType::Float128: + Out << 'Q'; + break; + case BuiltinType::NullPtr: + Out << 'n'; + break; +#define IMAGE_TYPE(ImgType, Id, SingletonId, Access, Suffix) \ + case BuiltinType::Id: \ + Out << "@BT@" << #Suffix << "_" << #ImgType; \ + break; #include "clang/Basic/OpenCLImageTypes.def" -#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ - case BuiltinType::Id: \ - Out << "@BT@" << #ExtType; break; +#define EXT_OPAQUE_TYPE(ExtType, Id, Ext) \ + case BuiltinType::Id: \ + Out << "@BT@" << #ExtType; \ + break; #include "clang/Basic/OpenCLExtensionTypes.def" - case BuiltinType::OCLEvent: - Out << "@BT@OCLEvent"; break; - case BuiltinType::OCLClkEvent: - Out << "@BT@OCLClkEvent"; break; - case BuiltinType::OCLQueue: - Out << "@BT@OCLQueue"; break; - case BuiltinType::OCLReserveID: - Out << "@BT@OCLReserveID"; break; - case BuiltinType::OCLSampler: - Out << "@BT@OCLSampler"; break; + case BuiltinType::OCLEvent: + Out << "@BT@OCLEvent"; + break; + case BuiltinType::OCLClkEvent: + Out << "@BT@OCLClkEvent"; + break; + case BuiltinType::OCLQueue: + Out << "@BT@OCLQueue"; + break; + case BuiltinType::OCLReserveID: + Out << "@BT@OCLReserveID"; + break; + case BuiltinType::OCLSampler: + Out << "@BT@OCLSampler"; + break; #define SVE_TYPE(Name, Id, SingletonId) \ case BuiltinType::Id: \ Out << "@BT@" << #Name; \ break; #include "clang/Basic/AArch64ACLETypes.def" -#define PPC_VECTOR_TYPE(Name, Id, Size) \ - case BuiltinType::Id: \ - Out << "@BT@" << #Name; break; +#define PPC_VECTOR_TYPE(Name, Id, Size) \ + case BuiltinType::Id: \ + Out << "@BT@" << #Name; \ + break; #include "clang/Basic/PPCTypes.def" -#define RVV_TYPE(Name, Id, SingletonId) \ - case BuiltinType::Id: \ - Out << "@BT@" << Name; break; +#define RVV_TYPE(Name, Id, SingletonId) \ + case BuiltinType::Id: \ + Out << "@BT@" << Name; \ + break; #include "clang/Basic/RISCVVTypes.def" #define WASM_TYPE(Name, Id, SingletonId) case BuiltinType::Id: #include "clang/Basic/WebAssemblyReferenceTypes.def" @@ -788,72 +826,101 @@ void USRGenerator::VisitType(QualType T) { Out << "@BT@" << #Name; \ break; #include "clang/Basic/HLSLIntangibleTypes.def" - case BuiltinType::ShortAccum: - Out << "@BT@ShortAccum"; break; - case BuiltinType::Accum: - Out << "@BT@Accum"; break; - case BuiltinType::LongAccum: - Out << "@BT@LongAccum"; break; - case BuiltinType::UShortAccum: - Out << "@BT@UShortAccum"; break; - case BuiltinType::UAccum: - Out << "@BT@UAccum"; break; - case BuiltinType::ULongAccum: - Out << "@BT@ULongAccum"; break; - case BuiltinType::ShortFract: - Out << "@BT@ShortFract"; break; - case BuiltinType::Fract: - Out << "@BT@Fract"; break; - case BuiltinType::LongFract: - Out << "@BT@LongFract"; break; - case BuiltinType::UShortFract: - Out << "@BT@UShortFract"; break; - case BuiltinType::UFract: - Out << "@BT@UFract"; break; - case BuiltinType::ULongFract: - Out << "@BT@ULongFract"; break; - case BuiltinType::SatShortAccum: - Out << "@BT@SatShortAccum"; break; - case BuiltinType::SatAccum: - Out << "@BT@SatAccum"; break; - case BuiltinType::SatLongAccum: - Out << "@BT@SatLongAccum"; break; - case BuiltinType::SatUShortAccum: - Out << "@BT@SatUShortAccum"; break; - case BuiltinType::SatUAccum: - Out << "@BT@SatUAccum"; break; - case BuiltinType::SatULongAccum: - Out << "@BT@SatULongAccum"; break; - case BuiltinType::SatShortFract: - Out << "@BT@SatShortFract"; break; - case BuiltinType::SatFract: - Out << "@BT@SatFract"; break; - case BuiltinType::SatLongFract: - Out << "@BT@SatLongFract"; break; - case BuiltinType::SatUShortFract: - Out << "@BT@SatUShortFract"; break; - case BuiltinType::SatUFract: - Out << "@BT@SatUFract"; break; - case BuiltinType::SatULongFract: - Out << "@BT@SatULongFract"; break; - case BuiltinType::BFloat16: - Out << "@BT@__bf16"; break; - case BuiltinType::Ibm128: - Out << "@BT@__ibm128"; break; - case BuiltinType::ObjCId: - Out << 'o'; break; - case BuiltinType::ObjCClass: - Out << 'O'; break; - case BuiltinType::ObjCSel: - Out << 'e'; break; + case BuiltinType::ShortAccum: + Out << "@BT@ShortAccum"; + break; + case BuiltinType::Accum: + Out << "@BT@Accum"; + break; + case BuiltinType::LongAccum: + Out << "@BT@LongAccum"; + break; + case BuiltinType::UShortAccum: + Out << "@BT@UShortAccum"; + break; + case BuiltinType::UAccum: + Out << "@BT@UAccum"; + break; + case BuiltinType::ULongAccum: + ... [truncated] `````````` </details> https://github.com/llvm/llvm-project/pull/185601 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
