[PATCH] D146634: [clang][USR] Prevent crashes when parameter lists have nulls

Kadir Cetinkaya via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Mar 28 01:50:01 PDT 2023


kadircet updated this revision to Diff 508934.
kadircet added a comment.
Herald added a project: clang-tools-extra.

- Add test


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D146634/new/

https://reviews.llvm.org/D146634

Files:
  clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
  clang/lib/Index/USRGeneration.cpp


Index: clang/lib/Index/USRGeneration.cpp
===================================================================
--- clang/lib/Index/USRGeneration.cpp
+++ clang/lib/Index/USRGeneration.cpp
@@ -262,6 +262,12 @@
 
   // Mangle in type information for the arguments.
   for (auto *PD : D->parameters()) {
+    // FIXME: Make sure we don't have nullptrs in parameter lists of function
+    // decls.
+    if (!PD) {
+      IgnoreResults = true;
+      return;
+    }
     Out << '#';
     VisitType(PD->getType());
   }
Index: clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
===================================================================
--- clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
+++ clang-tools-extra/clangd/unittests/CodeCompleteTests.cpp
@@ -4002,6 +4002,19 @@
   EXPECT_EQ(Second.activeParameter, 1);
 }
 
+TEST(CompletionTest, NoCrashTests) {
+  llvm::StringLiteral Cases[] = {
+      R"cpp(
+    template <typename = int> struct Foo {};
+    auto a = [x(3)](Foo<^>){};
+    )cpp",
+  };
+  for (auto Case : Cases) {
+    SCOPED_TRACE(Case);
+    auto Completions = completions(Case);
+  }
+}
+
 } // namespace
 } // namespace clangd
 } // namespace clang


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D146634.508934.patch
Type: text/x-patch
Size: 1186 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230328/6296996a/attachment.bin>


More information about the cfe-commits mailing list