From cc2d4dc3e0ccb50e341f4ea301087bdd14be78a7 Mon Sep 17 00:00:00 2001 From: Nico Weber Date: Thu, 2 Sep 2021 12:09:43 -0700 Subject: [PATCH] Reland "Try to unbreak Win build differently after 973519826edb76"" Build should be fixed by https://github.com/llvm/llvm-project/commit/9d22754389 This reverts commit df052e1732ab57f5d9c684ceeaed3ab39073cd9f. Differential Revision: https://reviews.llvm.org/D109181 --- clang/lib/Driver/ToolChains/Arch/X86.cpp | 5 ++--- llvm/include/llvm/ADT/StringMap.h | 8 +------- llvm/unittests/ADT/StringMapTest.cpp | 16 +++++++++++++++- 3 files changed, 18 insertions(+), 11 deletions(-) diff --git a/clang/lib/Driver/ToolChains/Arch/X86.cpp b/clang/lib/Driver/ToolChains/Arch/X86.cpp index 2e43c45..bfa008f 100644 --- a/clang/lib/Driver/ToolChains/Arch/X86.cpp +++ b/clang/lib/Driver/ToolChains/Arch/X86.cpp @@ -59,9 +59,8 @@ std::string x86::getX86TargetCPU(const Driver &D, const ArgList &Args, } StringRef CPU = ArchMap.lookup(A->getValue()); if (CPU.empty()) { - std::vector ValidArchs; - for (StringRef Key : ArchMap.keys()) - ValidArchs.push_back(Key); + std::vector ValidArchs{ArchMap.keys().begin(), + ArchMap.keys().end()}; sort(ValidArchs); D.Diag(diag::warn_drv_invalid_arch_name_with_suggestion) << A->getValue() << (Triple.getArch() == llvm::Triple::x86) diff --git a/llvm/include/llvm/ADT/StringMap.h b/llvm/include/llvm/ADT/StringMap.h index 003e62d..669956d 100644 --- a/llvm/include/llvm/ADT/StringMap.h +++ b/llvm/include/llvm/ADT/StringMap.h @@ -478,13 +478,7 @@ public: explicit StringMapKeyIterator(StringMapConstIterator Iter) : base(std::move(Iter)) {} - StringRef &operator*() { - Key = this->wrapped()->getKey(); - return Key; - } - -private: - StringRef Key; + StringRef operator*() const { return this->wrapped()->getKey(); } }; } // end namespace llvm diff --git a/llvm/unittests/ADT/StringMapTest.cpp b/llvm/unittests/ADT/StringMapTest.cpp index 6a3cca5..f38a604 100644 --- a/llvm/unittests/ADT/StringMapTest.cpp +++ b/llvm/unittests/ADT/StringMapTest.cpp @@ -308,7 +308,21 @@ TEST_F(StringMapTest, InsertOrAssignTest) { EXPECT_EQ(0, try1.first->second.copy); } -TEST_F(StringMapTest, IterMapKeys) { +TEST_F(StringMapTest, IterMapKeysVector) { + StringMap Map; + Map["A"] = 1; + Map["B"] = 2; + Map["C"] = 3; + Map["D"] = 3; + + std::vector Keys{Map.keys().begin(), Map.keys().end()}; + llvm::sort(Keys); + + std::vector Expected{{"A", "B", "C", "D"}}; + EXPECT_EQ(Expected, Keys); +} + +TEST_F(StringMapTest, IterMapKeysSmallVector) { StringMap Map; Map["A"] = 1; Map["B"] = 2; -- 2.7.4