aboutsummaryrefslogtreecommitdiff
path: root/clang/unittests/Frontend/CompilerInvocationTest.cpp
diff options
context:
space:
mode:
authorJan Svoboda <jan_svoboda@apple.com>2020-12-18 15:02:43 +0100
committerJan Svoboda <jan_svoboda@apple.com>2021-01-07 10:01:49 +0100
commit77db83ae997767400ffcbe0101f8ee867ebaa111 (patch)
treee1f1ab10a95c1970de797f3f36077b721693cf03 /clang/unittests/Frontend/CompilerInvocationTest.cpp
parent5471b1fa4013f463ad40abd61fa7f04500aaf7fd (diff)
downloadllvm-77db83ae997767400ffcbe0101f8ee867ebaa111.zip
llvm-77db83ae997767400ffcbe0101f8ee867ebaa111.tar.gz
llvm-77db83ae997767400ffcbe0101f8ee867ebaa111.tar.bz2
[clang][cli] Allow users to specify a conditional to prevent parsing options with MarshallingInfo
Depends on D84189 & D93540. Reviewed By: Bigcheese Differential Revision: https://reviews.llvm.org/D84674
Diffstat (limited to 'clang/unittests/Frontend/CompilerInvocationTest.cpp')
-rw-r--r--clang/unittests/Frontend/CompilerInvocationTest.cpp62
1 files changed, 62 insertions, 0 deletions
diff --git a/clang/unittests/Frontend/CompilerInvocationTest.cpp b/clang/unittests/Frontend/CompilerInvocationTest.cpp
index 8960e26..89d9c88 100644
--- a/clang/unittests/Frontend/CompilerInvocationTest.cpp
+++ b/clang/unittests/Frontend/CompilerInvocationTest.cpp
@@ -448,6 +448,68 @@ TEST_F(CommandLineTest, StringVectorMultiple) {
ASSERT_EQ(count(GeneratedArgs, StringRef("-fmodule-map-file=b")), 1);
}
+// A flag that should be parsed only if a condition is met.
+
+TEST_F(CommandLineTest, ConditionalParsingIfFalseFlagNotPresent) {
+ const char *Args[] = {""};
+
+ CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+
+ ASSERT_FALSE(Diags->hasErrorOccurred());
+ ASSERT_FALSE(Invocation.getLangOpts()->SYCL);
+ ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
+
+ Invocation.generateCC1CommandLine(GeneratedArgs, *this);
+
+ ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl"))));
+ ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
+}
+
+TEST_F(CommandLineTest, ConditionalParsingIfFalseFlagPresent) {
+ const char *Args[] = {"-sycl-std=2017"};
+
+ CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+
+ ASSERT_FALSE(Diags->hasErrorOccurred());
+ ASSERT_FALSE(Invocation.getLangOpts()->SYCL);
+ ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
+
+ Invocation.generateCC1CommandLine(GeneratedArgs, *this);
+
+ ASSERT_THAT(GeneratedArgs, Not(Contains(StrEq("-fsycl"))));
+ ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
+}
+
+TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagNotPresent) {
+ const char *Args[] = {"-fsycl"};
+
+ CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+
+ ASSERT_FALSE(Diags->hasErrorOccurred());
+ ASSERT_TRUE(Invocation.getLangOpts()->SYCL);
+ ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_None);
+
+ Invocation.generateCC1CommandLine(GeneratedArgs, *this);
+
+ ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl")));
+ ASSERT_THAT(GeneratedArgs, Not(Contains(HasSubstr("-sycl-std="))));
+}
+
+TEST_F(CommandLineTest, ConditionalParsingIfTrueFlagPresent) {
+ const char *Args[] = {"-fsycl", "-sycl-std=2017"};
+
+ CompilerInvocation::CreateFromArgs(Invocation, Args, *Diags);
+
+ ASSERT_FALSE(Diags->hasErrorOccurred());
+ ASSERT_TRUE(Invocation.getLangOpts()->SYCL);
+ ASSERT_EQ(Invocation.getLangOpts()->getSYCLVersion(), LangOptions::SYCL_2017);
+
+ Invocation.generateCC1CommandLine(GeneratedArgs, *this);
+
+ ASSERT_THAT(GeneratedArgs, Contains(StrEq("-fsycl")));
+ ASSERT_THAT(GeneratedArgs, Contains(StrEq("-sycl-std=2017")));
+}
+
// Wide integer option.
TEST_F(CommandLineTest, WideIntegerHighValue) {