From 95f0f69f1ff8eff34a00a47a236c2f91a2392c70 Mon Sep 17 00:00:00 2001 From: Haojian Wu Date: Tue, 12 Apr 2022 11:51:00 +0200 Subject: [PATCH] Revert "[AST] Add a new TemplateKind for template decls found via a using decl." It breaks arm build, there is no free bit for the extra UsingShadowDecl in TemplateName::StorageType. Reverting it to build the buildbot back until we comeup with a fix. This reverts commit 5a5be4044f0bceb71bb6a81f6955704691b389ed. --- clang-tools-extra/clangd/DumpAST.cpp | 1 - clang-tools-extra/clangd/SemanticHighlighting.cpp | 1 - clang/include/clang/AST/PropertiesBase.td | 10 ---- clang/include/clang/AST/TemplateName.h | 18 +----- clang/include/clang/AST/TextNodeDumper.h | 2 - clang/lib/AST/ASTContext.cpp | 4 -- clang/lib/AST/ASTImporter.cpp | 6 -- clang/lib/AST/ASTStructuralEquivalence.cpp | 1 - clang/lib/AST/ItaniumMangle.cpp | 7 --- clang/lib/AST/ODRHash.cpp | 1 - clang/lib/AST/TemplateName.cpp | 27 +-------- clang/lib/AST/TextNodeDumper.cpp | 13 ----- clang/lib/AST/Type.cpp | 3 +- clang/lib/Sema/SemaDecl.cpp | 22 ++------ clang/lib/Sema/SemaDeclCXX.cpp | 2 - clang/lib/Sema/SemaTemplate.cpp | 14 +---- clang/test/AST/ast-dump-using-template.cpp | 35 ------------ clang/test/CXX/temp/temp.deduct.guide/p3.cpp | 3 - clang/tools/libclang/CIndex.cpp | 1 - clang/unittests/AST/ASTImporterTest.cpp | 12 ---- clang/unittests/AST/CMakeLists.txt | 1 - clang/unittests/AST/TemplateNameTest.cpp | 68 ----------------------- 22 files changed, 13 insertions(+), 239 deletions(-) delete mode 100644 clang/test/AST/ast-dump-using-template.cpp delete mode 100644 clang/unittests/AST/TemplateNameTest.cpp diff --git a/clang-tools-extra/clangd/DumpAST.cpp b/clang-tools-extra/clangd/DumpAST.cpp index 8f640ad..4c36de8 100644 --- a/clang-tools-extra/clangd/DumpAST.cpp +++ b/clang-tools-extra/clangd/DumpAST.cpp @@ -184,7 +184,6 @@ class DumpVisitor : public RecursiveASTVisitor { TEMPLATE_KIND(DependentTemplate); TEMPLATE_KIND(SubstTemplateTemplateParm); TEMPLATE_KIND(SubstTemplateTemplateParmPack); - TEMPLATE_KIND(UsingTemplate); #undef TEMPLATE_KIND } llvm_unreachable("Unhandled NameKind enum"); diff --git a/clang-tools-extra/clangd/SemanticHighlighting.cpp b/clang-tools-extra/clangd/SemanticHighlighting.cpp index 2bc5928..862cfc8 100644 --- a/clang-tools-extra/clangd/SemanticHighlighting.cpp +++ b/clang-tools-extra/clangd/SemanticHighlighting.cpp @@ -762,7 +762,6 @@ public: case TemplateName::QualifiedTemplate: case TemplateName::SubstTemplateTemplateParm: case TemplateName::SubstTemplateTemplateParmPack: - case TemplateName::UsingTemplate: // Names that could be resolved to a TemplateDecl are handled elsewhere. break; } diff --git a/clang/include/clang/AST/PropertiesBase.td b/clang/include/clang/AST/PropertiesBase.td index 0ab18b6..3da7fd9 100644 --- a/clang/include/clang/AST/PropertiesBase.td +++ b/clang/include/clang/AST/PropertiesBase.td @@ -620,16 +620,6 @@ let Class = PropertyTypeCase in { return TemplateName(declaration); }]>; } - -let Class = PropertyTypeCase in { - def : Property<"foundDecl", UsingShadowDeclRef> { - let Read = [{ node.getAsUsingShadowDecl() }]; - } - def : Creator<[{ - return TemplateName(foundDecl); - }]>; -} - let Class = PropertyTypeCase in { def : Property<"overloads", Array> { let Read = [{ node.getAsOverloadedTemplate()->decls() }]; diff --git a/clang/include/clang/AST/TemplateName.h b/clang/include/clang/AST/TemplateName.h index 8b70608..26c64d0 100644 --- a/clang/include/clang/AST/TemplateName.h +++ b/clang/include/clang/AST/TemplateName.h @@ -39,7 +39,6 @@ class SubstTemplateTemplateParmStorage; class TemplateArgument; class TemplateDecl; class TemplateTemplateParmDecl; -class UsingShadowDecl; /// Implementation class used to describe either a set of overloaded /// template names or an already-substituted template template parameter pack. @@ -191,8 +190,7 @@ public: class TemplateName { using StorageType = llvm::PointerUnion; + QualifiedTemplateName *, DependentTemplateName *>; StorageType Storage; @@ -226,11 +224,7 @@ public: /// A template template parameter pack that has been substituted for /// a template template argument pack, but has not yet been expanded into /// individual arguments. - SubstTemplateTemplateParmPack, - - /// A template name that refers to a template declaration found through a - /// specific using shadow declaration. - UsingTemplate, + SubstTemplateTemplateParmPack }; TemplateName() = default; @@ -241,7 +235,6 @@ public: explicit TemplateName(SubstTemplateTemplateParmPackStorage *Storage); explicit TemplateName(QualifiedTemplateName *Qual); explicit TemplateName(DependentTemplateName *Dep); - explicit TemplateName(UsingShadowDecl *Using); /// Determine whether this template name is NULL. bool isNull() const; @@ -294,13 +287,6 @@ public: /// structure, if any. DependentTemplateName *getAsDependentTemplateName() const; - /// Retrieve the using shadow declaration through which the underlying - /// template declaration is introduced. - /// - /// The underlying template declaration is not stored in the template name, it - /// can be retrieved via the using shadow declaration. - UsingShadowDecl *getAsUsingShadowDecl() const; - TemplateName getUnderlying() const; /// Get the template name to substitute when this template name is used as a diff --git a/clang/include/clang/AST/TextNodeDumper.h b/clang/include/clang/AST/TextNodeDumper.h index 0ecb8a2..41bbf2e 100644 --- a/clang/include/clang/AST/TextNodeDumper.h +++ b/clang/include/clang/AST/TextNodeDumper.h @@ -317,8 +317,6 @@ public: void VisitTagType(const TagType *T); void VisitTemplateTypeParmType(const TemplateTypeParmType *T); void VisitAutoType(const AutoType *T); - void VisitDeducedTemplateSpecializationType( - const DeducedTemplateSpecializationType *T); void VisitTemplateSpecializationType(const TemplateSpecializationType *T); void VisitInjectedClassNameType(const InjectedClassNameType *T); void VisitObjCInterfaceType(const ObjCInterfaceType *T); diff --git a/clang/lib/AST/ASTContext.cpp b/clang/lib/AST/ASTContext.cpp index f6bb757..036f970 100644 --- a/clang/lib/AST/ASTContext.cpp +++ b/clang/lib/AST/ASTContext.cpp @@ -6125,9 +6125,6 @@ ASTContext::getNameForTemplate(TemplateName Name, return DeclarationNameInfo(subst->getParameterPack()->getDeclName(), NameLoc); } - case TemplateName::UsingTemplate: - return DeclarationNameInfo(Name.getAsUsingShadowDecl()->getDeclName(), - NameLoc); } llvm_unreachable("bad template name kind!"); @@ -6136,7 +6133,6 @@ ASTContext::getNameForTemplate(TemplateName Name, TemplateName ASTContext::getCanonicalTemplateName(const TemplateName &Name) const { switch (Name.getKind()) { - case TemplateName::UsingTemplate: case TemplateName::QualifiedTemplate: case TemplateName::Template: { TemplateDecl *Template = Name.getAsTemplateDecl(); diff --git a/clang/lib/AST/ASTImporter.cpp b/clang/lib/AST/ASTImporter.cpp index 22c0dbe..b368dbf 100644 --- a/clang/lib/AST/ASTImporter.cpp +++ b/clang/lib/AST/ASTImporter.cpp @@ -9193,12 +9193,6 @@ Expected ASTImporter::Import(TemplateName From) { return ToContext.getSubstTemplateTemplateParmPack( cast(*ParamOrErr), *ArgPackOrErr); } - case TemplateName::UsingTemplate: { - auto UsingOrError = Import(From.getAsUsingShadowDecl()); - if (!UsingOrError) - return UsingOrError.takeError(); - return TemplateName(cast(*UsingOrError)); - } } llvm_unreachable("Invalid template name kind"); diff --git a/clang/lib/AST/ASTStructuralEquivalence.cpp b/clang/lib/AST/ASTStructuralEquivalence.cpp index 05f3470..d4d20dd 100644 --- a/clang/lib/AST/ASTStructuralEquivalence.cpp +++ b/clang/lib/AST/ASTStructuralEquivalence.cpp @@ -517,7 +517,6 @@ static bool IsStructurallyEquivalent(StructuralEquivalenceContext &Context, case TemplateName::Template: case TemplateName::QualifiedTemplate: case TemplateName::SubstTemplateTemplateParm: - case TemplateName::UsingTemplate: // It is sufficient to check value of getAsTemplateDecl. break; diff --git a/clang/lib/AST/ItaniumMangle.cpp b/clang/lib/AST/ItaniumMangle.cpp index adab764..50e110e 100644 --- a/clang/lib/AST/ItaniumMangle.cpp +++ b/clang/lib/AST/ItaniumMangle.cpp @@ -2207,7 +2207,6 @@ void CXXNameMangler::mangleType(TemplateName TN) { TD = TN.getAsQualifiedTemplateName()->getTemplateDecl(); goto HaveDecl; - case TemplateName::UsingTemplate: case TemplateName::Template: TD = TN.getAsTemplateDecl(); goto HaveDecl; @@ -2384,12 +2383,6 @@ bool CXXNameMangler::mangleUnresolvedTypeOrSimpleId(QualType Ty, Out << "_SUBSTPACK_"; break; } - case TemplateName::UsingTemplate: { - TemplateDecl *TD = TN.getAsTemplateDecl(); - assert(TD && !isa(TD)); - mangleSourceNameWithAbiTags(TD); - break; - } } // Note: we don't pass in the template name here. We are mangling the diff --git a/clang/lib/AST/ODRHash.cpp b/clang/lib/AST/ODRHash.cpp index 04cbb09..735bcff 100644 --- a/clang/lib/AST/ODRHash.cpp +++ b/clang/lib/AST/ODRHash.cpp @@ -150,7 +150,6 @@ void ODRHash::AddTemplateName(TemplateName Name) { case TemplateName::DependentTemplate: case TemplateName::SubstTemplateTemplateParm: case TemplateName::SubstTemplateTemplateParmPack: - case TemplateName::UsingTemplate: break; } } diff --git a/clang/lib/AST/TemplateName.cpp b/clang/lib/AST/TemplateName.cpp index b887db8..a6d8a7f 100644 --- a/clang/lib/AST/TemplateName.cpp +++ b/clang/lib/AST/TemplateName.cpp @@ -13,7 +13,6 @@ #include "clang/AST/TemplateName.h" #include "clang/AST/Decl.h" #include "clang/AST/DeclBase.h" -#include "clang/AST/DeclCXX.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/DependenceFlags.h" #include "clang/AST/NestedNameSpecifier.h" @@ -77,7 +76,6 @@ TemplateName::TemplateName(SubstTemplateTemplateParmPackStorage *Storage) : Storage(Storage) {} TemplateName::TemplateName(QualifiedTemplateName *Qual) : Storage(Qual) {} TemplateName::TemplateName(DependentTemplateName *Dep) : Storage(Dep) {} -TemplateName::TemplateName(UsingShadowDecl *Using) : Storage(Using) {} bool TemplateName::isNull() const { return Storage.isNull(); } @@ -88,8 +86,6 @@ TemplateName::NameKind TemplateName::getKind() const { return DependentTemplate; if (Storage.is()) return QualifiedTemplate; - if (Storage.is()) - return UsingTemplate; UncommonTemplateNameStorage *uncommon = Storage.get(); @@ -112,9 +108,6 @@ TemplateDecl *TemplateName::getAsTemplateDecl() const { if (SubstTemplateTemplateParmStorage *sub = getAsSubstTemplateTemplateParm()) return sub->getReplacement().getAsTemplateDecl(); - if (UsingShadowDecl *USD = getAsUsingShadowDecl()) - return cast(USD->getTargetDecl()); - return nullptr; } @@ -160,10 +153,6 @@ DependentTemplateName *TemplateName::getAsDependentTemplateName() const { return Storage.dyn_cast(); } -UsingShadowDecl *TemplateName::getAsUsingShadowDecl() const { - return Storage.dyn_cast(); -} - TemplateName TemplateName::getNameToSubstitute() const { TemplateDecl *Decl = getAsTemplateDecl(); @@ -233,20 +222,7 @@ bool TemplateName::containsUnexpandedParameterPack() const { void TemplateName::print(raw_ostream &OS, const PrintingPolicy &Policy, Qualified Qual) const { - TemplateDecl *Template = Storage.dyn_cast(); - if (getKind() == TemplateName::UsingTemplate) { - // After `namespace ns { using std::vector }`, what is the fully-qualified - // name of the UsingTemplateName `vector` within ns? - // - // - ns::vector (the qualified name of the using-shadow decl) - // - std::vector (the qualifier name of the underlying template decl) - // - // Similar to the UsingType behavior, std::vector is much more common, and - // provides more information in practice, we print the underlying template - // decl of the using-shadow decl. - Template = getAsTemplateDecl(); - } - if (Template) + if (TemplateDecl *Template = Storage.dyn_cast()) if (Policy.CleanUglifiedParameters && isa(Template) && Template->getIdentifier()) OS << Template->getIdentifier()->deuglifiedName(); @@ -286,7 +262,6 @@ void TemplateName::print(raw_ostream &OS, const PrintingPolicy &Policy, else if (AssumedTemplateStorage *Assumed = getAsAssumedTemplateName()) { Assumed->getDeclName().print(OS, Policy); } else { - assert(getKind() == TemplateName::OverloadedTemplate); OverloadedTemplateStorage *OTS = getAsOverloadedTemplate(); (*OTS->begin())->printName(OS); } diff --git a/clang/lib/AST/TextNodeDumper.cpp b/clang/lib/AST/TextNodeDumper.cpp index 9131dfb..ba8b7b6 100644 --- a/clang/lib/AST/TextNodeDumper.cpp +++ b/clang/lib/AST/TextNodeDumper.cpp @@ -900,17 +900,12 @@ void TextNodeDumper::VisitIntegralTemplateArgument(const TemplateArgument &TA) { } void TextNodeDumper::VisitTemplateTemplateArgument(const TemplateArgument &TA) { - if (TA.getAsTemplate().getKind() == TemplateName::UsingTemplate) - OS << " using"; OS << " template "; TA.getAsTemplate().dump(OS); } void TextNodeDumper::VisitTemplateExpansionTemplateArgument( const TemplateArgument &TA) { - if (TA.getAsTemplateOrTemplatePattern().getKind() == - TemplateName::UsingTemplate) - OS << " using"; OS << " template expansion "; TA.getAsTemplateOrTemplatePattern().dump(OS); } @@ -1580,18 +1575,10 @@ void TextNodeDumper::VisitAutoType(const AutoType *T) { } } -void TextNodeDumper::VisitDeducedTemplateSpecializationType( - const DeducedTemplateSpecializationType *T) { - if (T->getTemplateName().getKind() == TemplateName::UsingTemplate) - OS << " using"; -} - void TextNodeDumper::VisitTemplateSpecializationType( const TemplateSpecializationType *T) { if (T->isTypeAlias()) OS << " alias"; - if (T->getTemplateName().getKind() == TemplateName::UsingTemplate) - OS << " using"; OS << " "; T->getTemplateName().dump(OS); } diff --git a/clang/lib/AST/Type.cpp b/clang/lib/AST/Type.cpp index bb9900e..936550d 100644 --- a/clang/lib/AST/Type.cpp +++ b/clang/lib/AST/Type.cpp @@ -3686,8 +3686,7 @@ TemplateSpecializationType::TemplateSpecializationType( "Use DependentTemplateSpecializationType for dependent template-name"); assert((T.getKind() == TemplateName::Template || T.getKind() == TemplateName::SubstTemplateTemplateParm || - T.getKind() == TemplateName::SubstTemplateTemplateParmPack || - T.getKind() == TemplateName::UsingTemplate) && + T.getKind() == TemplateName::SubstTemplateTemplateParmPack) && "Unexpected template name for TemplateSpecializationType"); auto *TemplateArgs = reinterpret_cast(this + 1); diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp index 6a6f691..cd9e6d5 100644 --- a/clang/lib/Sema/SemaDecl.cpp +++ b/clang/lib/Sema/SemaDecl.cpp @@ -504,11 +504,9 @@ ParsedType Sema::getTypeName(const IdentifierInfo &II, SourceLocation NameLoc, FoundUsingShadow = nullptr; } else if (AllowDeducedTemplate) { if (auto *TD = getAsTypeTemplateDecl(IIDecl)) { - assert(!FoundUsingShadow || FoundUsingShadow->getTargetDecl() == TD); - TemplateName Template = - FoundUsingShadow ? TemplateName(FoundUsingShadow) : TemplateName(TD); - T = Context.getDeducedTemplateSpecializationType(Template, QualType(), - false); + // FIXME: TemplateName should include FoundUsingShadow sugar. + T = Context.getDeducedTemplateSpecializationType(TemplateName(TD), + QualType(), false); // Don't wrap in a further UsingType. FoundUsingShadow = nullptr; } @@ -1109,20 +1107,12 @@ Corrected: IsFunctionTemplate = isa(TD); IsVarTemplate = isa(TD); - UsingShadowDecl *FoundUsingShadow = - dyn_cast(*Result.begin()); - - if (SS.isNotEmpty()) { - // FIXME: support using shadow-declaration in qualified template name. + if (SS.isNotEmpty()) Template = Context.getQualifiedTemplateName(SS.getScopeRep(), /*TemplateKeyword=*/false, TD); - } else { - assert(!FoundUsingShadow || - TD == cast(FoundUsingShadow->getTargetDecl())); - Template = FoundUsingShadow ? TemplateName(FoundUsingShadow) - : TemplateName(TD); - } + else + Template = TemplateName(TD); } else { // All results were non-template functions. This is a function template // name. diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 10546de..4d3a4ba 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/lib/Sema/SemaDeclCXX.cpp @@ -11023,8 +11023,6 @@ void Sema::CheckDeductionGuideDeclarator(Declarator &D, QualType &R, TemplateName SpecifiedName = RetTST.getTypePtr()->getTemplateName(); bool TemplateMatches = Context.hasSameTemplateName(SpecifiedName, GuidedTemplate); - // FIXME: We should consider other template kinds (using, qualified), - // otherwise we will emit bogus diagnostics. if (SpecifiedName.getKind() == TemplateName::Template && TemplateMatches) AcceptableReturnType = true; else { diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp index e7195ed..bf65f11 100644 --- a/clang/lib/Sema/SemaTemplate.cpp +++ b/clang/lib/Sema/SemaTemplate.cpp @@ -11,13 +11,11 @@ #include "TreeTransform.h" #include "clang/AST/ASTConsumer.h" #include "clang/AST/ASTContext.h" -#include "clang/AST/Decl.h" #include "clang/AST/DeclFriend.h" #include "clang/AST/DeclTemplate.h" #include "clang/AST/Expr.h" #include "clang/AST/ExprCXX.h" #include "clang/AST/RecursiveASTVisitor.h" -#include "clang/AST/TemplateName.h" #include "clang/AST/TypeVisitor.h" #include "clang/Basic/Builtins.h" #include "clang/Basic/LangOptions.h" @@ -225,7 +223,6 @@ TemplateNameKind Sema::isTemplateName(Scope *S, return TNK_Non_template; NamedDecl *D = nullptr; - UsingShadowDecl *FoundUsingShadow = dyn_cast(*R.begin()); if (R.isAmbiguous()) { // If we got an ambiguity involving a non-function template, treat this // as a template name, and pick an arbitrary template for error recovery. @@ -236,7 +233,6 @@ TemplateNameKind Sema::isTemplateName(Scope *S, AnyFunctionTemplates = true; else { D = FoundTemplate; - FoundUsingShadow = dyn_cast(FoundD); break; } } @@ -287,14 +283,10 @@ TemplateNameKind Sema::isTemplateName(Scope *S, if (SS.isSet() && !SS.isInvalid()) { NestedNameSpecifier *Qualifier = SS.getScopeRep(); - // FIXME: store the using TemplateName in QualifiedTemplateName if - // the TD is referred via a using-declaration. - Template = - Context.getQualifiedTemplateName(Qualifier, hasTemplateKeyword, TD); + Template = Context.getQualifiedTemplateName(Qualifier, + hasTemplateKeyword, TD); } else { - Template = - FoundUsingShadow ? TemplateName(FoundUsingShadow) : TemplateName(TD); - assert(!FoundUsingShadow || FoundUsingShadow->getTargetDecl() == TD); + Template = TemplateName(TD); } if (isa(TD)) { diff --git a/clang/test/AST/ast-dump-using-template.cpp b/clang/test/AST/ast-dump-using-template.cpp deleted file mode 100644 index fbce09d..0000000 --- a/clang/test/AST/ast-dump-using-template.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// RUN: %clang_cc1 -triple x86_64-unknown-unknown -std=c++17 -ast-dump %s | FileCheck -strict-whitespace %s - -// Tests to verify we construct correct using template names. -// TemplateNames are not dumped, so the sugar here isn't obvious. However -// the "using" on the TemplateSpecializationTypes shows that the -// UsingTemplateName is present. -namespace ns { -template class S { - public: - S(T); -}; -} -using ns::S; - -// TemplateName in TemplateSpecializationType. -template -using A = S; -// CHECK: TypeAliasDecl -// CHECK-NEXT: `-TemplateSpecializationType {{.*}} 'S' dependent using S - -// TemplateName in TemplateArgument. -template