summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRaphael Isemann <teemperor@gmail.com>2017-09-05 12:41:00 +0000
committerRaphael Isemann <teemperor@gmail.com>2017-09-05 12:41:00 +0000
commitbd7c45e7a827ed546912b8d7b02d80e820eb3e7b (patch)
tree66b4a3c03587caab22ed93b93f5379b3822e522a
parentd331cb66f9812c309d5593119cfb25720622ce74 (diff)
downloadbcm5719-llvm-bd7c45e7a827ed546912b8d7b02d80e820eb3e7b.tar.gz
bcm5719-llvm-bd7c45e7a827ed546912b8d7b02d80e820eb3e7b.zip
[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
-rw-r--r--clang/lib/Driver/Driver.cpp10
-rw-r--r--clang/test/Driver/autocomplete.c13
2 files changed, 17 insertions, 6 deletions
diff --git a/clang/lib/Driver/Driver.cpp b/clang/lib/Driver/Driver.cpp
index c6367409eb1..765b006e909 100644
--- a/clang/lib/Driver/Driver.cpp
+++ b/clang/lib/Driver/Driver.cpp
@@ -1165,12 +1165,10 @@ void Driver::handleAutocompletions(StringRef PassedFlags) const {
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);
}
diff --git a/clang/test/Driver/autocomplete.c b/clang/test/Driver/autocomplete.c
index bfa37328d59..8b6d6cfc89c 100644
--- a/clang/test/Driver/autocomplete.c
+++ b/clang/test/Driver/autocomplete.c
@@ -2,6 +2,19 @@
// autocompletion. You may have to update tests in this file when you
// add/modify flags, change HelpTexts or the values of some flags.
+// Some corner cases.
+// RUN: %clang --autocomplete= | FileCheck %s -check-prefix=ALL_FLAGS
+// RUN: %clang --autocomplete=# | FileCheck %s -check-prefix=ALL_FLAGS
+// Let's pick some example flags that are hopefully unlikely to change.
+// ALL_FLAGS: -fast
+// ALL_FLAGS: -fastcp
+// ALL_FLAGS: -fastf
+// Just test that this doesn't crash:
+// RUN: %clang --autocomplete=,
+// RUN: %clang --autocomplete==
+// RUN: %clang --autocomplete=,,
+// RUN: %clang --autocomplete=-
+
// RUN: %clang --autocomplete=-fsyn | FileCheck %s -check-prefix=FSYN
// FSYN: -fsyntax-only
// RUN: %clang --autocomplete=-std= | FileCheck %s -check-prefix=STD
OpenPOWER on IntegriCloud