diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2020-12-08 12:15:35 +0100 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2020-12-09 08:58:45 +0100 |
commit | 216d43053b4e7327e5f9eb5705a7c8e4f6ae850b (patch) | |
tree | 65b22196b6872d3e527434763a038dab37b58940 /clang/unittests/Frontend/CompilerInvocationTest.cpp | |
parent | 03692bae1fc9b6232de7caea3b57ad2f3dc2a9d0 (diff) | |
download | llvm-216d43053b4e7327e5f9eb5705a7c8e4f6ae850b.zip llvm-216d43053b4e7327e5f9eb5705a7c8e4f6ae850b.tar.gz llvm-216d43053b4e7327e5f9eb5705a7c8e4f6ae850b.tar.bz2 |
[clang][cli] CompilerInvocationTest: join and add test cases
Depends on D92829.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D92830
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
-rw-r--r-- | clang/unittests/Frontend/CompilerInvocationTest.cpp | 121 |
1 files changed, 74 insertions, 47 deletions
diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 7712dd0..c3bdd6bf 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -38,42 +38,43 @@ public: } }; -TEST_F(CommandLineTest, OptIsInitializedWithCustomDefaultValue) { +// Boolean option with a keypath that defaults to true. +// The only flag with a negative spelling can set the keypath to false. + +TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagNotPresent) { const char *Args[] = {""}; CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); ASSERT_FALSE(Diags->hasErrorOccurred()); - ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-temp-file")))); } -TEST_F(CommandLineTest, OptOfNegativeFlagIsPopulatedWithFalse) { +TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagPresent) { const char *Args[] = {"-fno-temp-file"}; CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); ASSERT_FALSE(Diags->hasErrorOccurred()); - ASSERT_FALSE(Invocation.getFrontendOpts().UseTemporary); -} -TEST_F(CommandLineTest, OptsOfImpliedPositiveFlagArePopulatedWithTrue) { - const char *Args[] = {"-cl-unsafe-math-optimizations"}; - - CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + Invocation.generateCC1CommandLine(GeneratedArgs, *this); - ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-temp-file"))); +} - // Explicitly provided flag. - ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath); +TEST_F(CommandLineTest, BoolOptionDefaultTrueSingleFlagUnknownPresent) { + const char *Args[] = {"-ftemp-file"}; - // Flags directly implied by explicitly provided flag. - ASSERT_TRUE(Invocation.getCodeGenOpts().LessPreciseFPMAD); - ASSERT_TRUE(Invocation.getLangOpts()->UnsafeFPMath); + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); - // Flag transitively implied by explicitly provided flag. - ASSERT_TRUE(Invocation.getLangOpts()->AllowRecip); + // Driver-only flag. + ASSERT_TRUE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getFrontendOpts().UseTemporary); } TEST_F(CommandLineTest, CanGenerateCC1CommandLineFlag) { @@ -157,75 +158,101 @@ TEST_F(CommandLineTest, CanGenerateCC1COmmandLineSeparateEnumDefault) { ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("pic")))); } -TEST_F(CommandLineTest, NotPresentNegativeFlagNotGenerated) { - const char *Args[] = {""}; - - CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); - - ASSERT_FALSE(Diags->hasErrorOccurred()); - - Invocation.generateCC1CommandLine(GeneratedArgs, *this); - - ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-temp-file")))); -} - -TEST_F(CommandLineTest, PresentNegativeFlagGenerated) { - const char *Args[] = {"-fno-temp-file"}; - - CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); - - ASSERT_FALSE(Diags->hasErrorOccurred()); - - Invocation.generateCC1CommandLine(GeneratedArgs, *this); - - ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-temp-file"))); -} +// Tree of boolean options that can be (directly or transitively) implied by +// their parent: +// +// * -cl-unsafe-math-optimizations +// * -cl-mad-enable +// * -menable-unsafe-fp-math +// * -freciprocal-math -TEST_F(CommandLineTest, NotPresentAndNotImpliedNotGenerated) { +TEST_F(CommandLineTest, ImpliedBoolOptionsNoFlagPresent) { const char *Args[] = {""}; CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_FALSE(Invocation.getLangOpts()->CLUnsafeMath); + ASSERT_FALSE(Invocation.getCodeGenOpts().LessPreciseFPMAD); + ASSERT_FALSE(Invocation.getLangOpts()->UnsafeFPMath); + ASSERT_FALSE(Invocation.getLangOpts()->AllowRecip); Invocation.generateCC1CommandLine(GeneratedArgs, *this); - // Missing options are not generated. + // Not generated - missing. ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-unsafe-math-optimizations")))); ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable")))); ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-menable-unsafe-fp-math")))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math")))); } -TEST_F(CommandLineTest, NotPresentAndImpliedNotGenerated) { +TEST_F(CommandLineTest, ImpliedBoolOptionsRootFlagPresent) { const char *Args[] = {"-cl-unsafe-math-optimizations"}; CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); ASSERT_FALSE(Diags->hasErrorOccurred()); + // Explicitly provided root flag. + ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath); + // Directly implied by explicitly provided root flag. + ASSERT_TRUE(Invocation.getCodeGenOpts().LessPreciseFPMAD); + ASSERT_TRUE(Invocation.getLangOpts()->UnsafeFPMath); + // Transitively implied by explicitly provided root flag. + ASSERT_TRUE(Invocation.getLangOpts()->AllowRecip); Invocation.generateCC1CommandLine(GeneratedArgs, *this); - // Missing options that were implied are not generated. + // Generated - explicitly provided. ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-unsafe-math-optimizations"))); + // Not generated - implied by the generated root flag. ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable")))); ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-menable-unsafe-fp-math")))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math")))); } -TEST_F(CommandLineTest, PresentAndImpliedNotGenerated) { +TEST_F(CommandLineTest, ImpliedBoolOptionsAllFlagsPresent) { const char *Args[] = {"-cl-unsafe-math-optimizations", "-cl-mad-enable", - "-menable-unsafe-fp-math"}; + "-menable-unsafe-fp-math", "-freciprocal-math"}; CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getLangOpts()->CLUnsafeMath); + ASSERT_TRUE(Invocation.getCodeGenOpts().LessPreciseFPMAD); + ASSERT_TRUE(Invocation.getLangOpts()->UnsafeFPMath); + ASSERT_TRUE(Invocation.getLangOpts()->AllowRecip); Invocation.generateCC1CommandLine(GeneratedArgs, *this); - // Present options that were also implied are not generated. + // Generated - explicitly provided. ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-unsafe-math-optimizations"))); + // Not generated - implied by their generated parent. ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-cl-mad-enable")))); ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-menable-unsafe-fp-math")))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math")))); +} + +TEST_F(CommandLineTest, ImpliedBoolOptionsImpliedFlagsPresent) { + const char *Args[] = {"-cl-mad-enable", "-menable-unsafe-fp-math", + "-freciprocal-math"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_FALSE(Invocation.getLangOpts()->CLUnsafeMath); + ASSERT_TRUE(Invocation.getCodeGenOpts().LessPreciseFPMAD); + ASSERT_TRUE(Invocation.getLangOpts()->UnsafeFPMath); + ASSERT_TRUE(Invocation.getLangOpts()->AllowRecip); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + // Not generated - missing. + ASSERT_THAT(GeneratedArgs, + Not(Contains(StrEq("-cl-unsafe-math-optimizations")))); + // Generated - explicitly provided. + ASSERT_THAT(GeneratedArgs, Contains(StrEq("-cl-mad-enable"))); + ASSERT_THAT(GeneratedArgs, Contains(StrEq("-menable-unsafe-fp-math"))); + // Not generated - implied by its generated parent. + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-freciprocal-math")))); } TEST_F(CommandLineTest, PresentAndNotImpliedGenerated) { |