aboutsummaryrefslogtreecommitdiff
path: root/llvm/unittests/Support/CommandLineTest.cpp
diff options
context:
space:
mode:
authorFangrui Song <i@maskray.me>2022-03-11 11:25:04 -0800
committerFangrui Song <i@maskray.me>2022-03-11 11:25:04 -0800
commitbd0bddc1ea72183813d49508c8b4e73920869ea5 (patch)
tree2e8e5c65307056b4e083136963997db0efdd0482 /llvm/unittests/Support/CommandLineTest.cpp
parent68099b1d5c2c99ff79e56a9e183f1601835ea244 (diff)
downloadllvm-bd0bddc1ea72183813d49508c8b4e73920869ea5.zip
llvm-bd0bddc1ea72183813d49508c8b4e73920869ea5.tar.gz
llvm-bd0bddc1ea72183813d49508c8b4e73920869ea5.tar.bz2
[CommandLine] Remove `may only occur zero or one times!` error
Early adoption of new technologies or adjusting certain code generation/IR optimization thresholds is often available through some cl::opt options (which have unstable surfaces). Specifying such an option twice will lead to an error. ``` % clang -c a.c -mllvm -disable-binop-extract-shuffle -mllvm -disable-binop-extract-shuffle clang (LLVM option parsing): for the --disable-binop-extract-shuffle option: may only occur zero or one times! % clang -c a.c -mllvm -hwasan-instrument-reads=0 -mllvm -hwasan-instrument-reads=0 clang (LLVM option parsing): for the --hwasan-instrument-reads option: may only occur zero or one times! % clang -c a.c -mllvm --scalar-evolution-max-arith-depth=32 -mllvm --scalar-evolution-max-arith-depth=16 clang (LLVM option parsing): for the --scalar-evolution-max-arith-depth option: may only occur zero or one times! ``` The option is specified twice, because there is sometimes a global setting and a specific file or project may need to override (or duplicately specify) the value. The error is contrary to the common practice of getopt/getopt_long command line utilities that let the last option win and the `getLastArg` behavior used by Clang driver options. I have seen such errors for several times. I think the error just makes users inconvenient, while providing very little value on discouraging production usage of unstable surfaces (this goal is itself controversial, because developers might not want to commit to a stable surface too early, or there is just some subtle codegen toggle which is infeasible to have a driver option). Therefore, I suggest we drop the diagnostic, at least before the diagnostic gets sufficiently better support for the overridding needs. Removing the error is a degraded error checking experience. I think this error checking behavior, if desirable, should be enabled explicitly by tools. Users preferring the behavior can figure out a way to do so. Reviewed By: jhenderson, rnk Differential Revision: https://reviews.llvm.org/D120455
Diffstat (limited to 'llvm/unittests/Support/CommandLineTest.cpp')
-rw-r--r--llvm/unittests/Support/CommandLineTest.cpp8
1 files changed, 8 insertions, 0 deletions
diff --git a/llvm/unittests/Support/CommandLineTest.cpp b/llvm/unittests/Support/CommandLineTest.cpp
index 7fe1cf4..e68761e 100644
--- a/llvm/unittests/Support/CommandLineTest.cpp
+++ b/llvm/unittests/Support/CommandLineTest.cpp
@@ -420,6 +420,14 @@ TEST(CommandLineTest, HideUnrelatedOptionsMulti) {
<< "Hid default option that should be visable.";
}
+TEST(CommandLineTest, SetMultiValues) {
+ StackOption<int> Option("option");
+ const char *args[] = {"prog", "-option=1", "-option=2"};
+ EXPECT_TRUE(cl::ParseCommandLineOptions(array_lengthof(args), args,
+ StringRef(), &llvm::nulls()));
+ EXPECT_EQ(Option, 2);
+}
+
TEST(CommandLineTest, SetValueInSubcategories) {
cl::ResetCommandLineParser();