Skip to content

Commit fc5dcb0

Browse files
committed
[llvm-libtool-darwin] Use MapVector to avoid relying on StringMap iteration order
Simplify future changes like D142862 that change the hash function.
1 parent ba877dc commit fc5dcb0

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

llvm/test/tools/llvm-libtool-darwin/archive-flattening.test

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,12 +63,12 @@
6363
# RUN: FileCheck %s --check-prefix=DUPLICATE-INPUT -DFILEA=%basename_t.tmp-input1.o \
6464
# RUN: -DPATHA=%t-input1.o -DFILEB=%basename_t.tmp-x86_64.bc -DPATHB=%t-x86_64.bc -DPATHCORRECT=%t.correct.ar
6565

66-
# DUPLICATE-INPUT: warning: file '[[FILEA]]' was specified multiple times.
67-
# DUPLICATE-INPUT-DAG: [[PATHA]]
68-
# DUPLICATE-INPUT-DAG: [[PATHCORRECT]]
69-
# DUPLICATE-INPUT: file '[[FILEB]]' was specified multiple times.
66+
# DUPLICATE-INPUT: warning: file '[[FILEB]]' was specified multiple times.
7067
# DUPLICATE-INPUT-DAG: [[PATHB]]
7168
# DUPLICATE-INPUT-DAG: [[PATHCORRECT]]
69+
# DUPLICATE-INPUT: file '[[FILEA]]' was specified multiple times.
70+
# DUPLICATE-INPUT-DAG: [[PATHA]]
71+
# DUPLICATE-INPUT-DAG: [[PATHCORRECT]]
7272

7373
## Cannot read archive:
7474
# RUN: echo '!<arch>' > %t-invalid-archive.lib

llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
//===----------------------------------------------------------------------===//
1212

1313
#include "DependencyInfo.h"
14+
#include "llvm/ADT/MapVector.h"
1415
#include "llvm/BinaryFormat/Magic.h"
1516
#include "llvm/IR/LLVMContext.h"
1617
#include "llvm/Object/ArchiveWriter.h"
@@ -554,7 +555,7 @@ checkForDuplicates(const MembersPerArchitectureMap &MembersPerArch) {
554555
for (const auto &M : MembersPerArch) {
555556
ArrayRef<NewArchiveMember> Members = M.second.getMembers();
556557
ArrayRef<StringRef> Files = M.second.getFiles();
557-
StringMap<std::vector<StringRef>> MembersToFiles;
558+
MapVector<StringRef, SmallVector<StringRef, 1>> MembersToFiles;
558559
for (auto Iterators = std::make_pair(Members.begin(), Files.begin());
559560
Iterators.first != Members.end();
560561
++Iterators.first, ++Iterators.second) {
@@ -565,12 +566,11 @@ checkForDuplicates(const MembersPerArchitectureMap &MembersPerArch) {
565566

566567
std::string ErrorData;
567568
raw_string_ostream ErrorStream(ErrorData);
568-
for (const auto &MemberToFile : MembersToFiles) {
569-
if (MemberToFile.getValue().size() > 1) {
570-
ErrorStream << "file '" << MemberToFile.getKey().str()
571-
<< "' was specified multiple times.\n";
569+
for (const auto &[Key, Value] : MembersToFiles) {
570+
if (Value.size() > 1) {
571+
ErrorStream << "file '" << Key << "' was specified multiple times.\n";
572572

573-
for (StringRef OriginalFile : MemberToFile.getValue())
573+
for (StringRef OriginalFile : Value)
574574
ErrorStream << "in: " << OriginalFile.str() << '\n';
575575

576576
ErrorStream << '\n';

0 commit comments

Comments
 (0)