[PATCH] D120455: [CommandLine] Remove `may only occur zero or one times!` error

Fangrui Song via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Feb 23 22:57:09 PST 2022


MaskRay created this revision.
MaskRay added reviewers: jhenderson, rnk, rriddle.
Herald added subscribers: sdasgup3, wenzhicui, wrengr, Chia-hungDuan, dcaballe, cota, teijeong, dexonsmith, rdzhabarov, tatianashp, msifontes, jurahul, Kayjukh, grosul1, Joonsoo, liufengdb, aartbik, mgester, arpith-jacob, antiagainst, shauheen, mehdi_amini, hiraditya.
MaskRay requested review of this revision.
Herald added subscribers: llvm-commits, stephenneuendorffer, nicolasvasilache.
Herald added projects: MLIR, LLVM.

Command line utilities using getopt/getopt_long typically let the last option
win. This makes overridding convenient if there is a global setting.
Clang driver options match the behavior with `getLastArg`.
However, cl::opt diverges from the traditional behavior by reporting an error,
therefore makeing workaround difficult:

  % 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 --scalar-evolution-max-arith-depth=32 -mllvm --scalar-evolution-max-arith-depth=32
  clang (LLVM option parsing): for the --scalar-evolution-max-arith-depth option: may only occur zero or one times!

I have seen such needs several times and the `may only occur zero or one
times!` error is quite a pain. I think cl::opt should match the traditional
behavior.

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. I am biased toward
matching the traditional behavior.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D120455

Files:
  llvm/lib/Support/CommandLine.cpp
  llvm/test/tools/llvm-libtool-darwin/create-static-lib.test
  llvm/test/tools/llvm-libtool-darwin/deterministic-library.test
  llvm/test/tools/llvm-libtool-darwin/filelist.test
  llvm/test/tools/llvm-libtool-darwin/invalid-input-output-args.test
  mlir/test/Pass/pipeline-options-parsing.mlir

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D120455.411012.patch
Type: text/x-patch
Size: 7461 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220224/10e480e2/attachment.bin>


More information about the llvm-commits mailing list