[all-commits] [llvm/llvm-project] 926e51: [Option] Support special argument "--"

Fangrui Song via All-commits all-commits at lists.llvm.org
Wed Jun 7 08:06:19 PDT 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: 926e51c1370c711946e4b04101008773ea9d2052
      https://github.com/llvm/llvm-project/commit/926e51c1370c711946e4b04101008773ea9d2052
  Author: Fangrui Song <i at maskray.me>
  Date:   2023-06-07 (Wed, 07 Jun 2023)

  Changed paths:
    M llvm/include/llvm/Option/OptTable.h
    M llvm/lib/Option/OptTable.cpp
    A llvm/test/tools/llvm-strings/dash-filename.test
    M llvm/tools/llvm-strings/llvm-strings.cpp
    M llvm/unittests/Option/OptionParsingTest.cpp
    M llvm/unittests/Option/Opts.td

  Log Message:
  -----------
  [Option] Support special argument "--"

Many command line option implementations, including getopt_long and our
Support/CommandLine.cpp, support `--` as an end-of-option indicator. All
the subsequent arguments are then treated as positional arguments.

D1387 added KIND_REMAINING_ARGS and 76ff1d915c9c42823a3f2b08ff936cf7a48933c5 dropped special handling of `--`.
Users need to add `def DASH_DASH : Option<["--"], "", KIND_REMAINING_ARGS>;` and
append `OPT_DASH_DASH` to the `OPT_INPUT` list., which is not ergonomic.

Restore this feature under an option and modify llvm-strings to utilize the
feature as an example. In the future, we probably should enable this feature by
default and exclude some tools that handle `DASH_DASH` differently (clang,
clang-scan-deps, etc. I suspect that many are workarounds for LLVMOption not
supporting `--` as a built-in feature).

Reviewed By: serge-sans-paille

Differential Revision: https://reviews.llvm.org/D152286




More information about the All-commits mailing list