diff options
author | Jan Svoboda <jan_svoboda@apple.com> | 2021-01-05 17:00:46 +0100 |
---|---|---|
committer | Jan Svoboda <jan_svoboda@apple.com> | 2021-01-06 13:27:19 +0100 |
commit | ce8c59e6af487f0b8786ae921aa926341f0ae04f (patch) | |
tree | d1f5b90025cd7b4ddc51b76486998bf83ee2eba8 /clang/unittests/Frontend/CompilerInvocationTest.cpp | |
parent | 643e3c90761f30194a76671065d221d3cb71a199 (diff) | |
download | llvm-ce8c59e6af487f0b8786ae921aa926341f0ae04f.zip llvm-ce8c59e6af487f0b8786ae921aa926341f0ae04f.tar.gz llvm-ce8c59e6af487f0b8786ae921aa926341f0ae04f.tar.bz2 |
Reapply multiple "[clang][cli]" patches
This reverts 7ad666798f12 and 1876a2914fe0 that reverted:
741978d727a4 [clang][cli] Port CodeGen option flags to new option parsing system
383778e2171b [clang][cli] Port LangOpts option flags to new option parsing system
aec2991d083a [clang][cli] Port LangOpts simple string based options to new option parsing system
95d3cc67caac [clang][cli] Port CodeGenOpts simple string flags to new option parsing system
27b7d646886d [clang][cli] Streamline MarshallingInfoFlag description
70410a264949 [clang][cli] Let denormalizer decide how to render the option based on the option class
63a24816f561 [clang][cli] Implement `getAllArgValues` marshalling
Commit 741978d727a4 accidentally changed the `Group` attribute of `g[no_]column_info` options from `g_flags_Group` to `g_Group`, which changed the debug info options passed to cc1 by the driver.
Similar change was also present in 383778e2171b, which accidentally added `Group<f_Group>` to `f[no_]const_strings` and `f[no_]signed_wchar`.
This patch corrects all three accidental changes by replacing `Bool{G,F}Option` with `BoolCC1Option`.
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
-rw-r--r-- | clang/unittests/Frontend/CompilerInvocationTest.cpp | 84 |
1 files changed, 82 insertions, 2 deletions
diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp index 83ae169..8960e26 100644 --- a/clang/unittests/Frontend/CompilerInvocationTest.cpp +++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp @@ -18,6 +18,7 @@ using namespace llvm; using namespace clang; using ::testing::Contains; +using ::testing::HasSubstr; using ::testing::StrEq; namespace { @@ -342,30 +343,109 @@ TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateRequiredAbsent) { ASSERT_THAT(GeneratedArgs, Contains(StrEq(DefaultTriple.c_str()))); } -TEST_F(CommandLineTest, CanGenerateCC1CommandLineSeparateEnumNonDefault) { +TEST_F(CommandLineTest, SeparateEnumNonDefault) { const char *Args[] = {"-mrelocation-model", "static"}; CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_EQ(Invocation.getCodeGenOpts().RelocationModel, Reloc::Model::Static); Invocation.generateCC1CommandLine(GeneratedArgs, *this); // Non default relocation model. + ASSERT_THAT(GeneratedArgs, Contains(StrEq("-mrelocation-model"))); ASSERT_THAT(GeneratedArgs, Contains(StrEq("static"))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model=static")))); } -TEST_F(CommandLineTest, CanGenerateCC1COmmandLineSeparateEnumDefault) { +TEST_F(CommandLineTest, SeparateEnumDefault) { const char *Args[] = {"-mrelocation-model", "pic"}; CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_EQ(Invocation.getCodeGenOpts().RelocationModel, Reloc::Model::PIC_); Invocation.generateCC1CommandLine(GeneratedArgs, *this); // Default relocation model. + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model")))); ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("pic")))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-mrelocation-model=pic")))); +} + +TEST_F(CommandLineTest, JoinedEnumNonDefault) { + const char *Args[] = {"-fobjc-dispatch-method=non-legacy"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_EQ(Invocation.getCodeGenOpts().getObjCDispatchMethod(), + CodeGenOptions::NonLegacy); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + + ASSERT_THAT(GeneratedArgs, + Contains(StrEq("-fobjc-dispatch-method=non-legacy"))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fobjc-dispatch-method=")))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("non-legacy")))); +} + +TEST_F(CommandLineTest, JoinedEnumDefault) { + const char *Args[] = {"-fobjc-dispatch-method=legacy"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_EQ(Invocation.getCodeGenOpts().getObjCDispatchMethod(), + CodeGenOptions::Legacy); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + + ASSERT_THAT(GeneratedArgs, + Not(Contains(StrEq("-fobjc-dispatch-method=legacy")))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fobjc-dispatch-method=")))); + ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("legacy")))); +} + +TEST_F(CommandLineTest, StringVectorEmpty) { + const char *Args[] = {""}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getFrontendOpts().ModuleMapFiles.empty()); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-fmodule-map-file=")))); +} + +TEST_F(CommandLineTest, StringVectorSingle) { + const char *Args[] = {"-fmodule-map-file=a"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_EQ(Invocation.getFrontendOpts().ModuleMapFiles, + std::vector<std::string>({"a"})); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=a")), 1); +} + +TEST_F(CommandLineTest, StringVectorMultiple) { + const char *Args[] = {"-fmodule-map-file=a", "-fmodule-map-file=b"}; + + CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags); + + ASSERT_FALSE(Diags->hasErrorOccurred()); + ASSERT_TRUE(Invocation.getFrontendOpts().ModuleMapFiles == + std::vector<std::string>({"a", "b"})); + + Invocation.generateCC1CommandLine(GeneratedArgs, *this); + ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=a")), 1); + ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=b")), 1); } // Wide integer option. |