[llvm] 4a63d32 - [Support] Remove LongOptionsUseDoubleDash from cl::ParseCommandLineOptions (#226347)

via llvm-commits llvm-commits at lists.llvm.org
Fri Sep 25 00:51:06 PDT 2026


Author: Fangrui Song
Date: 2026-09-25T00:50:59-07:00
New Revision: 4a63d32442818fd311739ec60c0a31a8e60fe64d

URL: https://github.com/llvm/llvm-project/commit/4a63d32442818fd311739ec60c0a31a8e60fe64d
DIFF: https://github.com/llvm/llvm-project/commit/4a63d32442818fd311739ec60c0a31a8e60fe64d.diff

LOG: [Support] Remove LongOptionsUseDoubleDash from cl::ParseCommandLineOptions (#226347)

The mode (https://reviews.llvm.org/D61294), in which `-` introduces only
single-character options and `--` long ones, was added for the
binutils-style tools, which have since moved to OptTable. Its last
users, yaml2obj, obj2yaml and split-file, parse with OptTable now.

LLM-aided

Added: 
    

Modified: 
    llvm/include/llvm/Support/CommandLine.h
    llvm/lib/Support/CommandLine.cpp
    llvm/unittests/Support/CommandLineTest.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index 7537d4c74f212..63e25183ba376 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -67,8 +67,7 @@ LLVM_ABI bool ParseCommandLineOptions(int argc, const char *const *argv,
                                       StringRef Overview = "",
                                       raw_ostream *Errs = nullptr,
                                       vfs::FileSystem *VFS = nullptr,
-                                      const char *EnvVar = nullptr,
-                                      bool LongOptionsUseDoubleDash = false);
+                                      const char *EnvVar = nullptr);
 
 // Function pointer type for printing version information.
 using VersionPrinterTy = std::function<void(raw_ostream &)>;

diff  --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index b19984a0eeb03..df54c69d07d0e 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -179,8 +179,7 @@ class CommandLineParser {
 
   bool ParseCommandLineOptions(int argc, const char *const *argv,
                                StringRef Overview, raw_ostream *Errs = nullptr,
-                               vfs::FileSystem *VFS = nullptr,
-                               bool LongOptionsUseDoubleDash = false);
+                               vfs::FileSystem *VFS = nullptr);
 
   void forEachSubCommand(Option &Opt, function_ref<void(SubCommand &)> Action) {
     if (Opt.Subs.empty()) {
@@ -381,14 +380,6 @@ class CommandLineParser {
   SubCommand *ActiveSubCommand = nullptr;
 
   Option *LookupOption(SubCommand &Sub, StringRef &Arg, StringRef &Value);
-  Option *LookupLongOption(SubCommand &Sub, StringRef &Arg, StringRef &Value,
-                           bool LongOptionsUseDoubleDash, bool HaveDoubleDash) {
-    Option *Opt = LookupOption(Sub, Arg, Value);
-    if (Opt && LongOptionsUseDoubleDash && !HaveDoubleDash &&
-        Opt->ArgStr.size() != 1)
-      return nullptr;
-    return Opt;
-  }
   SubCommand *LookupSubCommand(StringRef Name, std::string &NearestString);
 };
 
@@ -1366,8 +1357,7 @@ Error ExpansionContext::readConfigFile(StringRef CfgFile,
 static void initCommonOptions();
 bool cl::ParseCommandLineOptions(int argc, const char *const *argv,
                                  StringRef Overview, raw_ostream *Errs,
-                                 vfs::FileSystem *VFS, const char *EnvVar,
-                                 bool LongOptionsUseDoubleDash) {
+                                 vfs::FileSystem *VFS, const char *EnvVar) {
   initCommonOptions();
   SmallVector<const char *, 20> NewArgv;
   BumpPtrAllocator A;
@@ -1387,8 +1377,8 @@ bool cl::ParseCommandLineOptions(int argc, const char *const *argv,
   int NewArgc = static_cast<int>(NewArgv.size());
 
   // Parse all options.
-  return globalParser().ParseCommandLineOptions(
-      NewArgc, &NewArgv[0], Overview, Errs, VFS, LongOptionsUseDoubleDash);
+  return globalParser().ParseCommandLineOptions(NewArgc, &NewArgv[0], Overview,
+                                                Errs, VFS);
 }
 
 /// Reset all options at least once, so that we can parse 
diff erent options.
@@ -1412,9 +1402,11 @@ void CommandLineParser::ResetAllOptionOccurrences() {
   }
 }
 
-bool CommandLineParser::ParseCommandLineOptions(
-    int argc, const char *const *argv, StringRef Overview, raw_ostream *Errs,
-    vfs::FileSystem *VFS, bool LongOptionsUseDoubleDash) {
+bool CommandLineParser::ParseCommandLineOptions(int argc,
+                                                const char *const *argv,
+                                                StringRef Overview,
+                                                raw_ostream *Errs,
+                                                vfs::FileSystem *VFS) {
   assert(hasOptions() && "No options specified!");
 
   ProgramOverview = Overview;
@@ -1529,7 +1521,6 @@ bool CommandLineParser::ParseCommandLineOptions(
     std::string NearestHandlerString;
     StringRef Value;
     StringRef ArgName = "";
-    bool HaveDoubleDash = false;
 
     // Check to see if this is a positional argument.  This argument is
     // considered to be positional if it doesn't start with '-', if it is "-"
@@ -1568,11 +1559,9 @@ bool CommandLineParser::ParseCommandLineOptions(
       // otherwise feed it to the eating positional.
       ArgName = StringRef(argv[i] + 1);
       // Eat second dash.
-      if (ArgName.consume_front("-"))
-        HaveDoubleDash = true;
+      ArgName.consume_front("-");
 
-      Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
-                                 LongOptionsUseDoubleDash, HaveDoubleDash);
+      Handler = LookupOption(*ChosenSubCommand, ArgName, Value);
       if (!Handler || Handler->getFormattingFlag() != cl::Positional) {
         ProvidePositionalOption(ActivePositionalArg, StringRef(argv[i]), i);
         continue; // We are done!
@@ -1580,21 +1569,18 @@ bool CommandLineParser::ParseCommandLineOptions(
     } else { // We start with a '-', must be an argument.
       ArgName = StringRef(argv[i] + 1);
       // Eat second dash.
-      if (ArgName.consume_front("-"))
-        HaveDoubleDash = true;
+      ArgName.consume_front("-");
 
-      Handler = LookupLongOption(*ChosenSubCommand, ArgName, Value,
-                                 LongOptionsUseDoubleDash, HaveDoubleDash);
+      Handler = LookupOption(*ChosenSubCommand, ArgName, Value);
 
       // If Handler is not found in a specialized subcommand, look up handler
       // in the top-level subcommand.
       // cl::opt without cl::sub belongs to top-level subcommand.
       if (!Handler && ChosenSubCommand != &SubCommand::getTopLevel())
-        Handler = LookupLongOption(SubCommand::getTopLevel(), ArgName, Value,
-                                   LongOptionsUseDoubleDash, HaveDoubleDash);
+        Handler = LookupOption(SubCommand::getTopLevel(), ArgName, Value);
 
       // Check to see if this "option" is really a prefixed argument.
-      if (!Handler && !(LongOptionsUseDoubleDash && HaveDoubleDash))
+      if (!Handler)
         Handler = HandlePrefixedOption(ArgName, Value, OptionsMap);
 
       // Otherwise, look for the closest available option to report to the user

diff  --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index d354d3ccf6d9b..822b4637c6f64 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -1741,11 +1741,6 @@ TEST(CommandLineTest, LongOptions) {
   const char *args2[] = {"prog", "-a", "--ab", "val1"};
   const char *args3[] = {"prog", "-ab", "--ab", "val1"};
 
-  //
-  // The following tests treat `-` and `--` the same, and always match the
-  // longest string.
-  //
-
   EXPECT_TRUE(
       cl::ParseCommandLineOptions(4, args1, StringRef(), &OS));
   EXPECT_TRUE(OptA);
@@ -1765,34 +1760,8 @@ TEST(CommandLineTest, LongOptions) {
   // Fails because `val1` is unexpected.
   EXPECT_FALSE(
       cl::ParseCommandLineOptions(4, args3, StringRef(), &OS));
-  outs()<< Errs << "\n";
-  EXPECT_FALSE(Errs.empty()); Errs.clear();
-  cl::ResetAllOptionOccurrences();
-
-  //
-  // The following tests treat `-` and `--` 
diff erently, with `-` for short, and
-  // `--` for long options.
-  //
-
-  // Fails because `-ab` is neither a short option nor `--ab`, and `val1` is
-  // unexpected.
-  EXPECT_FALSE(cl::ParseCommandLineOptions(4, args1, StringRef(), &OS, nullptr,
-                                           nullptr, true));
   EXPECT_FALSE(Errs.empty()); Errs.clear();
   cl::ResetAllOptionOccurrences();
-
-  // Works because `-a` is treated 
diff erently than `--ab`.
-  EXPECT_TRUE(cl::ParseCommandLineOptions(4, args2, StringRef(), &OS, nullptr,
-                                          nullptr, true));
-  EXPECT_TRUE(Errs.empty()); Errs.clear();
-  cl::ResetAllOptionOccurrences();
-
-  // Fails because `-ab` is not `--ab`.
-  EXPECT_FALSE(cl::ParseCommandLineOptions(4, args3, StringRef(), &OS, nullptr,
-                                           nullptr, true));
-  EXPECT_FALSE(Errs.empty());
-  Errs.clear();
-  cl::ResetAllOptionOccurrences();
 }
 
 TEST(CommandLineTest, OptionErrorMessage) {


        


More information about the llvm-commits mailing list