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) {
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) {
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits