[llvm] r186838 - Option parsing: allow aliases in groups

Hans Wennborg hans at hanshq.net
Mon Jul 22 09:18:13 PDT 2013


Author: hans
Date: Mon Jul 22 11:18:13 2013
New Revision: 186838

URL: http://llvm.org/viewvc/llvm-project?rev=186838&view=rev
Log:
Option parsing: allow aliases in groups

Option aliases in option groups were previously disallowed by an assert.
As far as I can tell, there was no technical reason for this, and I would
like to be able to put cl.exe compatible options in their own group for Clang,
so let's change the assert.

Modified:
    llvm/trunk/lib/Option/Option.cpp
    llvm/trunk/unittests/Option/OptionParsingTest.cpp
    llvm/trunk/unittests/Option/Opts.td

Modified: llvm/trunk/lib/Option/Option.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Option/Option.cpp?rev=186838&r1=186837&r2=186838&view=diff
==============================================================================
--- llvm/trunk/lib/Option/Option.cpp (original)
+++ llvm/trunk/lib/Option/Option.cpp Mon Jul 22 11:18:13 2013
@@ -22,12 +22,10 @@ using namespace llvm::opt;
 Option::Option(const OptTable::Info *info, const OptTable *owner)
   : Info(info), Owner(owner) {
 
-  // Multi-level aliases are not supported, and alias options cannot
-  // have groups. This just simplifies option tracking, it is not an
-  // inherent limitation.
-  assert((!Info || !getAlias().isValid() || (!getAlias().getAlias().isValid() &&
-         !getGroup().isValid())) &&
-         "Multi-level aliases and aliases with groups are unsupported.");
+  // Multi-level aliases are not supported. This just simplifies option
+  // tracking, it is not an inherent limitation.
+  assert(!Info || !getAlias().isValid() || !getAlias().getAlias().isValid() &&
+         "Multi-level aliases are not supported.");
 }
 
 Option::~Option() {

Modified: llvm/trunk/unittests/Option/OptionParsingTest.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Option/OptionParsingTest.cpp?rev=186838&r1=186837&r2=186838&view=diff
==============================================================================
--- llvm/trunk/unittests/Option/OptionParsingTest.cpp (original)
+++ llvm/trunk/unittests/Option/OptionParsingTest.cpp Mon Jul 22 11:18:13 2013
@@ -136,3 +136,12 @@ TEST(Option, ParseWithFlagExclusions) {
   EXPECT_EQ(AL->getLastArgValue(OPT_SLASH_C), "foo");
   EXPECT_EQ(AL->getLastArgValue(OPT_C), "bar");
 }
+
+TEST(Option, ParseAliasInGroup) {
+  TestOptTable T;
+  unsigned MAI, MAC;
+
+  const char *MyArgs[] = { "-I" };
+  OwningPtr<InputArgList> AL(T.ParseArgs(MyArgs, array_endof(MyArgs), MAI, MAC));
+  EXPECT_TRUE(AL->hasArg(OPT_H));
+}

Modified: llvm/trunk/unittests/Option/Opts.td
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/unittests/Option/Opts.td?rev=186838&r1=186837&r2=186838&view=diff
==============================================================================
--- llvm/trunk/unittests/Option/Opts.td (original)
+++ llvm/trunk/unittests/Option/Opts.td Mon Jul 22 11:18:13 2013
@@ -16,3 +16,6 @@ def G : JoinedAndSeparate<["-"], "G">, H
 def Ceq : Joined<["-", "--"], "C=">, Alias<C>, Flags<[OptFlag1]>;
 
 def H : Flag<["-"], "H">, Flags<[HelpHidden]>;
+
+def my_group : OptionGroup<"my group">;
+def I : Flag<["-"], "I">, Alias<H>, Group<my_group>;





More information about the llvm-commits mailing list