<div dir="ltr">+Hans<div><br></div><div>I think Hans and I are the ones most responsible for the behavior of clang-cl --help. For our part, we made sure that clang-cl --help prints something useful, but did our best to leave the rest of the existing mess alone. If you make changes, please check that the clang-cl --help output remains as useful as possible, since we have made an effort to curate that with help text.</div><div><br></div><div>I think any changes you propose in this area will probably be an improvement over the current situation. </div><div><br></div><div>I would encourage you to try to improve the LLVM Option library if you can, but obviously it's always not straightforward. Most of the other clients (some LLVM tools, LLD) are pretty simple and easy to update for new APIs.</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Wed, Oct 7, 2020 at 12:33 PM Andrzej Warzynski via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org">cfe-dev@lists.llvm.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi all,<br>
<br>
We are in the process of adding Flang-specific options to libclangDriver <br>
and want to make sure that we don't pollute `clang -help` or `flang <br>
-help` with irrelevant options.<br>
<br>
# *PROBLEM IN GENERAL*<br>
I have been looking at clang/include/Driver/Options.td (and various <br>
files that define/modify/print compiler driver options) and I am not <br>
sure what the expected implementation and behaviour should be. For <br>
example, looking at ClangFlags [1], should `clang -help` display options <br>
flagged as `CC1Option` and `CC1AsOption`? Shouldn't these be reserved <br>
for `clang -cc1 -help` and `clang -cc1as -help`, respectively?<br>
<br>
What about `DriverOption` and `NoDriverOption`? Based on the <br>
descriptions in Options.td [2], I would assume that only one of these <br>
flags is be needed. Also, the current implementation of libclangDriver <br>
seem to focus on `clang -help` vs `clang-cl -help` split [3]. Lastly, <br>
`clang -help` prints a lot of options - should all of these be printed?<br>
<br>
I'm bringing this up because we want to add Flang-specific options (i.e. <br>
an option that's printed by `flang -help`, but not printed by `clang <br>
-help`), and that's proving quite tricky. To this end, we recently have <br>
submitted a patch that adds yet another item in ClangFlags (see <br>
`NoClangOption` in [4], still in review!). However, it feels that if <br>
libclangDriver was stricter about filtering the options (based on the <br>
flags), we could avoid that.<br>
<br>
# *PROBLEM IN DETAIL*<br>
IIUC, libclangDriver should clearly define what flags should be <br>
included/excluded when passing `-help` to `clang` and other tools. <br>
Currently this is a bit vague (from Driver.cpp [5]):<br>
<br>
```<br>
unsigned IncludedFlagsBitmask = 0;<br>
```<br>
<br>
It boils down to "print most of the options available". Wouldn't the <br>
following, more explicit approach, be preferred (example for `clang`):<br>
<br>
```<br>
unsigned IncludedFlagsBitmask =<br>
options::DriverOption |<br>
options::NoArgumentUnused |<br>
options::CoreOption |<br>
options::LinkOption<br>
```<br>
<br>
? However, there's a problem with this approach too: `clang -help` will <br>
stop working as the definition of `help` contains none of the above <br>
flags [6]:<br>
<br>
```<br>
def help : Flag<["-", "--"], "help">, Flags<[CC1Option,CC1AsOption, <br>
FC1Option, FlangOption]>,<br>
HelpText<"Display available options">;<br>
```<br>
<br>
This can be fixed by e.g. adding `CoreOption` to the definition above. <br>
But there will be more options with similar problem. There's also a <br>
group of options that contain no flags at all (so it's hard to classify <br>
them). What should happen with them?<br>
<br>
# *LLVM's OPTTABLE*<br>
Perhaps we should improve this in LLVM in OptTable.{h|cpp} instead? For <br>
instance, what's the relation between FlagsToExclude and FlagsToInclude <br>
[7]? Which one takes precedence? Note that any changes in LLVM's <br>
OptTable will have impact beyond Clang and Flang, so I don't want dive <br>
too deep into this in this RFC. But I suspect that refining that API a <br>
bit could help Clang and Flang.<br>
<br>
# *SUGGESTION*<br>
I think that some of these issues could be resolved (or at least <br>
improved) if:<br>
* all options defined in clang's Options.td were required to contain a <br>
flag or otherwise be ignored<br>
* every flag clearly communicated the mode (e.g. compiler driver vs <br>
frontend driver) in which particular option is available (i.e. there <br>
should be no need for `DriverOption` _and_ `NoDriverOption`)<br>
* every tool (e.g. `clang` or `clang -cc1`) was more explicit about <br>
the supported options (or, at least, options displayed when passing `-help`)<br>
<br>
Do these suggestions make sense? Is my reasoning valid? Or did I get it <br>
completely wrong? :)<br>
<br>
Thanks for reading!<br>
On behalf of the Arm Fortran team,<br>
-Andrzej<br>
<br>
[1] <br>
<a href="https://github.com/llvm/llvm-project/blob/25692b7765e2364896a0136f5b54dde3de2dd563/clang/include/clang/Driver/Options.h#L26-L40" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/25692b7765e2364896a0136f5b54dde3de2dd563/clang/include/clang/Driver/Options.h#L26-L40</a><br>
[2] <br>
<a href="https://github.com/llvm/llvm-project/blob/25692b7765e2364896a0136f5b54dde3de2dd563/clang/include/clang/Driver/Options.td#L19-L20" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/25692b7765e2364896a0136f5b54dde3de2dd563/clang/include/clang/Driver/Options.td#L19-L20</a><br>
[3] <br>
<a href="https://github.com/llvm/llvm-project/blob/25692b7765e2364896a0136f5b54dde3de2dd563/clang/lib/Driver/Driver.cpp#L5261-L5279" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/25692b7765e2364896a0136f5b54dde3de2dd563/clang/lib/Driver/Driver.cpp#L5261-L5279</a><br>
[4] <a href="https://reviews.llvm.org/D87989" rel="noreferrer" target="_blank">https://reviews.llvm.org/D87989</a><br>
[5] <br>
<a href="https://github.com/llvm/llvm-project/blob/25692b7765e2364896a0136f5b54dde3de2dd563/clang/lib/Driver/Driver.cpp#L5263" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/25692b7765e2364896a0136f5b54dde3de2dd563/clang/lib/Driver/Driver.cpp#L5263</a><br>
[6] <br>
<a href="https://github.com/llvm/llvm-project/blob/master/clang/include/clang/Driver/Options.td#L2131-L2132" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/master/clang/include/clang/Driver/Options.td#L2131-L2132</a><br>
[7] <br>
<a href="https://github.com/llvm/llvm-project/blob/25692b7765e2364896a0136f5b54dde3de2dd563/llvm/include/llvm/Option/OptTable.h#L173-L175" rel="noreferrer" target="_blank">https://github.com/llvm/llvm-project/blob/25692b7765e2364896a0136f5b54dde3de2dd563/llvm/include/llvm/Option/OptTable.h#L173-L175</a><br>
_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
</blockquote></div>