From d084c42bdfac4a5879bdabe645b14cf72f7685a7 Mon Sep 17 00:00:00 2001 From: Kirill Bobyrev Date: Thu, 30 Sep 2021 09:49:27 +0200 Subject: [PATCH] Investigate failure in rGdd13f45e04366cc4f648b57ec87d20a5569e27c3 https://lab.llvm.org/buildbot/#/builders/123/builds/6406/steps/8/logs/stdio --- clang-tools-extra/clangd/Headers.cpp | 4 +++- clang-tools-extra/clangd/Headers.h | 8 ++++++++ clang-tools-extra/clangd/unittests/HeadersTests.cpp | 17 ++++++++++------- clang-tools-extra/clangd/unittests/ParsedASTTests.cpp | 2 +- 4 files changed, 22 insertions(+), 9 deletions(-) diff --git a/clang-tools-extra/clangd/Headers.cpp b/clang-tools-extra/clangd/Headers.cpp index 33304b8..0b189e5 100644 --- a/clang-tools-extra/clangd/Headers.cpp +++ b/clang-tools-extra/clangd/Headers.cpp @@ -168,8 +168,10 @@ IncludeStructure::getOrCreateID(const FileEntry *Entry) { auto R = NameToIndex.try_emplace( Entry->getName(), static_cast(RealPathNames.size())); - if (R.second) + if (R.second) { RealPathNames.emplace_back(); + FileEntryIDs.push_back(Entry->getUID()); + } IncludeStructure::HeaderID Result = R.first->getValue(); std::string &RealPathName = RealPathNames[static_cast(Result)]; if (RealPathName.empty()) diff --git a/clang-tools-extra/clangd/Headers.h b/clang-tools-extra/clangd/Headers.h index 86294b9..f322529 100644 --- a/clang-tools-extra/clangd/Headers.h +++ b/clang-tools-extra/clangd/Headers.h @@ -141,8 +141,16 @@ public: std::vector MainFileIncludes; + std::string dump() { + return "RealPathNames: " + + llvm::join(RealPathNames.begin(), RealPathNames.end(), ", ") + + "\nFileEntryIDs: " + + llvm::join(FileEntryIDs.begin(), FileEntryIDs.end(), ", ") + '\n'; + } + private: std::vector RealPathNames; // In HeaderID order. + std::vector FileEntryIDs; // In HeaderID order. // HeaderID maps the FileEntry::Name to the internal representation. // Identifying files in a way that persists from preamble build to subsequent // builds is surprisingly hard. FileID is unavailable in diff --git a/clang-tools-extra/clangd/unittests/HeadersTests.cpp b/clang-tools-extra/clangd/unittests/HeadersTests.cpp index 8a6f5e8..f6f1f4a 100644 --- a/clang-tools-extra/clangd/unittests/HeadersTests.cpp +++ b/clang-tools-extra/clangd/unittests/HeadersTests.cpp @@ -165,7 +165,8 @@ TEST_F(HeadersTest, CollectRewrittenAndResolved) { AllOf(Written("\"sub/bar.h\""), Resolved(BarHeader)))); EXPECT_THAT(Includes.includeDepth(getID(MainFile, Includes)), UnorderedElementsAre(Distance(getID(MainFile, Includes), 0u), - Distance(getID(BarHeader, Includes), 1u))); + Distance(getID(BarHeader, Includes), 1u))) + << Includes.dump(); } TEST_F(HeadersTest, OnlyCollectInclusionsInMain) { @@ -179,17 +180,19 @@ TEST_F(HeadersTest, OnlyCollectInclusionsInMain) { #include "bar.h" )cpp"; auto Includes = collectIncludes(); - EXPECT_THAT(Includes.MainFileIncludes, - UnorderedElementsAre( - AllOf(Written("\"bar.h\""), Resolved(BarHeader)))); + EXPECT_THAT( + Includes.MainFileIncludes, + UnorderedElementsAre(AllOf(Written("\"bar.h\""), Resolved(BarHeader)))); EXPECT_THAT(Includes.includeDepth(getID(MainFile, Includes)), UnorderedElementsAre(Distance(getID(MainFile, Includes), 0u), Distance(getID(BarHeader, Includes), 1u), - Distance(getID(BazHeader, Includes), 2u))); + Distance(getID(BazHeader, Includes), 2u))) + << Includes.dump(); // includeDepth() also works for non-main files. EXPECT_THAT(Includes.includeDepth(getID(BarHeader, Includes)), UnorderedElementsAre(Distance(getID(BarHeader, Includes), 0u), - Distance(getID(BazHeader, Includes), 1u))); + Distance(getID(BazHeader, Includes), 1u))) + << Includes.dump(); } TEST_F(HeadersTest, PreambleIncludesPresentOnce) { @@ -240,7 +243,7 @@ TEST_F(HeadersTest, IncludedFilesGraph) { {getID(BarHeader, Includes), getID(FooHeader, Includes)}}, {getID(FooHeader, Includes), {getID(BarHeader, Includes), getID(BazHeader, Includes)}}}; - EXPECT_EQ(Includes.IncludeChildren, Expected); + EXPECT_EQ(Includes.IncludeChildren, Expected) << Includes.dump(); } TEST_F(HeadersTest, IncludeDirective) { diff --git a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp index 9195865..dde3371 100644 --- a/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp +++ b/clang-tools-extra/clangd/unittests/ParsedASTTests.cpp @@ -517,7 +517,7 @@ TEST(ParsedASTTest, PatchesAdditionalIncludes) { ASSERT_TRUE(MainFE); auto MainID = Includes.getID(*MainFE); auto AuxFE = FM.getFile(testPath("sub/aux.h")); - ASSERT_TRUE(AuxFE); + ASSERT_TRUE(AuxFE) << Includes.dump(); auto AuxID = Includes.getID(*AuxFE); EXPECT_THAT(Includes.IncludeChildren[*MainID], Contains(*AuxID)); } -- 2.7.4