aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Option/OptTable.cpp
diff options
context:
space:
mode:
authorgbreynoo <Owen.Reynolds@sony.com>2021-08-31 16:41:08 +0100
committergbreynoo <Owen.Reynolds@sony.com>2021-08-31 16:41:08 +0100
commit71d7fed3bc2ad6c22729d446526a59fcfd99bd03 (patch)
treef0eaf692d5dafd6378e37eb2ffaf6cd032c8c9ff /llvm/lib/Option/OptTable.cpp
parentc9948e9254fbb6ea00f66c7b4542311d21e060be (diff)
downloadllvm-71d7fed3bc2ad6c22729d446526a59fcfd99bd03.zip
llvm-71d7fed3bc2ad6c22729d446526a59fcfd99bd03.tar.gz
llvm-71d7fed3bc2ad6c22729d446526a59fcfd99bd03.tar.bz2
[OptTable] Improve error message output for grouped short options
As seen in https://bugs.llvm.org/show_bug.cgi?id=48880 the current implementation for parsing grouped short options can return unclear error messages. This change fixes the example given in the ticket in which a flag is incorrectly given an argument. Also when parsing a group we now keep reading past the first incorrect option and output errors for all incorrect options in the group. Differential Revision: https://reviews.llvm.org/D108770
Diffstat (limited to 'llvm/lib/Option/OptTable.cpp')
-rw-r--r--llvm/lib/Option/OptTable.cpp17
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp
index a994a42..2770f4d41 100644
--- a/llvm/lib/Option/OptTable.cpp
+++ b/llvm/lib/Option/OptTable.cpp
@@ -376,14 +376,23 @@ Arg *OptTable::parseOneArgGrouped(InputArgList &Args, unsigned &Index) const {
if (Fallback) {
Option Opt(Fallback, this);
if (Arg *A = Opt.accept(Args, Str.substr(0, 2), true, Index)) {
- if (Str.size() == 2)
- ++Index;
- else
- Args.replaceArgString(Index, Twine('-') + Str.substr(2));
+ // Check that the last option isn't a flag wrongly given an argument.
+ if (Str[2] == '=')
+ return new Arg(getOption(TheUnknownOptionID), Str, Index++, CStr);
+
+ Args.replaceArgString(Index, Twine('-') + Str.substr(2));
return A;
}
}
+ // In the case of an incorrect short option extract the character and move to
+ // the next one.
+ if (Str[1] != '-') {
+ CStr = Args.MakeArgString(Str.substr(0, 2));
+ Args.replaceArgString(Index, Twine('-') + Str.substr(2));
+ return new Arg(getOption(TheUnknownOptionID), CStr, Index, CStr);
+ }
+
return new Arg(getOption(TheUnknownOptionID), Str, Index++, CStr);
}