diff options
author | Alex Lorenz <arphaman@gmail.com> | 2019-10-08 22:42:44 +0000 |
---|---|---|
committer | Alex Lorenz <arphaman@gmail.com> | 2019-10-08 22:42:44 +0000 |
commit | b39c40c58951f18b5812ec839cdff5d9f41fe40e (patch) | |
tree | 7852db09e11421108dff354348756bbe06587638 /unittests | |
parent | b7e1c7cd95dcb7cc3ab6777f237326c47fae5165 (diff) | |
download | clang-b39c40c58951f18b5812ec839cdff5d9f41fe40e.tar.gz |
[clang-scan-deps] Improve string/character literal skipping
The existing string/character literal skipping code in the
dependency directives source minimizer has two issues:
- It doesn't stop the scanning when a newline is reached before the terminating character,
unlike the lexer which considers the token to be done (even if it's invalid) at the end of the line.
- It doesn't support whitespace between '\' and the newline when looking if the '\' is used as a line continuation character.
This commit fixes both issues.
Differential Revision: https://reviews.llvm.org/D68436
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@374127 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'unittests')
-rw-r--r-- | unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
diff --git a/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp b/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp index 5eb7d256a3..ed44cd86b3 100644 --- a/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp +++ b/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; |