[llvm] [llvm-objcopy] Check for missing argument values (PR #70710)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 30 12:20:19 PDT 2023
https://github.com/quic-akaryaki created https://github.com/llvm/llvm-project/pull/70710
Report an error if a required value for a command line argument is missing.
>From 09e0f68c9402fa275b9706c96caf3c8bccbd8f52 Mon Sep 17 00:00:00 2001
From: Alexey Karyakin <akaryaki at quicinc.com>
Date: Mon, 30 Oct 2023 11:50:00 -0700
Subject: [PATCH] [llvm-objcopy] Check for missing argument values
Report an error if a required value for a command line argument
is missing.
---
llvm/test/tools/llvm-objcopy/tool-options.test | 4 ++++
llvm/tools/llvm-objcopy/ObjcopyOptions.cpp | 6 ++++++
2 files changed, 10 insertions(+)
create mode 100644 llvm/test/tools/llvm-objcopy/tool-options.test
diff --git a/llvm/test/tools/llvm-objcopy/tool-options.test b/llvm/test/tools/llvm-objcopy/tool-options.test
new file mode 100644
index 000000000000000..7116ff39485562b
--- /dev/null
+++ b/llvm/test/tools/llvm-objcopy/tool-options.test
@@ -0,0 +1,4 @@
+## 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 %s
+# RUN: not llvm-objcopy -O 2>&1 | FileCheck --check-prefix=CHECK-NO-VALUE %s
+# CHECK-NO-VALUE: error: argument to '{{.*}}' is missing
diff --git a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
index d33adb0b6a3e478..63c3873b1e94340 100644
--- a/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
+++ b/llvm/tools/llvm-objcopy/ObjcopyOptions.cpp
@@ -552,6 +552,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);
More information about the llvm-commits
mailing list