-
Notifications
You must be signed in to change notification settings - Fork 15.9k
cc1: Report an error for multiple actions unless separated by -main-file-name #91140
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -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")) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any reason why use string-based prefix instead of checking for the
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Since there are 3+ |
||
| const Arg *SavedAction = nullptr; | ||
| for (const Arg *AA : | ||
| Args.filtered(OPT_Action_Group, OPT_main_file_name)) { | ||
| if (AA->getOption().matches(OPT_main_file_name)) { | ||
| SavedAction = nullptr; | ||
| } else if (!SavedAction) { | ||
| SavedAction = AA; | ||
| } else { | ||
| if (!A->getOption().matches(OPT_ast_dump_EQ)) | ||
| Diags.Report(diag::err_fe_invalid_multiple_actions) | ||
| << A->getSpelling() << SavedAction->getSpelling(); | ||
| break; | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
|
||
| if (const Arg* A = Args.getLastArg(OPT_plugin)) { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,7 @@ | ||
| // RUN: not %clang_cc1 -S -emit-llvm -main-file-name %s 2>&1 | FileCheck %s --check-prefix=ERR1 --implicit-check-not=error: | ||
| // ERR1: error: action -emit-llvm is specified, another action is not allowed: -S | ||
|
|
||
| // RUN: not %clang_cc1 -main-file-name %s -emit-llvm-only -emit-llvm -S 2>&1 | FileCheck %s --check-prefix=ERR2 --implicit-check-not=error: | ||
| // ERR2: error: action -S is specified, another action is not allowed: -emit-llvm-only | ||
|
|
||
| // RUN: %clang_cc1 -S -main-file-name %s -emit-llvm -o /dev/null |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe something like this? I dont think the original fits very well? Also the single ticks around the actions is, IMO, better for readability.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion. I adopted it by swapping %1 and %0 ...