[PATCH] D109167: Try to unbreak Win build differently after 973519826edb76

Nico Weber via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 2 09:44:38 PDT 2021


thakis created this revision.
thakis added a reviewer: hans.
Herald added subscribers: dexonsmith, mgrang.
thakis requested review of this revision.
Herald added a project: LLVM.

Looks like the MS STL wants StringMapKeyIterator::operator*() to be const.
Return the result by copy instead of reference to do that.
Assigning to a hash map key iterator doesn't make sense anyways.

Also reverts 123f811fe5b0b <https://reviews.llvm.org/rG123f811fe5b0ba33f271c1c6172e6dff1463717a> which is now hopefully no longer needed.


https://reviews.llvm.org/D109167

Files:
  clang/lib/Driver/ToolChains/Arch/X86.cpp
  llvm/include/llvm/ADT/StringMap.h
  llvm/unittests/ADT/StringMapTest.cpp


Index: llvm/unittests/ADT/StringMapTest.cpp
===================================================================
--- llvm/unittests/ADT/StringMapTest.cpp
+++ llvm/unittests/ADT/StringMapTest.cpp
@@ -308,7 +308,21 @@
   EXPECT_EQ(0, try1.first->second.copy);
 }
 
-TEST_F(StringMapTest, IterMapKeys) {
+TEST_F(StringMapTest, IterMapKeysVector) {
+  StringMap<int> Map;
+  Map["A"] = 1;
+  Map["B"] = 2;
+  Map["C"] = 3;
+  Map["D"] = 3;
+
+  std::vector<StringRef> Keys{Map.keys().begin(), Map.keys().end()};
+  llvm::sort(Keys);
+
+  std::vector<StringRef> Expected{{"A", "B", "C", "D"}};
+  EXPECT_EQ(Expected, Keys);
+}
+
+TEST_F(StringMapTest, IterMapKeysSmallVector) {
   StringMap<int> Map;
   Map["A"] = 1;
   Map["B"] = 2;
Index: llvm/include/llvm/ADT/StringMap.h
===================================================================
--- llvm/include/llvm/ADT/StringMap.h
+++ llvm/include/llvm/ADT/StringMap.h
@@ -478,13 +478,9 @@
   explicit StringMapKeyIterator(StringMapConstIterator<ValueTy> Iter)
       : base(std::move(Iter)) {}
 
-  StringRef &operator*() {
-    Key = this->wrapped()->getKey();
-    return Key;
+  StringRef operator*() const {
+    return this->wrapped()->getKey();
   }
-
-private:
-  StringRef Key;
 };
 
 } // end namespace llvm
Index: clang/lib/Driver/ToolChains/Arch/X86.cpp
===================================================================
--- clang/lib/Driver/ToolChains/Arch/X86.cpp
+++ clang/lib/Driver/ToolChains/Arch/X86.cpp
@@ -59,9 +59,8 @@
     }
     StringRef CPU = ArchMap.lookup(A->getValue());
     if (CPU.empty()) {
-      std::vector<StringRef> ValidArchs;
-      for (StringRef Key : ArchMap.keys())
-        ValidArchs.push_back(Key);
+      std::vector<StringRef> 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)


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D109167.370307.patch
Type: text/x-patch
Size: 1981 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210902/15dfbce2/attachment.bin>


More information about the llvm-commits mailing list