[Bash-autocomplete] Fix crash when invoking --autocomplete without value.

Summary:
Currently clang segfaults when invoked with `clang --autocomplete=`.
This patch adds the necessary boundary checks and some tests for corner cases like this.

Reviewers: yamaguchi

Reviewed By: yamaguchi

Subscribers: cfe-commits

Differential Revision: https://reviews.llvm.org/D37465

llvm-svn: 312533
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index c636740..765b006 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1165,12 +1165,10 @@
   unsigned short DisableFlags =
       options::NoDriverOption | options::Unsupported | options::Ignored;
   // We want to show cc1-only options only when clang is invoked as "clang
-  // -cc1".
-  // When clang is invoked as "clang -cc1", we add "#" to the beginning of an
-  // --autocomplete
-  // option so that the clang driver can distinguish whether it is requested to
-  // show cc1-only options or not.
-  if (PassedFlags[0] == '#') {
+  // -cc1". When clang is invoked as "clang -cc1", we add "#" to the beginning
+  // of an --autocomplete  option so that the clang driver can distinguish
+  // whether it is requested to show cc1-only options or not.
+  if (PassedFlags.size() > 0 && PassedFlags[0] == '#') {
     DisableFlags &= ~options::NoDriverOption;
     PassedFlags = PassedFlags.substr(1);
   }