[clang-tools-extra] 5191f70 - [clangd] Support new/deleta operator in TargetFinder.
Haojian Wu via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 3 05:10:32 PDT 2020
Author: Haojian Wu
Date: 2020-08-03T14:10:21+02:00
New Revision: 5191f70ab1f4b0b9225b2e9e11584e199172418c
URL: https://github.com/llvm/llvm-project/commit/5191f70ab1f4b0b9225b2e9e11584e199172418c
DIFF: https://github.com/llvm/llvm-project/commit/5191f70ab1f4b0b9225b2e9e11584e199172418c.diff
LOG: [clangd] Support new/deleta operator in TargetFinder.
Differential Revision: https://reviews.llvm.org/D85028
Added:
Modified:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/XRefs.cpp
clang-tools-extra/clangd/unittests/FindTargetTests.cpp
Removed:
################################################################################
diff --git a/clang-tools-extra/clangd/FindTarget.cpp b/clang-tools-extra/clangd/FindTarget.cpp
index a346d6b662e9..e4d2dddb4b5d 100644
--- a/clang-tools-extra/clangd/FindTarget.cpp
+++ b/clang-tools-extra/clangd/FindTarget.cpp
@@ -460,6 +460,12 @@ struct TargetFinder {
void VisitPseudoObjectExpr(const PseudoObjectExpr *POE) {
Outer.add(POE->getSyntacticForm(), Flags);
}
+ void VisitCXXNewExpr(const CXXNewExpr *CNE) {
+ Outer.add(CNE->getOperatorNew(), Flags);
+ }
+ void VisitCXXDeleteExpr(const CXXDeleteExpr *CDE) {
+ Outer.add(CDE->getOperatorDelete(), Flags);
+ }
};
Visitor(*this, Flags).Visit(S);
}
diff --git a/clang-tools-extra/clangd/XRefs.cpp b/clang-tools-extra/clangd/XRefs.cpp
index 1fc89f3e0847..26653aa409d7 100644
--- a/clang-tools-extra/clangd/XRefs.cpp
+++ b/clang-tools-extra/clangd/XRefs.cpp
@@ -238,6 +238,10 @@ locateASTReferent(SourceLocation CurLoc, const syntax::Token *TouchedIdentifier,
llvm::DenseMap<SymbolID, size_t> ResultIndex;
auto AddResultDecl = [&](const NamedDecl *D) {
+ // FIXME: Canonical declarations of some symbols might refer to built-in
+ // decls with possibly-invalid source locations (e.g. global new operator).
+ // In such cases we should pick up a redecl with valid source location
+ // instead of failing.
D = llvm::cast<NamedDecl>(D->getCanonicalDecl());
auto Loc =
makeLocation(AST.getASTContext(), nameLocation(*D, SM), MainFilePath);
diff --git a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
index 92095e871e20..8b872d6314d4 100644
--- a/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
+++ b/clang-tools-extra/clangd/unittests/FindTargetTests.cpp
@@ -535,6 +535,7 @@ TEST_F(TargetDeclTest, OverloadExpr) {
// FIXME: Auto-completion in a template requires disabling delayed template
// parsing.
Flags = {"-fno-delayed-template-parsing"};
+ Flags.push_back("--target=x86_64-pc-linux-gnu");
Code = R"cpp(
void func(int*);
@@ -559,6 +560,36 @@ TEST_F(TargetDeclTest, OverloadExpr) {
};
)cpp";
EXPECT_DECLS("UnresolvedMemberExpr", "void func(int *)", "void func(char *)");
+
+ Code = R"cpp(
+ struct X {
+ static void *operator new(unsigned long);
+ };
+ auto* k = [[new]] X();
+ )cpp";
+ EXPECT_DECLS("CXXNewExpr", "static void *operator new(unsigned long)");
+ Code = R"cpp(
+ void *operator new(unsigned long);
+ auto* k = [[new]] int();
+ )cpp";
+ EXPECT_DECLS("CXXNewExpr", "void *operator new(unsigned long)");
+
+ Code = R"cpp(
+ struct X {
+ static void operator delete(void *) noexcept;
+ };
+ void k(X* x) {
+ [[delete]] x;
+ }
+ )cpp";
+ EXPECT_DECLS("CXXDeleteExpr", "static void operator delete(void *) noexcept");
+ Code = R"cpp(
+ void operator delete(void *) noexcept;
+ void k(int* x) {
+ [[delete]] x;
+ }
+ )cpp";
+ EXPECT_DECLS("CXXDeleteExpr", "void operator delete(void *) noexcept");
}
TEST_F(TargetDeclTest, DependentExprs) {
More information about the cfe-commits
mailing list