[PATCH] D140379: [clangd] Avoid triggering linkage computation for decl with unstable linkage in SymbolRelevanceSignals::computeASTSignals()

Nathan Ridge via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Dec 20 01:34:13 PST 2022


nridge created this revision.
nridge added a reviewer: sammccall.
Herald added subscribers: kadircet, arphaman.
Herald added a project: All.
nridge requested review of this revision.
Herald added subscribers: cfe-commits, MaskRay, ilya-biryukov.
Herald added a project: clang-tools-extra.

Fixes https://github.com/clangd/clangd/issues/1427


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D140379

Files:
  clang-tools-extra/clangd/Quality.cpp
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp


Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -1100,6 +1100,21 @@
     )cpp");
 }
 
+TEST(CompletionTest, Issue1427Crash) {
+    // Need to provide main file signals to ensure that the branch in
+    // SymbolRelevanceSignals::computeASTSignals() that tries to
+    // compute a symbol ID is taken.
+    ASTSignals MainFileSignals;
+    CodeCompleteOptions Opts;
+    Opts.MainFileSignals = &MainFileSignals;
+    completions(R"cpp(
+      auto f = []() {
+        1.0_^
+      };
+    )cpp",
+                {}, Opts);
+}
+
 TEST(CompletionTest, BacktrackCrashes) {
   // Sema calls code completion callbacks twice in these cases.
   auto Results = completions(R"cpp(
Index: clang-tools-extra/clangd/Quality.cpp
===================================================================
--- clang-tools-extra/clangd/Quality.cpp
+++ clang-tools-extra/clangd/Quality.cpp
@@ -303,6 +303,8 @@
       (SemaResult.Kind != CodeCompletionResult::RK_Pattern))
     return;
   if (const NamedDecl *ND = SemaResult.getDeclaration()) {
+    if (hasUnstableLinkage(ND))
+      return;
     auto ID = getSymbolID(ND);
     if (!ID)
       return;


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D140379.484189.patch
Type: text/x-patch
Size: 1339 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20221220/ddd8c071/attachment.bin>


More information about the cfe-commits mailing list