diff options
author | gbreynoo <Owen.Reynolds@sony.com> | 2021-09-03 11:08:39 +0100 |
---|---|---|
committer | gbreynoo <Owen.Reynolds@sony.com> | 2021-09-03 11:13:52 +0100 |
commit | e28cd75a5039893db5861f49eeea9eb5b59bdcdc (patch) | |
tree | 90bf63ad2eab8c590dd9e959d0dc4d61d334b915 /llvm/lib/Option/OptTable.cpp | |
parent | 9e3f86e273d07786f5efa41494581e4971d8b0c0 (diff) | |
download | llvm-e28cd75a5039893db5861f49eeea9eb5b59bdcdc.zip llvm-e28cd75a5039893db5861f49eeea9eb5b59bdcdc.tar.gz llvm-e28cd75a5039893db5861f49eeea9eb5b59bdcdc.tar.bz2 |
[OptTable] Reapply Improve error message output for grouped short options
This reapplies 71d7fed3bc2ad6c22729d446526a59fcfd99bd03 which was
reverted by 3e2bd82f02c6cbbfb0544897c7645867f04b3a7e. This change
includes the fix for breaking the sanitizer bots.
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.cpp | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/llvm/lib/Option/OptTable.cpp b/llvm/lib/Option/OptTable.cpp index a994a42..1bf63a7 100644 --- a/llvm/lib/Option/OptTable.cpp +++ b/llvm/lib/Option/OptTable.cpp @@ -375,15 +375,24 @@ Arg *OptTable::parseOneArgGrouped(InputArgList &Args, unsigned &Index) const { } if (Fallback) { Option Opt(Fallback, this); + // Check that the last option isn't a flag wrongly given an argument. + if (Str[2] == '=') + return new Arg(getOption(TheUnknownOptionID), Str, Index++, CStr); + 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)); + 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); } |