[all-commits] [llvm/llvm-project] bd0bdd: [CommandLine] Remove `may only occur zero or one t...

Fangrui Song via All-commits all-commits at lists.llvm.org
Fri Mar 11 11:25:16 PST 2022


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: bd0bddc1ea72183813d49508c8b4e73920869ea5
      https://github.com/llvm/llvm-project/commit/bd0bddc1ea72183813d49508c8b4e73920869ea5
  Author: Fangrui Song <i at maskray.me>
  Date:   2022-03-11 (Fri, 11 Mar 2022)

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

  Log Message:
  -----------
  [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




More information about the All-commits mailing list