[llvm-objcopy] Check for missing argument values (#70710)

Report an error if a required value for a command line argument is
missing.
This commit is contained in:
Alexey Karyakin 2024-05-22 09:38:44 -05:00 committed by GitHub
parent 7630379156
commit 183beb33d7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 0 deletions

View File

@ -0,0 +1,6 @@
## An error must be reported if a required argument value is missing.
# RUN: not llvm-objcopy --only-section 2>&1 | FileCheck --check-prefix=CHECK-NO-VALUE-ONLY-SECTION %s
# CHECK-NO-VALUE-ONLY-SECTION: error: argument to '--only-section' is missing (expected 1 value(s))
# RUN: not llvm-objcopy -O 2>&1 | FileCheck --check-prefix=CHECK-NO-VALUE-O %s
# CHECK-NO-VALUE-O: error: argument to '-O' is missing (expected 1 value(s))

View File

@ -571,6 +571,12 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
llvm::opt::InputArgList InputArgs =
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
if (MissingArgumentCount)
return createStringError(
errc::invalid_argument,
"argument to '%s' is missing (expected %d value(s))",
InputArgs.getArgString(MissingArgumentIndex), MissingArgumentCount);
if (InputArgs.size() == 0 && DashDash == RawArgsArr.end()) {
printHelp(T, errs(), ToolType::Objcopy);
exit(1);