[lld] r185655 - Return 0 when processing --help. This matches gnu ld and gold.

Rafael Espindola rafael.espindola at gmail.com
Thu Jul 4 09:50:47 PDT 2013


Author: rafael
Date: Thu Jul  4 11:50:47 2013
New Revision: 185655

URL: http://llvm.org/viewvc/llvm-project?rev=185655&view=rev
Log:
Return 0 when processing --help. This matches gnu ld and gold.

Modified:
    lld/trunk/include/lld/Driver/Driver.h
    lld/trunk/lib/Driver/GnuLdDriver.cpp
    lld/trunk/test/Driver/trivial-driver.test

Modified: lld/trunk/include/lld/Driver/Driver.h
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/include/lld/Driver/Driver.h?rev=185655&r1=185654&r2=185655&view=diff
==============================================================================
--- lld/trunk/include/lld/Driver/Driver.h (original)
+++ lld/trunk/include/lld/Driver/Driver.h Thu Jul  4 11:50:47 2013
@@ -67,8 +67,9 @@ public:
 
   /// Uses gnu/binutils style ld command line options to fill in options struct.
   /// Returns true iff there was an error.
-  static std::unique_ptr<ELFTargetInfo> parse(int argc, const char *argv[],
-                                      raw_ostream &diagnostics = llvm::errs());
+  static bool parse(int argc, const char *argv[],
+                    std::unique_ptr<ELFTargetInfo> &targetInfo,
+                    raw_ostream &diagnostics = llvm::errs());
 
 private:
   static llvm::Triple getDefaultTarget(const char *progName);

Modified: lld/trunk/lib/Driver/GnuLdDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Driver/GnuLdDriver.cpp?rev=185655&r1=185654&r2=185655&view=diff
==============================================================================
--- lld/trunk/lib/Driver/GnuLdDriver.cpp (original)
+++ lld/trunk/lib/Driver/GnuLdDriver.cpp Thu Jul  4 11:50:47 2013
@@ -74,15 +74,19 @@ public:
 
 bool GnuLdDriver::linkELF(int argc, const char *argv[],
                                                   raw_ostream &diagnostics) {
-  std::unique_ptr<ELFTargetInfo> options(parse(argc, argv, diagnostics));
-  if (!options)
+  std::unique_ptr<ELFTargetInfo> options;
+  bool error = parse(argc, argv, options, diagnostics);
+  if (error)
     return true;
+  if (!options)
+    return false;
 
   return link(*options, diagnostics);
 }
 
-std::unique_ptr<ELFTargetInfo>
-GnuLdDriver::parse(int argc, const char *argv[], raw_ostream &diagnostics) {
+bool GnuLdDriver::parse(int argc, const char *argv[],
+                        std::unique_ptr<ELFTargetInfo> &targetInfo,
+                        raw_ostream &diagnostics) {
   // Parse command line options using LDOptions.td
   std::unique_ptr<llvm::opt::InputArgList> parsedArgs;
   GnuLdOptTable table;
@@ -94,7 +98,7 @@ GnuLdDriver::parse(int argc, const char
     diagnostics << "error: missing arg value for '"
                 << parsedArgs->getArgString(missingIndex) << "' expected "
                 << missingCount << " argument(s).\n";
-    return nullptr;
+    return true;
   }
 
   for (auto it = parsedArgs->filtered_begin(OPT_UNKNOWN),
@@ -107,7 +111,7 @@ GnuLdDriver::parse(int argc, const char
   // Handle --help
   if (parsedArgs->getLastArg(OPT_help)) {
     table.PrintHelp(llvm::outs(), argv[0], "LLVM Linker", false);
-    return nullptr;
+    return false;
   }
 
   // Use -target or use default target triple to instantiate TargetInfo
@@ -120,7 +124,7 @@ GnuLdDriver::parse(int argc, const char
 
   if (!options) {
     diagnostics << "unknown target triple\n";
-    return nullptr;
+    return true;
   }
 
   // Handle -e xxx
@@ -251,7 +255,7 @@ GnuLdDriver::parse(int argc, const char
       if (options->appendLibrary((*it)->getValue())) {
         diagnostics << "Failed to find library for " << (*it)->getValue()
                     << "\n";
-        return nullptr;
+        return true;
       }
       break;
     default:
@@ -261,9 +265,10 @@ GnuLdDriver::parse(int argc, const char
 
   // Validate the combination of options used.
   if (options->validate(diagnostics))
-    return nullptr;
+    return true;
 
-  return options;
+  targetInfo.swap(options);
+  return false;
 }
 
 /// Get the default target triple based on either the program name

Modified: lld/trunk/test/Driver/trivial-driver.test
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/test/Driver/trivial-driver.test?rev=185655&r1=185654&r2=185655&view=diff
==============================================================================
--- lld/trunk/test/Driver/trivial-driver.test (original)
+++ lld/trunk/test/Driver/trivial-driver.test Thu Jul  4 11:50:47 2013
@@ -1,4 +1,7 @@
-RUN: lld -flavor gnu --help | FileCheck %s
+We use a temporary file to check lld's return value.
+FIXME: use pipefail instead.
+RUN: lld -flavor gnu --help > %t
+RUN: cat %t | FileCheck %s
 
 CHECK: -L
 CHECK: -emit-yaml





More information about the llvm-commits mailing list