This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rG0d1be98a67e2: [clang][USR] Prevent crashes on incomplete FunctionDecls (authored by kadircet).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D149733/new/ https://reviews.llvm.org/D149733 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 @@ -226,6 +226,11 @@ if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D))) return; + if (D->getType().isNull()) { + IgnoreResults = true; + return; + } + const unsigned StartSize = Buf.size(); VisitDeclContext(D->getDeclContext()); if (Buf.size() == StartSize) 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, DoNotCrash) { + 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
Index: clang/lib/Index/USRGeneration.cpp =================================================================== --- clang/lib/Index/USRGeneration.cpp +++ clang/lib/Index/USRGeneration.cpp @@ -226,6 +226,11 @@ if (ShouldGenerateLocation(D) && GenLoc(D, /*IncludeOffset=*/isLocal(D))) return; + if (D->getType().isNull()) { + IgnoreResults = true; + return; + } + const unsigned StartSize = Buf.size(); VisitDeclContext(D->getDeclContext()); if (Buf.size() == StartSize) 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, DoNotCrash) { + 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
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits