diff options
author | Igor Kudrin <ikudrin@accesssoftek.com> | 2019-03-01 09:20:56 +0000 |
---|---|---|
committer | Igor Kudrin <ikudrin@accesssoftek.com> | 2019-03-01 09:20:56 +0000 |
commit | 875f05828d95251abe7c943d79399a3b1c80db12 (patch) | |
tree | bda5a205e962c01a076fe5ef6c2dfe7a84319a14 /llvm/lib/Support/CommandLine.cpp | |
parent | 88c643abf1df624a0402658c74359b6b17f6a86a (diff) | |
download | bcm5719-llvm-875f05828d95251abe7c943d79399a3b1c80db12.tar.gz bcm5719-llvm-875f05828d95251abe7c943d79399a3b1c80db12.zip |
[CommandLine] Do not crash if an option has both ValueRequired and Grouping.
If an option, which requires a value, has a `cl::Grouping` formatting
modifier, it works well as far as it is used at the end of a group,
or as a separate argument. However, if the option appears accidentally
in the middle of a group, the program just crashes. This patch prints
an error message instead.
Differential Revision: https://reviews.llvm.org/D58499
llvm-svn: 355184
Diffstat (limited to 'llvm/lib/Support/CommandLine.cpp')
-rw-r--r-- | llvm/lib/Support/CommandLine.cpp | 11 |
1 files changed, 7 insertions, 4 deletions
diff --git a/llvm/lib/Support/CommandLine.cpp b/llvm/lib/Support/CommandLine.cpp index b0c92b7c72c..8b279baf8d6 100644 --- a/llvm/lib/Support/CommandLine.cpp +++ b/llvm/lib/Support/CommandLine.cpp @@ -671,10 +671,13 @@ HandlePrefixedOrGroupedOption(StringRef &Arg, StringRef &Value, StringRef OneArgName = Arg.substr(0, Length); Arg = Arg.substr(Length); - // Because ValueRequired is an invalid flag for grouped arguments, - // we don't need to pass argc/argv in. - assert(PGOpt->getValueExpectedFlag() != cl::ValueRequired && - "Option can not be cl::Grouping AND cl::ValueRequired!"); + if (PGOpt->getValueExpectedFlag() == cl::ValueRequired) { + ErrorParsing |= PGOpt->error("may not occur within a group!"); + return nullptr; + } + + // Because the value for the option is not required, we don't need to pass + // argc/argv in. int Dummy = 0; ErrorParsing |= ProvideOption(PGOpt, OneArgName, StringRef(), 0, nullptr, Dummy); |