[cfe-dev] clang -cc1: confusing behaviour with multiple actions

Andrzej Warzynski via cfe-dev cfe-dev at lists.llvm.org
Tue Oct 19 04:57:48 PDT 2021


Clang's frontend driver, `clang -cc1`, will only run one action at a 
time. If multiple action options [1] are specified, only the rightmost 
one is run [2]. So in the following invocation, only `-dump-tokens` will 
be used:

clang -cc1 -ast-dump -dump-tokens file.c

Conversely, only `-ast-dump` will be run below:

clang -cc1 -dump-tokens -ast-dump file.c

No warning or error is issued, which is a bit counter-intuitive. Also, 
with one-action-at-a-time rule, only one type of information can be 
dumped per invocation (as in the example above). Is there any particular 
reason not to warn users (or to error out) when multiple actions are 
specified? And why not allow multiple "dump" options per invocation?

Flang's frontend driver exhibits similar behaviour - we've been 
discussing this on flang-dev [3]. We've considered extending the 
`ArgList` API to for such scenarios (https://reviews.llvm.org/D111781), 
but I'm not sure whether that's the right approach. Also, I wanted to 
better understand the rationale in Clang first.

Thank you for reading!

[1] Options decorated with `Action_Group` in Options.td 
[3] https://lists.llvm.org/pipermail/flang-dev/2021-October/000822.html

More information about the cfe-dev mailing list