[llvm] r241710 - LibDriver: Fix output path inference.

Peter Collingbourne peter at pcc.me.uk
Wed Jul 8 12:00:46 PDT 2015


Author: pcc
Date: Wed Jul  8 14:00:46 2015
New Revision: 241710

URL: http://llvm.org/viewvc/llvm-project?rev=241710&view=rev
Log:
LibDriver: Fix output path inference.

The inferred output file name is based on the first input file, not the
first one with extension .obj. The output file was also being written to
the wrong directory; it needs to be written to whichever directory on the
libpath it was found in. This change fixes both issues.

Added:
    llvm/trunk/test/LibDriver/infer-output-path.test
Modified:
    llvm/trunk/lib/LibDriver/LibDriver.cpp

Modified: llvm/trunk/lib/LibDriver/LibDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/LibDriver/LibDriver.cpp?rev=241710&r1=241709&r2=241710&view=diff
==============================================================================
--- llvm/trunk/lib/LibDriver/LibDriver.cpp (original)
+++ llvm/trunk/lib/LibDriver/LibDriver.cpp Wed Jul  8 14:00:46 2015
@@ -56,17 +56,13 @@ public:
 
 }
 
-static std::string getOutputPath(llvm::opt::InputArgList *Args) {
+static std::string getOutputPath(llvm::opt::InputArgList *Args,
+                                 const llvm::NewArchiveIterator &FirstMember) {
   if (auto *Arg = Args->getLastArg(OPT_out))
     return Arg->getValue();
-  for (auto *Arg : Args->filtered(OPT_INPUT)) {
-    if (!StringRef(Arg->getValue()).endswith_lower(".obj"))
-      continue;
-    SmallString<128> Val = StringRef(Arg->getValue());
-    llvm::sys::path::replace_extension(Val, ".lib");
-    return Val.str();
-  }
-  llvm_unreachable("internal error");
+  SmallString<128> Val = FirstMember.getNew();
+  llvm::sys::path::replace_extension(Val, ".lib");
+  return Val.str();
 }
 
 static std::vector<StringRef> getSearchPaths(llvm::opt::InputArgList *Args,
@@ -143,8 +139,8 @@ int llvm::libDriverMain(llvm::ArrayRef<c
                          llvm::sys::path::filename(Arg->getValue()));
   }
 
-  std::pair<StringRef, std::error_code> Result =
-      llvm::writeArchive(getOutputPath(&Args), Members, /*WriteSymtab=*/true);
+  std::pair<StringRef, std::error_code> Result = llvm::writeArchive(
+      getOutputPath(&Args, Members[0]), Members, /*WriteSymtab=*/true);
   if (Result.second) {
     if (Result.first.empty())
       Result.first = ArgsArr[0];

Added: llvm/trunk/test/LibDriver/infer-output-path.test
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/LibDriver/infer-output-path.test?rev=241710&view=auto
==============================================================================
--- llvm/trunk/test/LibDriver/infer-output-path.test (added)
+++ llvm/trunk/test/LibDriver/infer-output-path.test Wed Jul  8 14:00:46 2015
@@ -0,0 +1,15 @@
+RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %T/a.obj %S/Inputs/a.s
+RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %T/b.o %S/Inputs/b.s
+RUN: llvm-mc -triple=x86_64-pc-windows-msvc -filetype=obj -o %T/c %S/Inputs/b.s
+
+RUN: rm -f %T/a.lib
+RUN: llvm-lib %T/a.obj
+RUN: test -e %T/a.lib
+
+RUN: rm -f %T/b.lib
+RUN: llvm-lib /libpath:%T b.o
+RUN: test -e %T/b.lib
+
+RUN: rm -f %T/c.lib
+RUN: llvm-lib /libpath:%T c
+RUN: test -e %T/c.lib





More information about the llvm-commits mailing list