Driver: Implement 'missing argument' error.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67490 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/Option.cpp b/lib/Driver/Option.cpp
index 12d501b..dc681c7 100644
--- a/lib/Driver/Option.cpp
+++ b/lib/Driver/Option.cpp
@@ -108,7 +108,7 @@
 }
 
 Arg *OptionGroup::accept(const ArgList &Args, unsigned &Index) const {
-  assert(0 && "FIXME");
+  assert(0 && "accept() should never be called on an OptionGroup");
   return 0;
 }
 
@@ -117,7 +117,7 @@
 }
 
 Arg *InputOption::accept(const ArgList &Args, unsigned &Index) const {
-  assert(0 && "FIXME");
+  assert(0 && "accept() should never be called on an InputOption");
   return 0;
 }
 
@@ -126,7 +126,7 @@
 }
 
 Arg *UnknownOption::accept(const ArgList &Args, unsigned &Index) const {
-  assert(0 && "FIXME");
+  assert(0 && "accept() should never be called on an UnknownOption");
   return 0;
 }
 
@@ -181,8 +181,10 @@
   if (strlen(getName()) != strlen(Args.getArgString(Index)))
     return 0;
 
-  // FIXME: Missing argument error.
   Index += 2;
+  if (Index > Args.getNumInputArgStrings())
+    return 0;
+
   return new SeparateArg(this, Index - 2, 1);
 }
 
@@ -199,8 +201,10 @@
   if (strlen(getName()) != strlen(Args.getArgString(Index)))
     return 0;
 
-  // FIXME: Missing argument error.
   Index += 1 + NumArgs;
+  if (Index > Args.getNumInputArgStrings())
+    return 0;
+
   return new SeparateArg(this, Index - 1 - NumArgs, NumArgs);
 }
 
@@ -210,15 +214,18 @@
   : Option(Option::JoinedOrSeparateClass, ID, Name, Group, Alias) {
 }
 
-Arg *JoinedOrSeparateOption::accept(const ArgList &Args, unsigned &Index) const {
+Arg *JoinedOrSeparateOption::accept(const ArgList &Args, 
+                                    unsigned &Index) const {
   // If this is not an exact match, it is a joined arg.
   // FIXME: Avoid strlen.
   if (strlen(getName()) != strlen(Args.getArgString(Index)))
     return new JoinedArg(this, Index++);
 
   // Otherwise it must be separate.
-  // FIXME: Missing argument error.
   Index += 2;
+  if (Index > Args.getNumInputArgStrings())
+    return 0;
+
   return new SeparateArg(this, Index - 2, 1);  
 }
 
@@ -229,11 +236,14 @@
   : Option(Option::JoinedAndSeparateClass, ID, Name, Group, Alias) {
 }
 
-Arg *JoinedAndSeparateOption::accept(const ArgList &Args, unsigned &Index) const {
+Arg *JoinedAndSeparateOption::accept(const ArgList &Args, 
+                                     unsigned &Index) const {
   // Always matches.
 
-  // FIXME: Missing argument error.
   Index += 2;
+  if (Index > Args.getNumInputArgStrings())
+    return 0;
+
   return new JoinedAndSeparateArg(this, Index - 2);
 }