clang -cc1: confusing behaviour with multiple actions

hello,

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 (⚙ D111781 [flang] Make the frontend driver error out when requesting multiple actions), 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!
-Andrzej

[1] Options decorated with `Action_Group` in Options.td (llvm-project/Options.td at main · llvm/llvm-project · GitHub)
[2] llvm-project/CompilerInvocation.cpp at main · llvm/llvm-project · GitHub
[3] [flang-dev] [RFC] Frontend driver: action vs non-action options

The whole "-cc1" interface is an internal interface and the user is not
supposed to interact with it at all. As such, no sanity checks are
required.

Joerg