diff options
author | Sam McCall <sam.mccall@gmail.com> | 2019-03-28 17:07:28 +0000 |
---|---|---|
committer | Sam McCall <sam.mccall@gmail.com> | 2019-03-28 17:07:28 +0000 |
commit | 4180a7cd831537567c9c9eb8528365e3958aed6b (patch) | |
tree | e33ba9dbf6a4a0524b1e96efbd3eb640c867ed90 | |
parent | c694633a12af1312fcafd73d4de57ae40f696595 (diff) | |
download | bcm5719-llvm-4180a7cd831537567c9c9eb8528365e3958aed6b.tar.gz bcm5719-llvm-4180a7cd831537567c9c9eb8528365e3958aed6b.zip |
Disable warnings when indexing as a standalone action.
Summary:
- we don't record the warnings at all
- we don't want to stop indexing if we hit error-limit due to warnings
- this allows some analyses to be skipped which can save some CPU
https://github.com/clangd/clangd/issues/24
Reviewers: hokein
Subscribers: ilya-biryukov, ioeric, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D59935
llvm-svn: 357186
-rw-r--r-- | clang-tools-extra/clangd/index/IndexAction.cpp | 5 | ||||
-rw-r--r-- | clang-tools-extra/unittests/clangd/IndexActionTests.cpp | 24 |
2 files changed, 29 insertions, 0 deletions
diff --git a/clang-tools-extra/clangd/index/IndexAction.cpp b/clang-tools-extra/clangd/index/IndexAction.cpp index bda2cf44a58..120f6b0bae5 100644 --- a/clang-tools-extra/clangd/index/IndexAction.cpp +++ b/clang-tools-extra/clangd/index/IndexAction.cpp @@ -135,6 +135,11 @@ public: 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); } diff --git a/clang-tools-extra/unittests/clangd/IndexActionTests.cpp b/clang-tools-extra/unittests/clangd/IndexActionTests.cpp index 55ec45947e9..a7a9a56e879 100644 --- a/clang-tools-extra/unittests/clangd/IndexActionTests.cpp +++ b/clang-tools-extra/unittests/clangd/IndexActionTests.cpp @@ -29,6 +29,8 @@ MATCHER(IsTU, "") { return arg.IsTU; } 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 @@ IncludesAre(const std::vector<std::string> &Includes) { 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 @@ TEST_F(IndexActionTest, IncludeGraphDynamicInclude) { 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 |