[llvm] 8692dda - [Support] Remove cl::multi_val (#224959)

via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 20 13:16:33 PDT 2026


Author: Fangrui Song
Date: 2026-09-20T20:16:27Z
New Revision: 8692dda92022dc121e720b8f096e9dfdd6c00282

URL: https://github.com/llvm/llvm-project/commit/8692dda92022dc121e720b8f096e9dfdd6c00282
DIFF: https://github.com/llvm/llvm-project/commit/8692dda92022dc121e720b8f096e9dfdd6c00282.diff

LOG: [Support] Remove cl::multi_val (#224959)

Nothing uses it: the last user, llvm-nm, moved to OptTable. The feature
would block migration to TableGen based representation.

LLM-aided

Added: 
    

Modified: 
    llvm/docs/CommandLine.md
    llvm/include/llvm/Support/CommandLine.h
    llvm/lib/Support/CommandLine.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/docs/CommandLine.md b/llvm/docs/CommandLine.md
index 2cf37ebc52d42..bf5123fdcfa10 100644
--- a/llvm/docs/CommandLine.md
+++ b/llvm/docs/CommandLine.md
@@ -961,16 +961,6 @@ error at runtime if you don't put them in the right order.)
   You will get a compile time error if you try to use cl::values with a parser
   that does not support it.
 
-(cl::multi_val)=
-
-* The **cl::multi_val** attribute specifies that this option takes has multiple
-  values (example: `-sectalign segname sectname sectvalue`). This attribute
-  takes one unsigned argument - the number of values for the option. This
-  attribute is valid only on `cl::list` options (and will fail with compile
-  error if you try to use it with other option types). It is allowed to use all
-  of the usual modifiers on multi-valued options (besides
-  `cl::ValueDisallowed`, obviously).
-
 (cl::cat)=
 
 * The **cl::cat** attribute specifies the option category that the option

diff  --git a/llvm/include/llvm/Support/CommandLine.h b/llvm/include/llvm/Support/CommandLine.h
index dd42c4bfb7f49..d74958ba4f463 100644
--- a/llvm/include/llvm/Support/CommandLine.h
+++ b/llvm/include/llvm/Support/CommandLine.h
@@ -275,7 +275,6 @@ class LLVM_ABI Option {
   uint16_t Misc : 5;
   uint16_t FullyInitialized : 1; // Has addArgument been called?
   uint16_t Position;             // Position of last occurrence of the option
-  uint16_t AdditionalVals;       // Greater than 0 for multi-valued option.
 
 public:
   StringRef ArgStr;   // The argument string itself (ex: "help", "o")
@@ -303,7 +302,6 @@ class LLVM_ABI Option {
 
   inline unsigned getMiscFlags() const { return Misc; }
   inline unsigned getPosition() const { return Position; }
-  inline unsigned getNumAdditionalVals() const { return AdditionalVals; }
 
   // Return true if the argstr != ""
   bool hasArgStr() const { return !ArgStr.empty(); }
@@ -334,8 +332,6 @@ class LLVM_ABI Option {
   explicit Option(enum NumOccurrencesFlag OccurrencesFlag,
                   enum OptionHidden Hidden);
 
-  inline void setNumAdditionalVals(unsigned n) { AdditionalVals = n; }
-
 public:
   virtual ~Option() = default;
 
@@ -381,8 +377,7 @@ class LLVM_ABI Option {
 
   // Wrapper around handleOccurrence that enforces Flags.
   //
-  virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value,
-                             bool MultiArg = false);
+  virtual bool addOccurrence(unsigned pos, StringRef ArgName, StringRef Value);
 
   // Prints option name followed by message.  Always returns true.
   bool error(const Twine &Message, StringRef ArgName = StringRef(), raw_ostream &Errs = llvm::errs());
@@ -1790,8 +1785,6 @@ class list : public Option, public list_storage<DataType, StorageClass> {
       list_storage<DataType, StorageClass>::addValue(Val, true);
   }
 
-  void setNumAdditionalVals(unsigned n) { Option::setNumAdditionalVals(n); }
-
   template <class... Mods>
   explicit list(const Mods &... Ms)
       : Option(ZeroOrMore, NotHidden), Parser(*this) {
@@ -1807,17 +1800,6 @@ class list : public Option, public list_storage<DataType, StorageClass> {
   std::function<void(const typename ParserClass::parser_data_type &)> Callback;
 };
 
-// Modifier to set the number of additional values.
-struct multi_val {
-  unsigned AdditionalVals;
-  explicit multi_val(unsigned N) : AdditionalVals(N) {}
-
-  template <typename D, typename S, typename P>
-  void apply(list<D, S, P> &L) const {
-    L.setNumAdditionalVals(AdditionalVals);
-  }
-};
-
 //===----------------------------------------------------------------------===//
 // Default storage class definition: external storage.  This implementation
 // assumes the user will specify a variable to store the data into with the
@@ -1975,9 +1957,9 @@ class LLVM_ABI alias : public Option {
     return AliasFor->handleOccurrence(pos, AliasFor->ArgStr, Arg);
   }
 
-  bool addOccurrence(unsigned pos, StringRef /*ArgName*/, StringRef Value,
-                     bool MultiArg = false) override {
-    return AliasFor->addOccurrence(pos, AliasFor->ArgStr, Value, MultiArg);
+  bool addOccurrence(unsigned pos, StringRef /*ArgName*/,
+                     StringRef Value) override {
+    return AliasFor->addOccurrence(pos, AliasFor->ArgStr, Value);
   }
 
   // Handle printing stuff...

diff  --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp
index 03ef86bb225d3..f363190bca1ce 100644
--- a/llvm/lib/Support/CommandLine.cpp
+++ b/llvm/lib/Support/CommandLine.cpp
@@ -464,7 +464,7 @@ extrahelp::extrahelp(StringRef Help) : morehelp(Help) {
 Option::Option(NumOccurrencesFlag OccurrencesFlag, OptionHidden Hidden)
     : NumOccurrences(0), Occurrences(OccurrencesFlag), Value(0),
       HiddenFlag(Hidden), Formatting(NormalFormatting), Misc(0),
-      FullyInitialized(false), Position(0), AdditionalVals(0) {
+      FullyInitialized(false), Position(0) {
   Categories.push_back(&getGeneralCategory());
 }
 
@@ -656,8 +656,7 @@ static Option *LookupNearestOption(StringRef Arg,
 /// CommaSeparateAndAddOccurrence - A wrapper around Handler->addOccurrence()
 /// that does special handling of cl::CommaSeparated options.
 static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos,
-                                          StringRef ArgName, StringRef Value,
-                                          bool MultiArg = false) {
+                                          StringRef ArgName, StringRef Value) {
   // Check to see if this option accepts a comma separated list of values.  If
   // it does, we have to split up the value into multiple values.
   if (Handler->getMiscFlags() & CommaSeparated) {
@@ -666,7 +665,7 @@ static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos,
 
     while (Pos != StringRef::npos) {
       // Process the portion before the comma.
-      if (Handler->addOccurrence(pos, ArgName, Val.substr(0, Pos), MultiArg))
+      if (Handler->addOccurrence(pos, ArgName, Val.substr(0, Pos)))
         return true;
       // Erase the portion before the comma, AND the comma.
       Val = Val.substr(Pos + 1);
@@ -677,7 +676,7 @@ static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos,
     Value = Val;
   }
 
-  return Handler->addOccurrence(pos, ArgName, Value, MultiArg);
+  return Handler->addOccurrence(pos, ArgName, Value);
 }
 
 /// ProvideOption - For Value, this 
diff erentiates between an empty value ("")
@@ -686,9 +685,6 @@ static bool CommaSeparateAndAddOccurrence(Option *Handler, unsigned pos,
 static inline bool ProvideOption(Option *Handler, StringRef ArgName,
                                  StringRef Value, int argc,
                                  const char *const *argv, int &i) {
-  // Is this a multi-argument option?
-  unsigned NumAdditionalVals = Handler->getNumAdditionalVals();
-
   // Enforce value requirements
   switch (Handler->getValueExpectedFlag()) {
   case ValueRequired:
@@ -703,10 +699,6 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName,
     }
     break;
   case ValueDisallowed:
-    if (NumAdditionalVals > 0)
-      return Handler->error("multi-valued option specified"
-                            " with ValueDisallowed modifier!");
-
     if (Value.data())
       return Handler->error("does not allow a value! '" + Twine(Value) +
                             "' specified.");
@@ -715,32 +707,7 @@ static inline bool ProvideOption(Option *Handler, StringRef ArgName,
     break;
   }
 
-  // If this isn't a multi-arg option, just run the handler.
-  if (NumAdditionalVals == 0)
-    return CommaSeparateAndAddOccurrence(Handler, i, ArgName, Value);
-
-  // If it is, run the handle several times.
-  bool MultiArg = false;
-
-  if (Value.data()) {
-    if (CommaSeparateAndAddOccurrence(Handler, i, ArgName, Value, MultiArg))
-      return true;
-    --NumAdditionalVals;
-    MultiArg = true;
-  }
-
-  while (NumAdditionalVals > 0) {
-    if (i + 1 >= argc)
-      return Handler->error("not enough values!");
-    assert(argv && "null check");
-    Value = StringRef(argv[++i]);
-
-    if (CommaSeparateAndAddOccurrence(Handler, i, ArgName, Value, MultiArg))
-      return true;
-    MultiArg = true;
-    --NumAdditionalVals;
-  }
-  return false;
+  return CommaSeparateAndAddOccurrence(Handler, i, ArgName, Value);
 }
 
 bool llvm::cl::ProvidePositionalOption(Option *Handler, StringRef Arg, int i) {
@@ -1907,11 +1874,8 @@ bool Option::error(const Twine &Message, StringRef ArgName, raw_ostream &Errs) {
   return true;
 }
 
-bool Option::addOccurrence(unsigned pos, StringRef ArgName, StringRef Value,
-                           bool MultiArg) {
-  if (!MultiArg)
-    NumOccurrences++; // Increment the number of times we have been seen
-
+bool Option::addOccurrence(unsigned pos, StringRef ArgName, StringRef Value) {
+  ++NumOccurrences;
   return handleOccurrence(pos, ArgName, Value);
 }
 


        


More information about the llvm-commits mailing list