[llvm] fc5dcb0 - [llvm-libtool-darwin] Use MapVector to avoid relying on StringMap iteration order
Fangrui Song via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 19 17:22:01 PDT 2023
Author: Fangrui Song
Date: 2023-07-19T17:21:57-07:00
New Revision: fc5dcb0c22e07d76bc64db45a0c1cd584a9f2209
URL: https://github.com/llvm/llvm-project/commit/fc5dcb0c22e07d76bc64db45a0c1cd584a9f2209
DIFF: https://github.com/llvm/llvm-project/commit/fc5dcb0c22e07d76bc64db45a0c1cd584a9f2209.diff
LOG: [llvm-libtool-darwin] Use MapVector to avoid relying on StringMap iteration order
Simplify future changes like D142862 that change the hash function.
Added:
Modified:
llvm/test/tools/llvm-libtool-darwin/archive-flattening.test
llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
Removed:
################################################################################
diff --git a/llvm/test/tools/llvm-libtool-darwin/archive-flattening.test b/llvm/test/tools/llvm-libtool-darwin/archive-flattening.test
index 3b133cdffba161..6782b98bef81cd 100644
--- a/llvm/test/tools/llvm-libtool-darwin/archive-flattening.test
+++ b/llvm/test/tools/llvm-libtool-darwin/archive-flattening.test
@@ -63,12 +63,12 @@
# RUN: FileCheck %s --check-prefix=DUPLICATE-INPUT -DFILEA=%basename_t.tmp-input1.o \
# RUN: -DPATHA=%t-input1.o -DFILEB=%basename_t.tmp-x86_64.bc -DPATHB=%t-x86_64.bc -DPATHCORRECT=%t.correct.ar
-# DUPLICATE-INPUT: warning: file '[[FILEA]]' was specified multiple times.
-# DUPLICATE-INPUT-DAG: [[PATHA]]
-# DUPLICATE-INPUT-DAG: [[PATHCORRECT]]
-# DUPLICATE-INPUT: file '[[FILEB]]' was specified multiple times.
+# DUPLICATE-INPUT: warning: file '[[FILEB]]' was specified multiple times.
# DUPLICATE-INPUT-DAG: [[PATHB]]
# DUPLICATE-INPUT-DAG: [[PATHCORRECT]]
+# DUPLICATE-INPUT: file '[[FILEA]]' was specified multiple times.
+# DUPLICATE-INPUT-DAG: [[PATHA]]
+# DUPLICATE-INPUT-DAG: [[PATHCORRECT]]
## Cannot read archive:
# RUN: echo '!<arch>' > %t-invalid-archive.lib
diff --git a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
index c0f64a28a88d65..9188cada2edb9c 100644
--- a/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
+++ b/llvm/tools/llvm-libtool-darwin/llvm-libtool-darwin.cpp
@@ -11,6 +11,7 @@
//===----------------------------------------------------------------------===//
#include "DependencyInfo.h"
+#include "llvm/ADT/MapVector.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/IR/LLVMContext.h"
#include "llvm/Object/ArchiveWriter.h"
@@ -554,7 +555,7 @@ checkForDuplicates(const MembersPerArchitectureMap &MembersPerArch) {
for (const auto &M : MembersPerArch) {
ArrayRef<NewArchiveMember> Members = M.second.getMembers();
ArrayRef<StringRef> Files = M.second.getFiles();
- StringMap<std::vector<StringRef>> MembersToFiles;
+ MapVector<StringRef, SmallVector<StringRef, 1>> MembersToFiles;
for (auto Iterators = std::make_pair(Members.begin(), Files.begin());
Iterators.first != Members.end();
++Iterators.first, ++Iterators.second) {
@@ -565,12 +566,11 @@ checkForDuplicates(const MembersPerArchitectureMap &MembersPerArch) {
std::string ErrorData;
raw_string_ostream ErrorStream(ErrorData);
- for (const auto &MemberToFile : MembersToFiles) {
- if (MemberToFile.getValue().size() > 1) {
- ErrorStream << "file '" << MemberToFile.getKey().str()
- << "' was specified multiple times.\n";
+ for (const auto &[Key, Value] : MembersToFiles) {
+ if (Value.size() > 1) {
+ ErrorStream << "file '" << Key << "' was specified multiple times.\n";
- for (StringRef OriginalFile : MemberToFile.getValue())
+ for (StringRef OriginalFile : Value)
ErrorStream << "in: " << OriginalFile.str() << '\n';
ErrorStream << '\n';
More information about the llvm-commits
mailing list