[PATCH] D85028: [clangd] Support new/delete operator in TargetFinder.
Haojian Wu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Aug 3 05:10:44 PDT 2020
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG5191f70ab1f4: [clangd] Support new/deleta operator in TargetFinder. (authored by hokein).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D85028/new/
https://reviews.llvm.org/D85028
Files:
clang-tools-extra/clangd/FindTarget.cpp
clang-tools-extra/clangd/XRefs.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
@@ -535,6 +535,7 @@
// 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 @@
};
)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) {
Index: clang-tools-extra/clangd/XRefs.cpp
===================================================================
--- clang-tools-extra/clangd/XRefs.cpp
+++ clang-tools-extra/clangd/XRefs.cpp
@@ -238,6 +238,10 @@
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);
Index: clang-tools-extra/clangd/FindTarget.cpp
===================================================================
--- clang-tools-extra/clangd/FindTarget.cpp
+++ clang-tools-extra/clangd/FindTarget.cpp
@@ -460,6 +460,12 @@
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);
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D85028.282591.patch
Type: text/x-patch
Size: 2828 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20200803/a1909701/attachment-0001.bin>
More information about the cfe-commits
mailing list