aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Frontend/CompilerInvocationTest.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
-rw-r--r--clang/unittests/Frontend/CompilerInvocationTest.cpp35
1 files changed, 35 insertions, 0 deletions
diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index ed82d678462f..d9b55f0ae5ba 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -37,6 +37,25 @@ public:
: Diags(CompilerInstance::createDiagnostics(new DiagnosticOptions())) {}
};
+TEST(OptsPopulationTest, CanPopulateOptsWithImpliedFlags) {
+ const char *Args[] = {"clang", "-xc++", "-cl-unsafe-math-optimizations"};
+
+ auto Diags = CompilerInstance::createDiagnostics(new DiagnosticOptions());
+
+ CompilerInvocation CInvok;
+ CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+
+ // Explicitly provided flag.
+ ASSERT_EQ(CInvok.getLangOpts()->CLUnsafeMath, true);
+
+ // Flags directly implied by explicitly provided flag.
+ ASSERT_EQ(CInvok.getCodeGenOpts().LessPreciseFPMAD, true);
+ ASSERT_EQ(CInvok.getLangOpts()->UnsafeFPMath, true);
+
+ // Flag transitively implied by explicitly provided flag.
+ ASSERT_EQ(CInvok.getLangOpts()->AllowRecip, true);
+}
+
TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineFlag) {
const char *Args[] = {"clang", "-xc++", "-fmodules-strict-context-hash", "-"};
@@ -115,4 +134,20 @@ TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineSeparateEnum) {
ASSERT_THAT(GeneratedArgs, Each(StrNe(RelocationModelCStr)));
}
+TEST_F(CC1CommandLineGenerationTest, CanGenerateCC1CommandLineImpliedFlags) {
+ const char *Args[] = {"clang", "-xc++", "-cl-unsafe-math-optimizations",
+ "-cl-mad-enable", "-menable-unsafe-fp-math"};
+
+ CompilerInvocation CInvok;
+ CompilerInvocation::CreateFromArgs(CInvok, Args, *Diags);
+
+ CInvok.generateCC1CommandLine(GeneratedArgs, *this);
+
+ // Explicitly provided flags that were also implied by another flag are not
+ // generated.
+ ASSERT_THAT(GeneratedArgs, 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"))));
+}
+
} // anonymous namespace