This revision was automatically updated to reflect the committed changes. sammccall marked an inline comment as done. Closed by commit rL357186: Disable warnings when indexing as a standalone action. (authored by sammccall, committed by ). Herald added a project: LLVM. Herald added a subscriber: llvm-commits.
Changed prior to commit: https://reviews.llvm.org/D59935?vs=192651&id=192672#toc Repository: rL LLVM CHANGES SINCE LAST ACTION https://reviews.llvm.org/D59935/new/ https://reviews.llvm.org/D59935 Files: clang-tools-extra/trunk/clangd/index/IndexAction.cpp clang-tools-extra/trunk/unittests/clangd/IndexActionTests.cpp Index: clang-tools-extra/trunk/unittests/clangd/IndexActionTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/IndexActionTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/IndexActionTests.cpp @@ -29,6 +29,8 @@ MATCHER_P(HasDigest, Digest, "") { return arg.Digest == Digest; } +MATCHER_P(HasName, Name, "") { return arg.Name == Name; } + MATCHER(HasSameURI, "") { llvm::StringRef URI = testing::get<0>(arg); const std::string &Path = testing::get<1>(arg); @@ -43,6 +45,7 @@ void checkNodesAreInitialized(const IndexFileIn &IndexFile, const std::vector<std::string> &Paths) { + ASSERT_TRUE(IndexFile.Sources); EXPECT_THAT(Paths.size(), IndexFile.Sources->size()); for (llvm::StringRef Path : Paths) { auto URI = toUri(Path); @@ -224,6 +227,27 @@ HasDigest(digest(HeaderCode)))))); } +TEST_F(IndexActionTest, NoWarnings) { + std::string MainFilePath = testPath("main.cpp"); + std::string MainCode = R"cpp( + void foo(int x) { + if (x = 1) // -Wparentheses + return; + if (x = 1) // -Wparentheses + return; + } + void bar() {} + )cpp"; + addFile(MainFilePath, MainCode); + // We set -ferror-limit so the warning-promoted-to-error would be fatal. + // This would cause indexing to stop (if warnings weren't disabled). + IndexFileIn IndexFile = runIndexingAction( + MainFilePath, {"-ferror-limit=1", "-Wparentheses", "-Werror"}); + ASSERT_TRUE(IndexFile.Sources); + ASSERT_NE(0u, IndexFile.Sources->size()); + EXPECT_THAT(*IndexFile.Symbols, ElementsAre(HasName("foo"), HasName("bar"))); +} + } // namespace } // namespace clangd } // namespace clang Index: clang-tools-extra/trunk/clangd/index/IndexAction.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/IndexAction.cpp +++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp @@ -135,6 +135,11 @@ bool BeginInvocation(CompilerInstance &CI) override { // We want all comments, not just the doxygen ones. CI.getLangOpts().CommentOpts.ParseAllComments = true; + // Index the whole file even if there are warnings and -Werror is set. + // Avoids some analyses too. Set in two places as we're late to the party. + CI.getDiagnosticOpts().IgnoreWarnings = true; + CI.getDiagnostics().setIgnoreAllWarnings(true); + return WrapperFrontendAction::BeginInvocation(CI); }
Index: clang-tools-extra/trunk/unittests/clangd/IndexActionTests.cpp =================================================================== --- clang-tools-extra/trunk/unittests/clangd/IndexActionTests.cpp +++ clang-tools-extra/trunk/unittests/clangd/IndexActionTests.cpp @@ -29,6 +29,8 @@ MATCHER_P(HasDigest, Digest, "") { return arg.Digest == Digest; } +MATCHER_P(HasName, Name, "") { return arg.Name == Name; } + MATCHER(HasSameURI, "") { llvm::StringRef URI = testing::get<0>(arg); const std::string &Path = testing::get<1>(arg); @@ -43,6 +45,7 @@ void checkNodesAreInitialized(const IndexFileIn &IndexFile, const std::vector<std::string> &Paths) { + ASSERT_TRUE(IndexFile.Sources); EXPECT_THAT(Paths.size(), IndexFile.Sources->size()); for (llvm::StringRef Path : Paths) { auto URI = toUri(Path); @@ -224,6 +227,27 @@ HasDigest(digest(HeaderCode)))))); } +TEST_F(IndexActionTest, NoWarnings) { + std::string MainFilePath = testPath("main.cpp"); + std::string MainCode = R"cpp( + void foo(int x) { + if (x = 1) // -Wparentheses + return; + if (x = 1) // -Wparentheses + return; + } + void bar() {} + )cpp"; + addFile(MainFilePath, MainCode); + // We set -ferror-limit so the warning-promoted-to-error would be fatal. + // This would cause indexing to stop (if warnings weren't disabled). + IndexFileIn IndexFile = runIndexingAction( + MainFilePath, {"-ferror-limit=1", "-Wparentheses", "-Werror"}); + ASSERT_TRUE(IndexFile.Sources); + ASSERT_NE(0u, IndexFile.Sources->size()); + EXPECT_THAT(*IndexFile.Symbols, ElementsAre(HasName("foo"), HasName("bar"))); +} + } // namespace } // namespace clangd } // namespace clang Index: clang-tools-extra/trunk/clangd/index/IndexAction.cpp =================================================================== --- clang-tools-extra/trunk/clangd/index/IndexAction.cpp +++ clang-tools-extra/trunk/clangd/index/IndexAction.cpp @@ -135,6 +135,11 @@ bool BeginInvocation(CompilerInstance &CI) override { // We want all comments, not just the doxygen ones. CI.getLangOpts().CommentOpts.ParseAllComments = true; + // Index the whole file even if there are warnings and -Werror is set. + // Avoids some analyses too. Set in two places as we're late to the party. + CI.getDiagnosticOpts().IgnoreWarnings = true; + CI.getDiagnostics().setIgnoreAllWarnings(true); + return WrapperFrontendAction::BeginInvocation(CI); }
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits