From acd38fa683686672cfbed237c242009d30f696d4 Mon Sep 17 00:00:00 2001 From: Alex Lorenz Date: Wed, 10 Jul 2019 22:00:59 +0000 Subject: [PATCH] [clang-scan-deps] Dependency directives source minimizer: single quotes are not digit separators after a valid character literal prefix The single quote character can act as a c++ digit separator. However, the minimizer shouldn't treat it as such when it's actually following a valid character literal prefix, like L, U, u, or u8. Differential Revision: https://reviews.llvm.org/D64525 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@365700 91177308-0d34-0410-b5e6-96231b3b80d8 --- .../DependencyDirectivesSourceMinimizer.cpp | 9 ++++- ...ependencyDirectivesSourceMinimizerTest.cpp | 37 +++++++++++++++++++ 2 files changed, 45 insertions(+), 1 deletion(-) diff --git a/lib/Lex/DependencyDirectivesSourceMinimizer.cpp b/lib/Lex/DependencyDirectivesSourceMinimizer.cpp index 6d7dfd1145..cfc37c5d3c 100644 --- a/lib/Lex/DependencyDirectivesSourceMinimizer.cpp +++ b/lib/Lex/DependencyDirectivesSourceMinimizer.cpp @@ -262,7 +262,14 @@ static bool isQuoteCppDigitSeparator(const char *const Start, if (Start == Cur) return false; // The previous character must be a valid PP number character. - if (!isPreprocessingNumberBody(*(Cur - 1))) + // Make sure that the L, u, U, u8 prefixes don't get marked as a + // separator though. + char Prev = *(Cur - 1); + if (Prev == 'L' || Prev == 'U' || Prev == 'u') + return false; + if (Prev == '8' && (Cur - 1 != Start) && *(Cur - 2) == 'u') + return false; + if (!isPreprocessingNumberBody(Prev)) return false; // The next character should be a valid identifier body character. return (Cur + 1) < End && isIdentifierBody(*(Cur + 1)); diff --git a/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp b/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp index d13723bdd1..cfa3ec91e0 100644 --- a/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp +++ b/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp @@ -507,4 +507,41 @@ int c = 12 ' '; EXPECT_STREQ("#include \n#include \n", Out.data()); } +TEST(MinimizeSourceToDependencyDirectivesTest, CharacterLiteralPrefixL) { + SmallVector Out; + + StringRef Source = R"(L'P' +#if DEBUG +// ' +#endif +#include +)"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#include \n", Out.data()); +} + +TEST(MinimizeSourceToDependencyDirectivesTest, CharacterLiteralPrefixU) { + SmallVector Out; + + StringRef Source = R"(int x = U'P'; +#include +// ' +)"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#include \n", Out.data()); +} + +TEST(MinimizeSourceToDependencyDirectivesTest, CharacterLiteralPrefixu) { + SmallVector Out; + + StringRef Source = R"(int x = u'b'; +int y = u8'a'; +int z = 128'78; +#include +// ' +)"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#include \n", Out.data()); +} + } // end anonymous namespace -- 2.40.0