[llvm] r352848 - Revert r352750.

James Henderson via llvm-commits llvm-commits at lists.llvm.org
Fri Feb 1 02:38:40 PST 2019


Author: jhenderson
Date: Fri Feb  1 02:38:40 2019
New Revision: 352848

URL: http://llvm.org/viewvc/llvm-project?rev=352848&view=rev
Log:
Revert r352750.

This was causing a build bot failure:
http://green.lab.llvm.org/green/job/clang-stage2-Rthinlto/15346/

Modified:
    llvm/trunk/lib/Support/CommandLine.cpp
    llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp
    llvm/trunk/unittests/Support/CommandLineTest.cpp

Modified: llvm/trunk/lib/Support/CommandLine.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/CommandLine.cpp?rev=352848&r1=352847&r2=352848&view=diff
==============================================================================
--- llvm/trunk/lib/Support/CommandLine.cpp (original)
+++ llvm/trunk/lib/Support/CommandLine.cpp Fri Feb  1 02:38:40 2019
@@ -1663,35 +1663,13 @@ size_t generic_parser_base::getOptionWid
 void generic_parser_base::printOptionInfo(const Option &O,
                                           size_t GlobalWidth) const {
   if (O.hasArgStr()) {
-    // When the value is optional, first print a line just describing the option
-    // without values.
-    if (O.getValueExpectedFlag() == ValueOptional) {
-      for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
-        if (getOption(i).empty()) {
-          outs() << "  -" << O.ArgStr;
-          Option::printHelpStr(O.HelpStr, GlobalWidth, O.ArgStr.size() + 6);
-          break;
-        }
-      }
-    }
+    outs() << "  -" << O.ArgStr;
+    Option::printHelpStr(O.HelpStr, GlobalWidth, O.ArgStr.size() + 6);
 
-    outs() << "  -" << O.ArgStr << "=<value>";
-    Option::printHelpStr(O.HelpStr, GlobalWidth, O.ArgStr.size() + 14);
     for (unsigned i = 0, e = getNumOptions(); i != e; ++i) {
-      StringRef ValueName = getOption(i);
-      StringRef Description = getDescription(i);
-      if (O.getValueExpectedFlag() == ValueOptional && ValueName.empty() &&
-          Description.empty())
-        continue;
-      size_t NumSpaces = GlobalWidth - ValueName.size() - 8;
-      outs() << "    =" << ValueName;
-      if (ValueName.empty()) {
-        outs() << "<empty>";
-        NumSpaces -= 7;
-      }
-      if (!Description.empty())
-        outs().indent(NumSpaces) << " -   " << Description;
-      outs() << '\n';
+      size_t NumSpaces = GlobalWidth - getOption(i).size() - 8;
+      outs() << "    =" << getOption(i);
+      outs().indent(NumSpaces) << " -   " << getDescription(i) << '\n';
     }
   } else {
     if (!O.HelpStr.empty())

Modified: llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp?rev=352848&r1=352847&r2=352848&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp (original)
+++ llvm/trunk/tools/llvm-symbolizer/llvm-symbolizer.cpp Fri Feb  1 02:38:40 2019
@@ -38,7 +38,7 @@ ClUseSymbolTable("use-symbol-table", cl:
 
 static cl::opt<FunctionNameKind> ClPrintFunctions(
     "functions", cl::init(FunctionNameKind::LinkageName),
-    cl::desc("Print function name for a given address"), cl::ValueOptional,
+    cl::desc("Print function name for a given address:"), cl::ValueOptional,
     cl::values(clEnumValN(FunctionNameKind::None, "none", "omit function name"),
                clEnumValN(FunctionNameKind::ShortName, "short",
                           "print short function name"),

Modified: llvm/trunk/unittests/Support/CommandLineTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Support/CommandLineTest.cpp?rev=352848&r1=352847&r2=352848&view=diff
==============================================================================
--- llvm/trunk/unittests/Support/CommandLineTest.cpp (original)
+++ llvm/trunk/unittests/Support/CommandLineTest.cpp Fri Feb  1 02:38:40 2019
@@ -13,7 +13,6 @@
 #include "llvm/Config/config.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/InitLLVM.h"
-#include "llvm/Support/MemoryBuffer.h"
 #include "llvm/Support/Path.h"
 #include "llvm/Support/Program.h"
 #include "llvm/Support/StringSaver.h"
@@ -840,137 +839,4 @@ TEST(CommandLineTest, GetCommandLineArgu
 }
 #endif
 
-class OutputRedirector {
-public:
-  OutputRedirector(int RedirectFD)
-      : RedirectFD(RedirectFD), OldFD(dup(RedirectFD)) {
-    if (OldFD == -1 ||
-        sys::fs::createTemporaryFile("unittest-redirect", "", NewFD,
-                                     FilePath) ||
-        dup2(NewFD, RedirectFD) == -1)
-      Valid = false;
-  }
-
-  ~OutputRedirector() {
-    dup2(OldFD, RedirectFD);
-    close(OldFD);
-    close(NewFD);
-  }
-
-  SmallVector<char, 128> FilePath;
-  bool Valid = true;
-
-private:
-  int RedirectFD;
-  int OldFD;
-  int NewFD;
-};
-
-struct AutoDeleteFile {
-  SmallVector<char, 128> FilePath;
-  ~AutoDeleteFile() {
-    if (!FilePath.empty())
-      sys::fs::remove(std::string(FilePath.data(), FilePath.size()));
-  }
-};
-
-class PrintOptionInfoTest : public ::testing::Test {
-public:
-  // Return std::string because the output of a failing EXPECT check is
-  // unreadable for StringRef. It also avoids any lifetime issues.
-  template <typename... Ts> std::string runTest(Ts... OptionAttributes) {
-    AutoDeleteFile File;
-    {
-      OutputRedirector Stdout(fileno(stdout));
-      if (!Stdout.Valid)
-        return "";
-      File.FilePath = Stdout.FilePath;
-
-      StackOption<OptionValue> TestOption(Opt, cl::desc(HelpText),
-                                          OptionAttributes...);
-      printOptionInfo(TestOption, 25);
-      outs().flush();
-    }
-    auto Buffer = MemoryBuffer::getFile(File.FilePath);
-    if (!Buffer)
-      return "";
-    return Buffer->get()->getBuffer().str();
-  }
-
-  enum class OptionValue { Val };
-  const StringRef Opt = "some-option";
-  const StringRef HelpText = "some help";
-
-private:
-  // This is a workaround for cl::Option sub-classes having their
-  // printOptionInfo functions private.
-  void printOptionInfo(const cl::Option &O, size_t Width) {
-    O.printOptionInfo(Width);
-  }
-};
-
-TEST_F(PrintOptionInfoTest, PrintOptionInfoValueOptionalWithoutSentinel) {
-  std::string Output =
-      runTest(cl::ValueOptional,
-              cl::values(clEnumValN(OptionValue::Val, "v1", "desc1")));
-
-  // clang-format off
-  EXPECT_EQ(Output, ("  -" + Opt + "=<value> - " + HelpText + "\n"
-                     "    =v1                -   desc1\n")
-                        .str());
-  // clang-format on
-}
-
-TEST_F(PrintOptionInfoTest, PrintOptionInfoValueOptionalWithSentinel) {
-  std::string Output = runTest(
-      cl::ValueOptional, cl::values(clEnumValN(OptionValue::Val, "v1", "desc1"),
-                                    clEnumValN(OptionValue::Val, "", "")));
-
-  // clang-format off
-  EXPECT_EQ(Output,
-            ("  -" + Opt + "         - " + HelpText + "\n"
-             "  -" + Opt + "=<value> - " + HelpText + "\n"
-             "    =v1                -   desc1\n")
-                .str());
-  // clang-format on
-}
-
-TEST_F(PrintOptionInfoTest, PrintOptionInfoValueOptionalWithSentinelWithHelp) {
-  std::string Output = runTest(
-      cl::ValueOptional, cl::values(clEnumValN(OptionValue::Val, "v1", "desc1"),
-                                    clEnumValN(OptionValue::Val, "", "desc2")));
-
-  // clang-format off
-  EXPECT_EQ(Output, ("  -" + Opt + "         - " + HelpText + "\n"
-                     "  -" + Opt + "=<value> - " + HelpText + "\n"
-                     "    =v1                -   desc1\n"
-                     "    =<empty>           -   desc2\n")
-                        .str());
-  // clang-format on
-}
-
-TEST_F(PrintOptionInfoTest, PrintOptionInfoValueRequiredWithEmptyValueName) {
-  std::string Output = runTest(
-      cl::ValueRequired, cl::values(clEnumValN(OptionValue::Val, "v1", "desc1"),
-                                    clEnumValN(OptionValue::Val, "", "")));
-
-  // clang-format off
-  EXPECT_EQ(Output, ("  -" + Opt + "=<value> - " + HelpText + "\n"
-                     "    =v1                -   desc1\n"
-                     "    =<empty>\n")
-                        .str());
-  // clang-format on
-}
-
-TEST_F(PrintOptionInfoTest, PrintOptionInfoEmptyValueDescription) {
-  std::string Output = runTest(
-      cl::ValueRequired, cl::values(clEnumValN(OptionValue::Val, "v1", "")));
-
-  // clang-format off
-  EXPECT_EQ(Output,
-            ("  -" + Opt + "=<value> - " + HelpText + "\n"
-             "    =v1\n").str());
-  // clang-format on
-}
-
 }  // anonymous namespace




More information about the llvm-commits mailing list