Skip to content

[clangd] Support operators new and delete in textDocument/references #135620

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2025

Conversation

ckandeler
Copy link
Member

No description provided.

@llvmbot llvmbot added clang Clang issues not falling into any other category clang-tools-extra clangd labels Apr 14, 2025
@llvmbot
Copy link
Member

llvmbot commented Apr 14, 2025

@llvm/pr-subscribers-clangd
@llvm/pr-subscribers-clang-tools-extra

@llvm/pr-subscribers-clang

Author: Christian Kandeler (ckandeler)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/135620.diff

2 Files Affected:

  • (modified) clang-tools-extra/clangd/unittests/XRefsTests.cpp (+9-1)
  • (modified) clang/lib/Index/IndexBody.cpp (+14)
diff --git a/clang-tools-extra/clangd/unittests/XRefsTests.cpp b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
index 693e965e78a96..1892f87c8e82a 100644
--- a/clang-tools-extra/clangd/unittests/XRefsTests.cpp
+++ b/clang-tools-extra/clangd/unittests/XRefsTests.cpp
@@ -2303,7 +2303,15 @@ TEST(FindReferences, WithinAST) {
         bool $decl[[operator]]"" _u^dl(unsigned long long value);
         bool x = $(x)[[1_udl]];
       )cpp",
-  };
+      R"cpp(
+        struct S {
+        public:
+          static void $decl(S)[[operator]] delete(void *);
+          static void deleteObject(S *S) {
+            $(S::deleteObject)[[de^lete]] S;
+          }
+        };
+      )cpp"};
   for (const char *Test : Tests)
     checkFindRefs(Test);
 }
diff --git a/clang/lib/Index/IndexBody.cpp b/clang/lib/Index/IndexBody.cpp
index 5e69987820730..2ed20df22bda0 100644
--- a/clang/lib/Index/IndexBody.cpp
+++ b/clang/lib/Index/IndexBody.cpp
@@ -153,6 +153,20 @@ class BodyIndexer : public RecursiveASTVisitor<BodyIndexer> {
                                     ParentDC);
   }
 
+  bool VisitCXXNewExpr(CXXNewExpr *E) {
+    if (E->isGlobalNew() || !E->getOperatorNew())
+      return true;
+    return IndexCtx.handleReference(E->getOperatorNew(), E->getBeginLoc(),
+                                    Parent, ParentDC);
+  }
+
+  bool VisitCXXDeleteExpr(CXXDeleteExpr *E) {
+    if (E->isGlobalDelete() || !E->getOperatorDelete())
+      return true;
+    return IndexCtx.handleReference(E->getOperatorDelete(), E->getBeginLoc(),
+                                    Parent, ParentDC);
+  }
+
   bool VisitLabelStmt(LabelStmt *S) {
     if (IndexCtx.shouldIndexFunctionLocalSymbols())
       return IndexCtx.handleDecl(S->getDecl());

Copy link
Collaborator

@HighCommander4 HighCommander4 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@ckandeler ckandeler merged commit a35f940 into llvm:main Apr 22, 2025
14 of 15 checks passed
@llvm-ci
Copy link
Collaborator

llvm-ci commented Apr 22, 2025

LLVM Buildbot has detected a new failure on builder openmp-clang-x86_64-linux-debian running on gribozavr4 while building clang-tools-extra,clang at step 6 "test-openmp".

Full details are available at: https://lab.llvm.org/buildbot/#/builders/6/builds/8542

Here is the relevant piece of the build log for the reference
Step 6 (test-openmp) failure: test (failure)
******************** TEST 'libomp :: tasking/issue-94260-2.c' FAILED ********************
Exit Code: -11

Command Output (stdout):
--
# RUN: at line 1
/b/1/openmp-clang-x86_64-linux-debian/llvm.build/./bin/clang -fopenmp   -I /b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test -L /b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src  -fno-omit-frame-pointer -I /b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test/ompt /b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic && /b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# executed command: /b/1/openmp-clang-x86_64-linux-debian/llvm.build/./bin/clang -fopenmp -I /b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -I /b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test -L /b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/src -fno-omit-frame-pointer -I /b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test/ompt /b/1/openmp-clang-x86_64-linux-debian/llvm.src/openmp/runtime/test/tasking/issue-94260-2.c -o /b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp -lm -latomic
# executed command: /b/1/openmp-clang-x86_64-linux-debian/llvm.build/runtimes/runtimes-bins/openmp/runtime/test/tasking/Output/issue-94260-2.c.tmp
# note: command had no output on stdout or stderr
# error: command failed with exit status: -11

--

********************


IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
IanWood1 pushed a commit to IanWood1/llvm-project that referenced this pull request May 6, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang Clang issues not falling into any other category clang-tools-extra clangd
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants