summaryrefslogtreecommitdiffstats
path: root/clang/unittests/Lex
diff options
context:
space:
mode:
Diffstat (limited to 'clang/unittests/Lex')
-rw-r--r--clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp44
1 files changed, 44 insertions, 0 deletions
diff --git a/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp b/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
index 5eb7d256a36..ed44cd86b3e 100644
--- a/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
+++ b/clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp
@@ -594,6 +594,50 @@ TEST(MinimizeSourceToDependencyDirectivesTest, PragmaOnce) {
EXPECT_STREQ("#pragma once\n#include <test.h>\n", Out.data());
}
+TEST(MinimizeSourceToDependencyDirectivesTest,
+ SkipLineStringCharLiteralsUntilNewline) {
+ SmallVector<char, 128> Out;
+
+ StringRef Source = R"(#if NEVER_ENABLED
+ #define why(fmt, ...) #error don't try me
+ #endif
+
+ void foo();
+)";
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+ EXPECT_STREQ(
+ "#if NEVER_ENABLED\n#define why(fmt,...) #error don't try me\n#endif\n",
+ Out.data());
+
+ Source = R"(#if NEVER_ENABLED
+ #define why(fmt, ...) "quote dropped
+ #endif
+
+ void foo();
+ )";
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+ EXPECT_STREQ(
+ "#if NEVER_ENABLED\n#define why(fmt,...) \"quote dropped\n#endif\n",
+ Out.data());
+}
+
+TEST(MinimizeSourceToDependencyDirectivesTest,
+ SupportWhitespaceBeforeLineContinuationInStringSkipping) {
+ SmallVector<char, 128> Out;
+
+ StringRef Source = "#define X '\\ \t\nx'\nvoid foo() {}";
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+ EXPECT_STREQ("#define X '\\ \t\nx'\n", Out.data());
+
+ Source = "#define X \"\\ \r\nx\"\nvoid foo() {}";
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+ EXPECT_STREQ("#define X \"\\ \r\nx\"\n", Out.data());
+
+ Source = "#define X \"\\ \r\nx\n#include <x>\n";
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+ EXPECT_STREQ("#define X \"\\ \r\nx\n#include <x>\n", Out.data());
+}
+
TEST(MinimizeSourceToDependencyDirectivesTest, CxxModules) {
SmallVector<char, 128> Out;
SmallVector<Token, 4> Tokens;
OpenPOWER on IntegriCloud