[clang] cc1: Report an error for multiple actions unless separated by -main-file-name (PR #91140)

Jan Svoboda via cfe-commits cfe-commits at lists.llvm.org
Sun May 5 22:56:33 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")) {
----------------
jansvoboda11 wrote:

Any reason why use string-based prefix instead of checking for the `OPT_` enums?

https://github.com/llvm/llvm-project/pull/91140


More information about the cfe-commits mailing list