diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2021-01-26 08:52:31 +0100 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2021-01-26 09:05:43 +0100 |
commit | 2154cffdc2a6fc9bc7fc75064dc875fa9bf18190 (patch) | |
tree | 15714a0e22d6dfd8cffdfdedce23380a2391f554 /clang/unittests/Frontend/CompilerInvocationTest.cpp | |
parent | e72b22a40b09f533cbcf2517800692ce0fddff7e (diff) | |
download | llvm-2154cffdc2a6fc9bc7fc75064dc875fa9bf18190.zip llvm-2154cffdc2a6fc9bc7fc75064dc875fa9bf18190.tar.gz llvm-2154cffdc2a6fc9bc7fc75064dc875fa9bf18190.tar.bz2 |
[clang][cli] Store LangStandard::Kind in LangOptions
The `LangStandard::Kind` parsed from command line arguments is used to set up some `LangOption` defaults, but isn't stored anywhere.
To be able to generate `-std=` (in future patch), we need `CompilerInvocation` to not forget it.
This patch demonstrates another use-case: using `LangStd` to set up defaults of marshalled options.
Reviewed By: dexonsmith
Differential Revision: https://reviews.llvm.org/D95342
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
-rw-r--r-- | clang/unittests/Frontend/CompilerInvocationTest.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 8efba9c..268f0d0 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -695,4 +695,49 @@ TEST_F(CommandLineTest, DiagnosticOptionPresent) { ASSERT_THAT(GeneratedArgs, ContainsN(StrEq("-verify=xyz"), 1)); } + +// Option default depends on language standard. + +TEST_F(CommandLineTest, DigraphsImplied) { + const char *Args[] = {""}; + + ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags)); + ASSERT_TRUE(Invocation.getLangOpts()->Digraphs); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-digraphs")))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fdigraphs")))); +} + +TEST_F(CommandLineTest, DigraphsDisabled) { + const char *Args[] = {"-fno-digraphs"}; + + ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags)); + ASSERT_FALSE(Invocation.getLangOpts()->Digraphs); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fno-digraphs"))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fdigraphs")))); +} + +TEST_F(CommandLineTest, DigraphsNotImplied) { + const char *Args[] = {"-std=c89"}; + + ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags)); + ASSERT_FALSE(Invocation.getLangOpts()->Digraphs); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fno-digraphs")))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fdigraphs")))); +} + +TEST_F(CommandLineTest, DigraphsEnabled) { + const char *Args[] = {"-std=c89", "-fdigraphs"}; + + ASSERT_TRUE(CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags)); + ASSERT_TRUE(Invocation.getLangOpts()->Digraphs); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fdigraphs"))); +} } // anonymous namespace |