Skip to content

Commit 735214f

Browse files
committed
[llvm-objcopy] Check for missing argument values
Report an error if a required value for a command line argument is missing.
1 parent 3df7cb9 commit 735214f

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
## An error must be reported if a required argument value is missing.
2+
# RUN: not llvm-objcopy --only-section 2>&1 | FileCheck --check-prefix=CHECK-NO-VALUE %s
3+
# RUN: not llvm-objcopy -O 2>&1 | FileCheck --check-prefix=CHECK-NO-VALUE %s
4+
# CHECK-NO-VALUE: error: argument to '{{.*}}' is missing

llvm/tools/llvm-objcopy/ObjcopyOptions.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,12 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
571571
llvm::opt::InputArgList InputArgs =
572572
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
573573

574+
if (MissingArgumentCount)
575+
return createStringError(
576+
errc::invalid_argument,
577+
"argument to '%s' is missing (expected %d value(s))",
578+
InputArgs.getArgString(MissingArgumentIndex), MissingArgumentCount);
579+
574580
if (InputArgs.size() == 0 && DashDash == RawArgsArr.end()) {
575581
printHelp(T, errs(), ToolType::Objcopy);
576582
exit(1);

0 commit comments

Comments
 (0)