[cfe-dev] Understanding Options.td

Richard Smith via cfe-dev cfe-dev at lists.llvm.org
Tue Mar 5 13:20:05 PST 2019


On Tue, 5 Mar 2019 at 13:01, David Greene via cfe-dev
<cfe-dev at lists.llvm.org> wrote:
> David Blaikie via cfe-dev <cfe-dev at lists.llvm.org> writes:
> > I haven't looked - but my first guess at an argument to seek
> > inspiration from, would be -fuse-ld. See how that's handled, how it
> > warns if the compiler isn't doing a link action, etc.
>
> I grepped around but didn't see anything obvious that tells clang to
> emit the warning for use in a non-linking context.  clang does emit the
> warning so I am puzzled about how that happens.

Clang warns on all command-line arguments that are not "claimed".
Arguments are "claimed" by any operation that looks for them (eg,
getLastArg, hasFlag, ...) as well as by explicit ClaimAllArgs calls.
So, if you add a new option, then by default you get the "unused
option" diagnostic for free, and the diagnostic is automatically
suppressed if you actually use the argument in the driver (eg, by
looking for it, or by passing it into some subtool invocation).

Groups in Options.td serve a few purposes:

 - they (optionally) control how the --help output is grouped (if
HelpText is provided)
 - they (optionally) control how
http://clang.llvm.org/docs/ClangCommandLineReference.html is grouped
(if DocFlatten is not specified)
 - they control how the arguments are grouped by tools that dump
clang's list of arguments (I think XCode does this and tab-completion
might do so too)
 - they provide a mechanism to allow the driver code to easily refer
to all arguments of a given kind, for instance to propagate all flags
of some kind to a subtool or claim all of them (grep for _Group in
lib/Driver to see these cases)

> The definition looks simple enough:
>
> def fuse_ld_EQ : Joined<["-"], "fuse-ld=">, Group<f_Group>, Flags<[CoreOption]>;
>
> It must not have anything to do with the TableGen definition.
>
>                            -David
> _______________________________________________
> cfe-dev mailing list
> cfe-dev at lists.llvm.org
> https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev



More information about the cfe-dev mailing list