diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2020-11-09 15:51:42 -0500 |
---|---|---|
committer | Duncan P. N. Exon Smith <dexonsmith@apple.com> | 2020-11-09 18:00:10 -0500 |
commit | dbfa69c5024cfe58b8029a3766ec46c857cddb1e (patch) | |
tree | 009d1cdffd1d5ca3b728ba3ba591bfe736ea008a /clang/unittests | |
parent | 09c6259d6d0eb51b282f6c3a28052a8146bc095b (diff) | |
download | llvm-project-dbfa69c5024cfe58b8029a3766ec46c857cddb1e.tar.gz |
Port some floating point options to new option marshalling infrastructure
This ports a number of OpenCL and fast-math flags for floating point
over to the new marshalling infrastructure.
As part of this, `Opt{In,Out}FFlag` were enhanced to allow other flags to
imply them, via `DefaultAnyOf<>`. For example:
```
defm signed_zeros : OptOutFFlag<"signed-zeros", ...,
"LangOpts->NoSignedZero",
DefaultAnyOf<[cl_no_signed_zeros, menable_unsafe_fp_math]>>;
```
defines `-fsigned-zeros` (`false`) and `-fno-signed-zeros` (`true`)
linked to the keypath `LangOpts->NoSignedZero`, defaulting to `false`,
but set to `true` implicitly if one of `-cl-no-signed-zeros` or
`-menable-unsafe-fp-math` is on.
Note that the initial patch was written Daniel Grumberg.
Differential Revision: https://reviews.llvm.org/D82756
Diffstat (limited to 'clang/unittests')
-rw-r--r-- | clang/unittests/Frontend/CompilerInvocationTest.cpp | 35 |
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 |