mirror of
https://github.com/llvm/llvm-project.git
synced 2025-04-26 05:26:07 +00:00
[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:
parent
7630379156
commit
183beb33d7
6
llvm/test/tools/llvm-objcopy/tool-options.test
Normal file
6
llvm/test/tools/llvm-objcopy/tool-options.test
Normal 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))
|
@ -571,6 +571,12 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
|
|||||||
llvm::opt::InputArgList InputArgs =
|
llvm::opt::InputArgList InputArgs =
|
||||||
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
|
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()) {
|
if (InputArgs.size() == 0 && DashDash == RawArgsArr.end()) {
|
||||||
printHelp(T, errs(), ToolType::Objcopy);
|
printHelp(T, errs(), ToolType::Objcopy);
|
||||||
exit(1);
|
exit(1);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user