This revision was automatically updated to reflect the committed changes. Closed by commit rGcd4e8d7f6f5e: [clangd] Fix an assertion failure in TargetFinder's heuristic resolution of… (authored by hokein).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D84837/new/ https://reviews.llvm.org/D84837 Files: clang-tools-extra/clangd/FindTarget.cpp clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Index: clang-tools-extra/clangd/unittests/FindTargetTests.cpp =================================================================== --- clang-tools-extra/clangd/unittests/FindTargetTests.cpp +++ clang-tools-extra/clangd/unittests/FindTargetTests.cpp @@ -627,6 +627,20 @@ }; )cpp"; EXPECT_DECLS("CXXDependentScopeMemberExpr", "int aaaa"); + + Code = R"cpp( + class Foo { + public: + static Foo k(int); + template <typename T> T convert() const; + }; + template <typename T> + void test() { + Foo::k(T()).template [[convert]]<T>(); + } + )cpp"; + EXPECT_DECLS("CXXDependentScopeMemberExpr", + "template <typename T> T convert() const"); } TEST_F(TargetDeclTest, ObjC) { Index: clang-tools-extra/clangd/FindTarget.cpp =================================================================== --- clang-tools-extra/clangd/FindTarget.cpp +++ clang-tools-extra/clangd/FindTarget.cpp @@ -163,13 +163,12 @@ } // Forward declaration, needed as this function is mutually recursive -// with resolveDependentExprToDecls. -const Type *resolveDependentExprToType(const Expr *E); +// with resolveExprToDecls. +const Type *resolveExprToType(const Expr *E); -// Try to heuristically resolve a dependent expression `E` to one +// Try to heuristically resolve a possibly-dependent expression `E` to one // or more declarations that it likely references. -std::vector<const NamedDecl *> resolveDependentExprToDecls(const Expr *E) { - assert(E->isTypeDependent()); +std::vector<const NamedDecl *> resolveExprToDecls(const Expr *E) { if (const auto *ME = dyn_cast<CXXDependentScopeMemberExpr>(E)) { const Type *BaseType = ME->getBaseType().getTypePtrOrNull(); if (ME->isArrow()) { @@ -183,7 +182,7 @@ // can get further by analyzing the depedent expression. Expr *Base = ME->isImplicitAccess() ? nullptr : ME->getBase(); if (Base && BT->getKind() == BuiltinType::Dependent) { - BaseType = resolveDependentExprToType(Base); + BaseType = resolveExprToType(Base); } } return getMembersReferencedViaDependentName( @@ -197,7 +196,7 @@ /*IsNonstaticMember=*/false); } if (const auto *CE = dyn_cast<CallExpr>(E)) { - const auto *CalleeType = resolveDependentExprToType(CE->getCallee()); + const auto *CalleeType = resolveExprToType(CE->getCallee()); if (!CalleeType) return {}; if (const auto *FnTypePtr = CalleeType->getAs<PointerType>()) @@ -209,15 +208,16 @@ } } } - if (const auto *ME = dyn_cast<MemberExpr>(E)) { + if (const auto *ME = dyn_cast<MemberExpr>(E)) return {ME->getMemberDecl()}; - } + if (const auto *DRE = dyn_cast<DeclRefExpr>(E)) + return {DRE->getFoundDecl()}; return {}; } -// Try to heuristically resolve the type of a dependent expression `E`. -const Type *resolveDependentExprToType(const Expr *E) { - std::vector<const NamedDecl *> Decls = resolveDependentExprToDecls(E); +// Try to heuristically resolve the type of a possibly-dependent expression `E`. +const Type *resolveExprToType(const Expr *E) { + std::vector<const NamedDecl *> Decls = resolveExprToDecls(E); if (Decls.size() != 1) // Names an overload set -- just bail. return nullptr; if (const auto *TD = dyn_cast<TypeDecl>(Decls[0])) { @@ -426,12 +426,12 @@ } void VisitCXXDependentScopeMemberExpr(const CXXDependentScopeMemberExpr *E) { - for (const NamedDecl *D : resolveDependentExprToDecls(E)) { + for (const NamedDecl *D : resolveExprToDecls(E)) { Outer.add(D, Flags); } } void VisitDependentScopeDeclRefExpr(const DependentScopeDeclRefExpr *E) { - for (const NamedDecl *D : resolveDependentExprToDecls(E)) { + for (const NamedDecl *D : resolveExprToDecls(E)) { Outer.add(D, Flags); } }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits