[clang] cc1: Report an error for multiple actions unless separated by -main-file-name (PR #91140)
Fangrui Song via cfe-commits
cfe-commits at lists.llvm.org
Mon May 6 09:53:45 PDT 2024
================
@@ -2841,6 +2841,30 @@ static bool ParseFrontendArgs(FrontendOptions &Opts, ArgList &Args,
}
Opts.ProgramAction = *ProgramAction;
+
+ // Catch common mistakes when multiple actions are specified for cc1 (e.g.
+ // -S -emit-llvm means -emit-llvm while -emit-llvm -S means -S). However, to
+ // support driver `-c -Xclang ACTION` (-cc1 -emit-llvm file -main-file-name
+ // X ACTION), we suppress the error when the two actions are separated by
+ // -main-file-name.
+ //
+ // As an exception, accept composable -ast-dump*.
+ if (!A->getSpelling().starts_with("-ast-dump")) {
----------------
MaskRay wrote:
`-ast-dump -ast-dump-lookups` and `-ast-dump-lookups -ast-dump` are composable. `llvm/utils/update_cc_test_checks.py` appends `-ast-dump=json` when the cc1 command line may contain another action option.
Since there are 3+ `-ast-dump*` options that need an exception, I feel that `starts_with("-ast-dump"))` is simpler than listing all `OPT_ast_dump*`..
https://github.com/llvm/llvm-project/pull/91140
More information about the cfe-commits
mailing list