diff options
| author | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-04 16:50:47 +0000 |
|---|---|---|
| committer | Rafael Espindola <rafael.espindola@gmail.com> | 2013-07-04 16:50:47 +0000 |
| commit | 611db946c257a8aa9e465367526e6d94c28f73ea (patch) | |
| tree | 80bdda785af4f64351e1dda417c44205fc32e675 | |
| parent | b55bb2fccfa7812532859fa8a2aa0faea3e46e68 (diff) | |
| download | bcm5719-llvm-611db946c257a8aa9e465367526e6d94c28f73ea.tar.gz bcm5719-llvm-611db946c257a8aa9e465367526e6d94c28f73ea.zip | |
Return 0 when processing --help. This matches gnu ld and gold.
llvm-svn: 185655
| -rw-r--r-- | lld/include/lld/Driver/Driver.h | 5 | ||||
| -rw-r--r-- | lld/lib/Driver/GnuLdDriver.cpp | 25 | ||||
| -rw-r--r-- | lld/test/Driver/trivial-driver.test | 5 |
3 files changed, 22 insertions, 13 deletions
diff --git a/lld/include/lld/Driver/Driver.h b/lld/include/lld/Driver/Driver.h index 7ec3d58e58f..321c5271265 100644 --- a/lld/include/lld/Driver/Driver.h +++ b/lld/include/lld/Driver/Driver.h @@ -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); diff --git a/lld/lib/Driver/GnuLdDriver.cpp b/lld/lib/Driver/GnuLdDriver.cpp index 4603d98bf4c..207a84dd71a 100644 --- a/lld/lib/Driver/GnuLdDriver.cpp +++ b/lld/lib/Driver/GnuLdDriver.cpp @@ -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 *argv[], raw_ostream &diagnostics) { 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 *argv[], raw_ostream &diagnostics) { // 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 *argv[], raw_ostream &diagnostics) { if (!options) { diagnostics << "unknown target triple\n"; - return nullptr; + return true; } // Handle -e xxx @@ -251,7 +255,7 @@ GnuLdDriver::parse(int argc, const char *argv[], raw_ostream &diagnostics) { 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 *argv[], raw_ostream &diagnostics) { // 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 diff --git a/lld/test/Driver/trivial-driver.test b/lld/test/Driver/trivial-driver.test index 304d171d414..9fdecac8bb6 100644 --- a/lld/test/Driver/trivial-driver.test +++ b/lld/test/Driver/trivial-driver.test @@ -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 |

