Skip to content

Commit

Permalink
Merging r368549:
Browse files Browse the repository at this point in the history
------------------------------------------------------------------------
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
  • Loading branch information
zmodem committed Aug 13, 2019
1 parent fcfd891 commit f44fc88
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
8 changes: 6 additions & 2 deletions clang-tools-extra/clangd/Diagnostics.cpp
Expand Up @@ -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;

Expand Down
9 changes: 9 additions & 0 deletions clang-tools-extra/clangd/unittests/DiagnosticsTests.cpp
Expand Up @@ -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
Expand Down

0 comments on commit f44fc88

Please sign in to comment.