[all-commits] [llvm/llvm-project] b88308: [Support]Look up in top-level subcommand as a fall...

Mingming Liu via All-commits all-commits at lists.llvm.org
Fri Nov 10 09:22:14 PST 2023


  Branch: refs/heads/main
  Home:   https://github.com/llvm/llvm-project
  Commit: b88308b1b4813e55ce8f54ceff6e57736328fb58
      https://github.com/llvm/llvm-project/commit/b88308b1b4813e55ce8f54ceff6e57736328fb58
  Author: Mingming Liu <mingmingl at google.com>
  Date:   2023-11-10 (Fri, 10 Nov 2023)

  Changed paths:
    M llvm/lib/Support/CommandLine.cpp
    M llvm/unittests/Support/CommandLineTest.cpp

  Log Message:
  -----------
  [Support]Look up in top-level subcommand as a fallback when looking options for a custom subcommand. (#71776)

**Context:**

- In https://lists.llvm.org/pipermail/llvm-dev/2016-June/101804.html and commit 07670b3e984db32f291373fe12c392959f2aff67, `cl::SubCommand` is introduced.
- Options that don't specify subcommand goes into a special 'top level' subcommand.

**Motivating Use Case:**
- The motivating use case is to refactor `llvm-profdata` to use `cl::SubCommand` to organize subcommands. See
https://github.com/llvm/llvm-project/pull/71328. A valid use case that's not supported before this patch is shown below

```
  // show-option{1,2} are associated with 'show' subcommand.
  // top-level-option3 is in top-level subcomand (e.g., `profile-isfs` in SampleProfReader.cpp)
  llvm-profdata show --show-option1 --show-option2 --top-level-option3
```

- Before this patch, option handler look-up will fail with the following error message "Unknown command line argument --top-level-option3".
- After this patch, option handler look-up will look up in sub-command options first, and use top-level subcommand as a fallback, so 'top-level-option3' is parsed correctly.




More information about the All-commits mailing list