Skip to content

Commit 09e0f68

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 849f963 commit 09e0f68

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
@@ -552,6 +552,12 @@ objcopy::parseObjcopyOptions(ArrayRef<const char *> RawArgsArr,
552552
llvm::opt::InputArgList InputArgs =
553553
T.ParseArgs(ArgsArr, MissingArgumentIndex, MissingArgumentCount);
554554

555+
if (MissingArgumentCount)
556+
return createStringError(
557+
errc::invalid_argument,
558+
"argument to '%s' is missing (expected %d value(s))",
559+
InputArgs.getArgString(MissingArgumentIndex), MissingArgumentCount);
560+
555561
if (InputArgs.size() == 0 && DashDash == RawArgsArr.end()) {
556562
printHelp(T, errs(), ToolType::Objcopy);
557563
exit(1);

0 commit comments

Comments
 (0)