From 2154cffdc2a6fc9bc7fc75064dc875fa9bf18190 Mon Sep 17 00:00:00 2001 From: Jan Svoboda Date: Tue, 26 Jan 2021 08:52:31 +0100 Subject: [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 --- .../unittests/Frontend/CompilerInvocationTest.cpp | 45 ++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp') 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 -- cgit v1.1