[PATCH] D121560: [clang][Opt] Add NoArgUnusedWith to not warn for unused redundant options

Alex Brachet via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Sun Mar 13 16:17:20 PDT 2022


abrachet marked an inline comment as done.
abrachet added a comment.

In D121560#3378181 <https://reviews.llvm.org/D121560#3378181>, @MaskRay wrote:

>> This patch adds an example for -static-libcxx and -nostdlib.
>
> We have -static-libstdc++ but not -static-libc++. (D53238 <https://reviews.llvm.org/D53238> attempts to add `-static` and name it `-static=c++stdlib`)

Thank you, updated the description

>> NoArgUnusedWith can be used for options which together are redundant or not meaningful.
>
> I agree that `-Wunused-command-line-argument` sometimes gets in the way and removing the warnings is sometimes inconvenient.
>
> You can currently avoid the warning with: `--start-no-unused-arguments -static-libstdc++ --end-no-unused-arguments`.

Yeah, we are currently using this in some places, but if you just globally set `-static-libstdc++` as `--start-no-unused-arguments -static-libstdc++ --end-no-unused-arguments`, then you lose out when it should actually warn. Likewise right now we set `-Wno-unused-command-line-argument` in a few places where this is an issue

> For `NoArgUnusedWith`, intuitively I am unsure it is the desired interface. For `-static-libstdc++`, you probably want to remove the diagnostic with `-nostdlib++` and `-nodefaultlibs` as well. There are just so many similar options.

Added to the example both of these flags to show `NoArgUnusedWith` can support multiple flags. There's a lot more redundant flags, and I'll get to some in follow up patches



================
Comment at: clang/lib/Driver/Driver.cpp:4426
 
+  std::function<bool(llvm::opt::DerivedArgList &, Arg *)> ConsideredUsed =
+      [&ConsideredUsed](llvm::opt::DerivedArgList &Args, Arg *A) {
----------------
MaskRay wrote:
> Unless you want to capture it somewhere.
Indeed, `ConsideredUsed` is used in the llvm::any_of call


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D121560/new/

https://reviews.llvm.org/D121560



More information about the llvm-commits mailing list