aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Frontend/CompilerInvocationTest.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2020-12-18 13:55:48 +0100
committerJan Svoboda <jan_svoboda@apple.com>2020-12-21 11:32:47 +0100
commit70410a264949101ced3ce3458f37dd4cc2f5af85 (patch)
treea556384161d6a76f1244a6ef7294146ef713dd41 /clang/unittests/Frontend/CompilerInvocationTest.cpp
parent27b7d646886d499c70dec3481dfc3c82dfc43dd7 (diff)
downloadllvm-70410a264949101ced3ce3458f37dd4cc2f5af85.zip
llvm-70410a264949101ced3ce3458f37dd4cc2f5af85.tar.gz
llvm-70410a264949101ced3ce3458f37dd4cc2f5af85.tar.bz2
[clang][cli] Let denormalizer decide how to render the option based on the option class
Before this patch, you needed to use `AutoNormalizeEnumJoined` whenever you wanted to **de**normalize joined enum. Besides the naming confusion, this means the fact the option is joined is specified in two places: in the normalization multiclass and in the `Joined<["-"], ...>` multiclass. This patch makes this work automatically, taking into account the `OptionClass` of options. Also, the enum denormalizer now just looks up the spelling of the present enum case in a table and forwards it to the string denormalizer. I also added more tests that exercise this. Reviewed By: dexonsmith Original patch by Daniel Grumberg. Differential Revision: https://reviews.llvm.org/D84189
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
-rw-r--r--clang/unittests/Frontend/CompilerInvocationTest.cpp44
1 files changed, 42 insertions, 2 deletions
diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 51b7ba8..71e8d09 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -342,30 +342,70 @@ 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"))));
}
// Tree of boolean options that can be (directly or transitively) implied by