Skip to content

Commit 75d7180

Browse files
committed
[VirtualFileSystem] Use map to stabilize iteration order
StringMap iteration order is not guaranteed to be deterministic (https://llvm.org/docs/ProgrammersManual.html#llvm-adt-stringmap-h). Tested by `TEST_F(InMemoryFileSystemTest, DirectoryIteration)`.
1 parent 721571b commit 75d7180

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

llvm/lib/Support/VirtualFileSystem.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
#include <cstdint>
4444
#include <iterator>
4545
#include <limits>
46+
#include <map>
4647
#include <memory>
4748
#include <optional>
4849
#include <string>
@@ -725,7 +726,7 @@ class InMemoryFileAdaptor : public File {
725726

726727
class InMemoryDirectory : public InMemoryNode {
727728
Status Stat;
728-
llvm::StringMap<std::unique_ptr<InMemoryNode>> Entries;
729+
std::map<std::string, std::unique_ptr<InMemoryNode>> Entries;
729730

730731
public:
731732
InMemoryDirectory(Status Stat)
@@ -741,7 +742,7 @@ class InMemoryDirectory : public InMemoryNode {
741742
UniqueID getUniqueID() const { return Stat.getUniqueID(); }
742743

743744
InMemoryNode *getChild(StringRef Name) const {
744-
auto I = Entries.find(Name);
745+
auto I = Entries.find(Name.str());
745746
if (I != Entries.end())
746747
return I->second.get();
747748
return nullptr;

0 commit comments

Comments
 (0)