[PATCH] D92857: [clang][cli] [clang][cli] Don't always emit -f[no-]legacy-pass-manager
Jan Svoboda via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Fri Dec 11 05:49:40 PST 2020
jansvoboda11 updated this revision to Diff 311193.
jansvoboda11 added a comment.
Extract default value
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D92857/new/
https://reviews.llvm.org/D92857
Files:
clang/unittests/Frontend/CompilerInvocationTest.cpp
llvm/include/llvm/Option/OptParser.td
Index: llvm/include/llvm/Option/OptParser.td
===================================================================
--- llvm/include/llvm/Option/OptParser.td
+++ llvm/include/llvm/Option/OptParser.td
@@ -173,7 +173,6 @@
class MarshallingInfoBooleanFlag<code keypath, code defaultvalue, code neg_name, string neg_spelling>
: MarshallingInfoFlag<keypath, defaultvalue> {
- bit ShouldAlwaysEmit = 1;
code Normalizer = "makeBooleanFlagNormalizer(OPT_"#neg_name#")";
code Denormalizer = "makeBooleanFlagDenormalizer(\""#neg_spelling#"\")";
}
Index: clang/unittests/Frontend/CompilerInvocationTest.cpp
===================================================================
--- clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -177,51 +177,53 @@
// The flag with positive spelling can set the keypath to true.
// The flag with negative spelling can set the keypath to false.
+static constexpr unsigned PassManagerDefault =
+ !static_cast<unsigned>(LLVM_ENABLE_NEW_PASS_MANAGER);
+
+static constexpr const char *PassManagerResetByFlag =
+ LLVM_ENABLE_NEW_PASS_MANAGER ? "-fno-legacy-pass-manager"
+ : "-flegacy-pass-manager";
+
+static constexpr const char *PassManagerChangedByFlag =
+ LLVM_ENABLE_NEW_PASS_MANAGER ? "-flegacy-pass-manager"
+ : "-fno-legacy-pass-manager";
+
TEST_F(CommandLineTest, BoolOptionDefaultArbitraryTwoFlagsPresentNone) {
const char *Args = {""};
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
ASSERT_FALSE(Diags->hasErrorOccurred());
- ASSERT_EQ(Invocation.getCodeGenOpts().LegacyPassManager,
- !static_cast<unsigned>(LLVM_ENABLE_NEW_PASS_MANAGER));
+ ASSERT_EQ(Invocation.getCodeGenOpts().LegacyPassManager, PassManagerDefault);
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
- const char *ResetByFlag = LLVM_ENABLE_NEW_PASS_MANAGER
- ? "-fno-legacy-pass-manager"
- : "-flegacy-pass-manager";
-
- const char *ChangedByFlag = LLVM_ENABLE_NEW_PASS_MANAGER
- ? "-flegacy-pass-manager"
- : "-fno-legacy-pass-manager";
-
- ASSERT_THAT(GeneratedArgs, Contains(StrEq(ResetByFlag)));
- ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq(ChangedByFlag))));
+ ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq(PassManagerResetByFlag))));
+ ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq(PassManagerChangedByFlag))));
}
-TEST_F(CommandLineTest, BoolOptionDefaultArbitraryTwoFlagsPresentPos) {
- const char *Args[] = {"-flegacy-pass-manager"};
+TEST_F(CommandLineTest, BoolOptionDefaultArbitraryTwoFlagsPresentChange) {
+ const char *Args[] = {PassManagerChangedByFlag};
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
ASSERT_FALSE(Diags->hasErrorOccurred());
- ASSERT_TRUE(Invocation.getCodeGenOpts().LegacyPassManager);
+ ASSERT_EQ(Invocation.getCodeGenOpts().LegacyPassManager, !PassManagerDefault);
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
- ASSERT_THAT(GeneratedArgs, Contains(StrEq("-flegacy-pass-manager")));
- ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-legacy-pass-manager"))));
+ ASSERT_THAT(GeneratedArgs, Contains(StrEq(PassManagerChangedByFlag)));
+ ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq(PassManagerResetByFlag))));
}
-TEST_F(CommandLineTest, BoolOptionDefaultArbitraryTwoFlagsPresentNeg) {
- const char *Args[] = {"-fno-legacy-pass-manager"};
+TEST_F(CommandLineTest, BoolOptionDefaultArbitraryTwoFlagsPresentReset) {
+ const char *Args[] = {PassManagerResetByFlag};
CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
ASSERT_FALSE(Diags->hasErrorOccurred());
- ASSERT_FALSE(Invocation.getCodeGenOpts().LegacyPassManager);
+ ASSERT_EQ(Invocation.getCodeGenOpts().LegacyPassManager, PassManagerDefault);
Invocation.generateCC1CommandLine(GeneratedArgs, *this);
- ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-legacy-pass-manager")));
- ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-flegacy-pass-manager"))));
+ ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq(PassManagerChangedByFlag))));
+ ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq(PassManagerResetByFlag))));
}
TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) {
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92857.311193.patch
Type: text/x-patch
Size: 4378 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201211/6c25f054/attachment.bin>
More information about the cfe-commits
mailing list