summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHans Wennborg <hans@hanshq.net>2019-08-13 12:39:23 +0000
committerHans Wennborg <hans@hanshq.net>2019-08-13 12:39:23 +0000
commitac739170c2e9dc4b7c15af6809a7a04c713b219f (patch)
tree9444bdd61c9766c27e53fef39260965ea4d44e9f
parent9ad41b82f62c94f822190536e6b537ceca1cef8a (diff)
Merging r368549:
------------------------------------------------------------------------ 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 ------------------------------------------------------------------------ git-svn-id: https://llvm.org/svn/llvm-project/clang-tools-extra/branches/release_90@368683 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--clangd/Diagnostics.cpp8
-rw-r--r--clangd/unittests/DiagnosticsTests.cpp9
2 files changed, 15 insertions, 2 deletions
diff --git a/clangd/Diagnostics.cpp b/clangd/Diagnostics.cpp
index 919182d5..7f1ab06d 100644
--- a/clangd/Diagnostics.cpp
+++ b/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/clangd/unittests/DiagnosticsTests.cpp b/clangd/unittests/DiagnosticsTests.cpp
index c80dafee..2089c89e 100644
--- a/clangd/unittests/DiagnosticsTests.cpp
+++ b/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