Skip to content

Commit 5881dcf

Browse files
committed
Try to unbreak Win build differently after 9735198
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 123f811 which is now hopefully no longer needed. Differential Revision: https://reviews.llvm.org/D109167
1 parent a270de3 commit 5881dcf

File tree

3 files changed

+19
-10
lines changed

3 files changed

+19
-10
lines changed

clang/lib/Driver/ToolChains/Arch/X86.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,8 @@ std::string x86::getX86TargetCPU(const Driver &D, const ArgList &Args,
5959
}
6060
StringRef CPU = ArchMap.lookup(A->getValue());
6161
if (CPU.empty()) {
62-
std::vector<StringRef> ValidArchs;
63-
for (StringRef Key : ArchMap.keys())
64-
ValidArchs.push_back(Key);
62+
std::vector<StringRef> ValidArchs{ArchMap.keys().begin(),
63+
ArchMap.keys().end()};
6564
sort(ValidArchs);
6665
D.Diag(diag::warn_drv_invalid_arch_name_with_suggestion)
6766
<< A->getValue() << (Triple.getArch() == llvm::Triple::x86)

llvm/include/llvm/ADT/StringMap.h

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -478,13 +478,9 @@ class StringMapKeyIterator
478478
explicit StringMapKeyIterator(StringMapConstIterator<ValueTy> Iter)
479479
: base(std::move(Iter)) {}
480480

481-
StringRef &operator*() {
482-
Key = this->wrapped()->getKey();
483-
return Key;
481+
StringRef operator*() const {
482+
return this->wrapped()->getKey();
484483
}
485-
486-
private:
487-
StringRef Key;
488484
};
489485

490486
} // end namespace llvm

llvm/unittests/ADT/StringMapTest.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,7 +308,21 @@ TEST_F(StringMapTest, InsertOrAssignTest) {
308308
EXPECT_EQ(0, try1.first->second.copy);
309309
}
310310

311-
TEST_F(StringMapTest, IterMapKeys) {
311+
TEST_F(StringMapTest, IterMapKeysVector) {
312+
StringMap<int> Map;
313+
Map["A"] = 1;
314+
Map["B"] = 2;
315+
Map["C"] = 3;
316+
Map["D"] = 3;
317+
318+
std::vector<StringRef> Keys{Map.keys().begin(), Map.keys().end()};
319+
llvm::sort(Keys);
320+
321+
std::vector<StringRef> Expected{{"A", "B", "C", "D"}};
322+
EXPECT_EQ(Expected, Keys);
323+
}
324+
325+
TEST_F(StringMapTest, IterMapKeysSmallVector) {
312326
StringMap<int> Map;
313327
Map["A"] = 1;
314328
Map["B"] = 2;

0 commit comments

Comments
 (0)