[llvm-branch-commits] [clang-tools-extra-branch] r368683 - Merging r368549:

Hans Wennborg via llvm-branch-commits llvm-branch-commits at lists.llvm.org
Tue Aug 13 05:39:23 PDT 2019


Author: hans
Date: Tue Aug 13 05:39:23 2019
New Revision: 368683

URL: http://llvm.org/viewvc/llvm-project?rev=368683&view=rev
Log:
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
------------------------------------------------------------------------

Modified:
    clang-tools-extra/branches/release_90/   (props changed)
    clang-tools-extra/branches/release_90/clangd/Diagnostics.cpp
    clang-tools-extra/branches/release_90/clangd/unittests/DiagnosticsTests.cpp

Propchange: clang-tools-extra/branches/release_90/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Tue Aug 13 05:39:23 2019
@@ -1 +1 @@
-/clang-tools-extra/trunk:366443,366451,366455,366541,366545,366559,366687,366811,366880,366900,366991-366992,367112,367303,367687,368019,368058,368498,368581
+/clang-tools-extra/trunk:366443,366451,366455,366541,366545,366559,366687,366811,366880,366900,366991-366992,367112,367303,367687,368019,368058,368498,368549,368581

Modified: clang-tools-extra/branches/release_90/clangd/Diagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/branches/release_90/clangd/Diagnostics.cpp?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- clang-tools-extra/branches/release_90/clangd/Diagnostics.cpp (original)
+++ clang-tools-extra/branches/release_90/clangd/Diagnostics.cpp Tue Aug 13 05:39:23 2019
@@ -122,8 +122,12 @@ bool adjustDiagFromHeader(Diag &D, const
     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;
 

Modified: clang-tools-extra/branches/release_90/clangd/unittests/DiagnosticsTests.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/branches/release_90/clangd/unittests/DiagnosticsTests.cpp?rev=368683&r1=368682&r2=368683&view=diff
==============================================================================
--- clang-tools-extra/branches/release_90/clangd/unittests/DiagnosticsTests.cpp (original)
+++ clang-tools-extra/branches/release_90/clangd/unittests/DiagnosticsTests.cpp Tue Aug 13 05:39:23 2019
@@ -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




More information about the llvm-branch-commits mailing list