[llvm] r373426 - [llvm-lib] Detect duplicate input files
Rui Ueyama via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 1 23:41:52 PDT 2019
Author: ruiu
Date: Tue Oct 1 23:41:52 2019
New Revision: 373426
URL: http://llvm.org/viewvc/llvm-project?rev=373426&view=rev
Log:
[llvm-lib] Detect duplicate input files
Differential Revision: https://reviews.llvm.org/D68320
Added:
llvm/trunk/test/tools/llvm-lib/duplicate.test
Modified:
llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp
Modified: llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp?rev=373426&r1=373425&r2=373426&view=diff
==============================================================================
--- llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp (original)
+++ llvm/trunk/lib/ToolDrivers/llvm-lib/LibDriver.cpp Tue Oct 1 23:41:52 2019
@@ -13,6 +13,7 @@
#include "llvm/ToolDrivers/llvm-lib/LibDriver.h"
#include "llvm/ADT/STLExtras.h"
+#include "llvm/ADT/StringSet.h"
#include "llvm/BinaryFormat/COFF.h"
#include "llvm/BinaryFormat/Magic.h"
#include "llvm/Bitcode/BitcodeReader.h"
@@ -315,6 +316,7 @@ int llvm::libDriverMain(ArrayRef<const c
}
std::vector<std::unique_ptr<MemoryBuffer>> MBs;
+ StringSet<> Seen;
std::vector<NewArchiveMember> Members;
// Create a NewArchiveMember for each input file.
@@ -326,6 +328,16 @@ int llvm::libDriverMain(ArrayRef<const c
return 1;
}
+ // Input files are uniquified by pathname. If you specify the exact same
+ // path more than once, all but the first one are ignored.
+ //
+ // Note that there's a loophole in the rule; you can prepend `.\` or
+ // something like that to a path to make it look different, and they are
+ // handled as if they were different files. This behavior is compatible with
+ // Microsoft lib.exe.
+ if (!Seen.insert(Path).second)
+ continue;
+
// Open a file.
ErrorOr<std::unique_ptr<MemoryBuffer>> MOrErr =
MemoryBuffer::getFile(Path, -1, false);
Added: llvm/trunk/test/tools/llvm-lib/duplicate.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/tools/llvm-lib/duplicate.test?rev=373426&view=auto
==============================================================================
--- llvm/trunk/test/tools/llvm-lib/duplicate.test (added)
+++ llvm/trunk/test/tools/llvm-lib/duplicate.test Tue Oct 1 23:41:52 2019
@@ -0,0 +1,14 @@
+If the same file is specified more than once as an input file,
+llvm-lib should ignore all but the first occurrence of the file.
+
+RUN: rm -rf %t
+RUN: mkdir -p %t
+
+RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t/foo.o %S/Inputs/a.s
+RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %t/bar.o %S/Inputs/b.s
+RUN: llvm-lib -out:%t/foo.lib %t/foo.o %t/foo.o %t/bar.o
+
+RUN: llvm-ar t %t/foo.lib | FileCheck %s
+CHECK: foo.o
+CHECK-NOT: foo.o
+CHECK: bar.o
More information about the llvm-commits
mailing list