[PATCH] D68320: [llvm-lib] Detect duplicate input files

Rui Ueyama via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Tue Oct 1 23:02:30 PDT 2019


ruiu created this revision.
ruiu added a reviewer: MaskRay.
Herald added a subscriber: hiraditya.
Herald added a project: LLVM.

[llvm-lib] Detect duplicate input files


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D68320

Files:
  llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp


Index: llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
===================================================================
--- llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
+++ llvm/lib/ToolDrivers/llvm-lib/LibDriver.cpp
@@ -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 @@
   }
 
   std::vector<std::unique_ptr<MemoryBuffer>> MBs;
+  StringSet<> Seen;
   std::vector<NewArchiveMember> Members;
 
   // Create a NewArchiveMember for each input file.
@@ -326,6 +328,16 @@
       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);


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68320.222758.patch
Type: text/x-patch
Size: 1299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191002/86807ed7/attachment.bin>


More information about the llvm-commits mailing list