From 1812e13a3d6be9a838672ff74b3d9d383f5a83b5 Mon Sep 17 00:00:00 2001 From: Alexander Kornienko Date: Thu, 23 Feb 2023 17:08:47 +0100 Subject: [PATCH] Revert "[clang] Add the check of membership for the issue #58674 and improve the lookup process" The commit causes clang to crash. See https://reviews.llvm.org/D143840#4147234 This reverts commit 8498ba6c2860c838183f9951b63df26ab5f02265. --- clang/docs/ReleaseNotes.rst | 3 -- clang/include/clang/AST/DeclCXX.h | 10 ++---- clang/lib/AST/CXXInheritance.cpp | 31 +++++++++---------- clang/lib/Sema/SemaExpr.cpp | 42 ++++++++------------------ clang/test/CodeGenCXX/decl-ref-inheritance.cpp | 22 -------------- clang/test/SemaCXX/decltype.cpp | 38 ----------------------- 6 files changed, 30 insertions(+), 116 deletions(-) delete mode 100644 clang/test/CodeGenCXX/decl-ref-inheritance.cpp diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 0c8d3d9..2a636eb 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -171,9 +171,6 @@ Bug Fixes to C++ Support - Fix crash when evaluating consteval constructor of derived class whose base has more than one field. (`#60166 `_) -- Fix an issue about ``decltype`` in the members of class templates derived from - templates with related parameters. - (`#58674 `_) Bug Fixes to AST Handling ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/clang/include/clang/AST/DeclCXX.h b/clang/include/clang/AST/DeclCXX.h index 8909acc7..11276c7 100644 --- a/clang/include/clang/AST/DeclCXX.h +++ b/clang/include/clang/AST/DeclCXX.h @@ -1546,11 +1546,8 @@ public: /// /// \param Base the base class we are searching for. /// - /// \param LookupInDependentTypes whether to look up in dependent types. - /// /// \returns true if this class is derived from Base, false otherwise. - bool isDerivedFrom(const CXXRecordDecl *Base, - bool LookupInDependentTypes = false) const; + bool isDerivedFrom(const CXXRecordDecl *Base) const; /// Determine whether this class is derived from the type \p Base. /// @@ -1564,14 +1561,11 @@ public: /// \param Paths will contain the paths taken from the current class to the /// given \p Base class. /// - /// \param LookupInDependentTypes whether to look up independent types. - /// /// \returns true if this class is derived from \p Base, false otherwise. /// /// \todo add a separate parameter to configure IsDerivedFrom, rather than /// tangling input and output in \p Paths - bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths, - bool LookupInDependentTypes = false) const; + bool isDerivedFrom(const CXXRecordDecl *Base, CXXBasePaths &Paths) const; /// Determine whether this class is virtually derived from /// the class \p Base. diff --git a/clang/lib/AST/CXXInheritance.cpp b/clang/lib/AST/CXXInheritance.cpp index 32b17fc..25de2a2 100644 --- a/clang/lib/AST/CXXInheritance.cpp +++ b/clang/lib/AST/CXXInheritance.cpp @@ -64,16 +64,14 @@ void CXXBasePaths::swap(CXXBasePaths &Other) { std::swap(DetectedVirtual, Other.DetectedVirtual); } -bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base, - bool LookupInDependentTypes) const { +bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base) const { CXXBasePaths Paths(/*FindAmbiguities=*/false, /*RecordPaths=*/false, /*DetectVirtual=*/false); - return isDerivedFrom(Base, Paths, LookupInDependentTypes); + return isDerivedFrom(Base, Paths); } bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base, - CXXBasePaths &Paths, - bool LookupInDependentTypes) const { + CXXBasePaths &Paths) const { if (getCanonicalDecl() == Base->getCanonicalDecl()) return false; @@ -85,7 +83,7 @@ bool CXXRecordDecl::isDerivedFrom(const CXXRecordDecl *Base, return Specifier->getType()->getAsRecordDecl() && FindBaseClass(Specifier, Path, BaseDecl); }, - Paths, LookupInDependentTypes); + Paths); } bool CXXRecordDecl::isVirtuallyDerivedFrom(const CXXRecordDecl *Base) const { @@ -248,16 +246,17 @@ bool CXXBasePaths::lookupInBases(ASTContext &Context, } else if (VisitBase) { CXXRecordDecl *BaseRecord; if (LookupInDependent) { - BaseRecord = cast_if_present( - BaseSpec.getType()->getAsRecordDecl()); - if (!BaseRecord) { - if (const TemplateSpecializationType *TST = - BaseSpec.getType()->getAs()) { - TemplateName TN = TST->getTemplateName(); - if (auto *TD = - dyn_cast_or_null(TN.getAsTemplateDecl())) - BaseRecord = TD->getTemplatedDecl(); - } + BaseRecord = nullptr; + const TemplateSpecializationType *TST = + BaseSpec.getType()->getAs(); + if (!TST) { + if (auto *RT = BaseSpec.getType()->getAs()) + BaseRecord = cast(RT->getDecl()); + } else { + TemplateName TN = TST->getTemplateName(); + if (auto *TD = + dyn_cast_or_null(TN.getAsTemplateDecl())) + BaseRecord = TD->getTemplatedDecl(); } if (BaseRecord) { if (!BaseRecord->hasDefinition() || diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 922f102..3b8c8a4 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -2698,36 +2698,20 @@ Sema::ActOnIdExpression(Scope *S, CXXScopeSpec &SS, // to get this right here so that we don't end up making a // spuriously dependent expression if we're inside a dependent // instance method. - // - // We also don't need to do this if R resolved to a member in another - // class, which can happen in an unevaluated operand: - // - // C++ [expr.prim.id]p3.3: - // If that id-expression denotes a non-static data member and it - // appears in an unevaluated operand. if (!R.empty() && (*R.begin())->isCXXClassMember()) { - bool MightBeImplicitMember = true, CheckField = true; - if (IsAddressOfOperand) { - MightBeImplicitMember = SS.isEmpty() && !R.isOverloadedResult(); - CheckField = !R.isUnresolvableResult(); - } - if (MightBeImplicitMember && CheckField) { - if (R.isSingleResult() && - isa(R.getFoundDecl())) { - auto Class = cast((*R.begin())->getDeclContext()); - for (auto Curr = S->getLookupEntity(); Curr && !Curr->isFileContext(); - Curr = Curr->getParent()) { - if (auto ThisClass = dyn_cast_if_present(Curr)) { - if ((MightBeImplicitMember = - ThisClass->Equals(Class) || - ThisClass->isDerivedFrom(Class, - /*LookupIndependent=*/true))) - break; - } - } - } else if (IsAddressOfOperand) - MightBeImplicitMember = false; - } + bool MightBeImplicitMember; + if (!IsAddressOfOperand) + MightBeImplicitMember = true; + else if (!SS.isEmpty()) + MightBeImplicitMember = false; + else if (R.isOverloadedResult()) + MightBeImplicitMember = false; + else if (R.isUnresolvableResult()) + MightBeImplicitMember = true; + else + MightBeImplicitMember = isa(R.getFoundDecl()) || + isa(R.getFoundDecl()) || + isa(R.getFoundDecl()); if (MightBeImplicitMember) return BuildPossibleImplicitMemberExpr(SS, TemplateKWLoc, diff --git a/clang/test/CodeGenCXX/decl-ref-inheritance.cpp b/clang/test/CodeGenCXX/decl-ref-inheritance.cpp deleted file mode 100644 index ba58ec3..0000000 --- a/clang/test/CodeGenCXX/decl-ref-inheritance.cpp +++ /dev/null @@ -1,22 +0,0 @@ -// RUN: %clang_cc1 -triple=x86_64-unknown-linux -emit-llvm %s -o - | FileCheck %s - -// CHECK: [[FOO:%.+]] = type { i32 } -struct foo { - int val; -}; - -template struct bar : T { -}; - -struct baz : bar { - // CHECK-LABEL: define{{.*}} i32 @_ZN3baz3getEv - // CHECK: {{%.+}} = getelementptr inbounds [[FOO]], ptr {{%.+}}, i32 0, i32 0 - int get() { - return val; - } -}; - -int qux() { - auto f = baz{}; - return f.get(); -} diff --git a/clang/test/SemaCXX/decltype.cpp b/clang/test/SemaCXX/decltype.cpp index 96abb60..32c61bb 100644 --- a/clang/test/SemaCXX/decltype.cpp +++ b/clang/test/SemaCXX/decltype.cpp @@ -101,44 +101,6 @@ namespace D5789 { template void foo(decltype(T(LP1{ .p1 = g1, .p1.x[1] = 'x' }))) {} } -namespace GH58674 { - struct Foo { - float value_; - struct nested { - float value_; - }; - }; - - template - struct TemplateFoo { - float value_; - }; - - float bar; - - template - struct Animal{}; - - template - class Cat : Animal { - using okay = decltype(Foo::value_); - using also_okay = decltype(bar); - using okay2 = decltype(Foo::nested::value_); - using okay3 = decltype(TemplateFoo::value_); - public: - void meow() { - using okay = decltype(Foo::value_); - using also_okay = decltype(bar); - using okay2 = decltype(Foo::nested::value_); - using okay3 = decltype(TemplateFoo::value_); - } - }; - - void baz() { - Cat{}.meow(); - } -} - template class conditional { }; -- 2.7.4