Fix a bug exposed by lli
authorChris Lattner <sabre@nondot.org>
Wed, 24 Jul 2002 20:15:13 +0000 (20:15 +0000)
committerChris Lattner <sabre@nondot.org>
Wed, 24 Jul 2002 20:15:13 +0000 (20:15 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@3049 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/CommandLine.cpp
support/lib/Support/CommandLine.cpp

index cafc14d3206d83f90bb80827b4cbac3ce9dda3b1..433cefda7bf7f37617db8c15fccb54e78f203924 100644 (file)
@@ -348,8 +348,17 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
     unsigned ValNo = 0;
     for (unsigned j = 1, e = PositionalOpts.size(); j != e; ++j)
       if (RequiresValue(PositionalOpts[j]))
-        ErrorParsing |=
-          ProvidePositionalOption(PositionalOpts[j], PositionalVals[ValNo++]);
+        ErrorParsing |= ProvidePositionalOption(PositionalOpts[j],
+                                                PositionalVals[ValNo++]);
+
+    // Handle the case where there is just one positional option, and it's
+    // optional.  In this case, we want to give JUST THE FIRST option to the
+    // positional option and keep the rest for the consume after.  The above
+    // loop would have assigned no values to positional options in this case.
+    //
+    if (PositionalOpts.size() == 2 && ValNo == 0)
+      ErrorParsing |= ProvidePositionalOption(PositionalOpts[1],
+                                              PositionalVals[ValNo++]);
     
     // Handle over all of the rest of the arguments to the
     // cl::ConsumeAfter command line option...
index cafc14d3206d83f90bb80827b4cbac3ce9dda3b1..433cefda7bf7f37617db8c15fccb54e78f203924 100644 (file)
@@ -348,8 +348,17 @@ void cl::ParseCommandLineOptions(int &argc, char **argv,
     unsigned ValNo = 0;
     for (unsigned j = 1, e = PositionalOpts.size(); j != e; ++j)
       if (RequiresValue(PositionalOpts[j]))
-        ErrorParsing |=
-          ProvidePositionalOption(PositionalOpts[j], PositionalVals[ValNo++]);
+        ErrorParsing |= ProvidePositionalOption(PositionalOpts[j],
+                                                PositionalVals[ValNo++]);
+
+    // Handle the case where there is just one positional option, and it's
+    // optional.  In this case, we want to give JUST THE FIRST option to the
+    // positional option and keep the rest for the consume after.  The above
+    // loop would have assigned no values to positional options in this case.
+    //
+    if (PositionalOpts.size() == 2 && ValNo == 0)
+      ErrorParsing |= ProvidePositionalOption(PositionalOpts[1],
+                                              PositionalVals[ValNo++]);
     
     // Handle over all of the rest of the arguments to the
     // cl::ConsumeAfter command line option...