diff options
author | Hans Wennborg <hans@hanshq.net> | 2019-08-13 12:39:23 +0000 |
---|---|---|
committer | Hans Wennborg <hans@hanshq.net> | 2019-08-13 12:39:23 +0000 |
commit | f44fc8869c1609ab5235a00ec748175dd0f1cf18 (patch) | |
tree | 61c3d616be9a28969132f3a98f18ce14ecdb94c8 /clang-tools-extra | |
parent | fcfd891f22aa593a659b866f8d834ded64285b03 (diff) | |
download | llvm-llvmorg-9.0.0-rc2.zip llvm-llvmorg-9.0.0-rc2.tar.gz llvm-llvmorg-9.0.0-rc2.tar.bz2 |
Merging r368549:llvmorg-9.0.0-rc2
------------------------------------------------------------------------
r368549 | hokein | 2019-08-12 11:35:04 +0200 (Mon, 12 Aug 2019) | 11 lines
[clangd] Drop diags from non-written #include.
Summary: This would fix that we show weird diagnostics on random lines of the main file.
Reviewers: ilya-biryukov
Subscribers: MaskRay, jkorous, arphaman, kadircet, cfe-commits
Tags: #clang
Differential Revision: https://reviews.llvm.org/D66074
------------------------------------------------------------------------
llvm-svn: 368683
Diffstat (limited to 'clang-tools-extra')
-rw-r--r-- | clang-tools-extra/clangd/Diagnostics.cpp | 8 | ||||
-rw-r--r-- | clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp | 9 |
2 files changed, 15 insertions, 2 deletions
diff --git a/clang-tools-extra/clangd/Diagnostics.cpp b/clang-tools-extra/clangd/Diagnostics.cpp index 919182d..7f1ab06 100644 --- a/clang-tools-extra/clangd/Diagnostics.cpp +++ b/clang-tools-extra/clangd/Diagnostics.cpp @@ -122,8 +122,12 @@ bool adjustDiagFromHeader(Diag &D, const clang::Diagnostic &Info, return SM.getIncludeLoc(SM.getFileID(SLoc)); }; for (auto IncludeLocation = GetIncludeLoc(DiagLoc); IncludeLocation.isValid(); - IncludeLocation = GetIncludeLoc(IncludeLocation)) - IncludeInMainFile = IncludeLocation; + IncludeLocation = GetIncludeLoc(IncludeLocation)) { + if (clangd::isInsideMainFile(IncludeLocation, SM)) { + IncludeInMainFile = IncludeLocation; + break; + } + } if (IncludeInMainFile.isInvalid()) return false; diff --git a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp index c80dafe..2089c89 100644 --- a/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp +++ b/clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp @@ -948,6 +948,15 @@ TEST(IgnoreDiags, FromNonWrittenSources) { EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); } +TEST(IgnoreDiags, FromNonWrittenInclude) { + TestTU TU = TestTU::withCode(""); + TU.ExtraArgs.push_back("--include=a.h"); + TU.AdditionalFiles = {{"a.h", "void main();"}}; + // The diagnostic "main must return int" is from the header, we don't attempt + // to render it in the main file as there is no written location there. + EXPECT_THAT(TU.build().getDiagnostics(), UnorderedElementsAre()); +} + } // namespace } // namespace clangd |