arphaman created this revision. arphaman added a reviewer: Bigcheese. Herald added subscribers: tschuett, dexonsmith, jkorous. Herald added a project: clang.
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`. Repository: rC Clang https://reviews.llvm.org/D64525 Files: clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp Index: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp =================================================================== --- clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp +++ clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp @@ -507,4 +507,41 @@ EXPECT_STREQ("#include <bob>\n#include <foo>\n", Out.data()); } +TEST(MinimizeSourceToDependencyDirectivesTest, CharacterLiteralPrefixL) { + SmallVector<char, 128> Out; + + StringRef Source = R"(L'P' +#if DEBUG +// ' +#endif +#include <test.h> +)"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#include <test.h>\n", Out.data()); +} + +TEST(MinimizeSourceToDependencyDirectivesTest, CharacterLiteralPrefixU) { + SmallVector<char, 128> Out; + + StringRef Source = R"(int x = U'P'; +#include <test.h> +// ' +)"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#include <test.h>\n", Out.data()); +} + +TEST(MinimizeSourceToDependencyDirectivesTest, CharacterLiteralPrefixu) { + SmallVector<char, 128> Out; + + StringRef Source = R"(int x = u'b'; +int y = u8'a'; +int z = 128'78; +#include <test.h> +// ' +)"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#include <test.h>\n", Out.data()); +} + } // end anonymous namespace Index: clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp =================================================================== --- clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp +++ clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp @@ -262,7 +262,14 @@ 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));
Index: clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp =================================================================== --- clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp +++ clang/unittests/Lex/DependencyDirectivesSourceMinimizerTest.cpp @@ -507,4 +507,41 @@ EXPECT_STREQ("#include <bob>\n#include <foo>\n", Out.data()); } +TEST(MinimizeSourceToDependencyDirectivesTest, CharacterLiteralPrefixL) { + SmallVector<char, 128> Out; + + StringRef Source = R"(L'P' +#if DEBUG +// ' +#endif +#include <test.h> +)"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#include <test.h>\n", Out.data()); +} + +TEST(MinimizeSourceToDependencyDirectivesTest, CharacterLiteralPrefixU) { + SmallVector<char, 128> Out; + + StringRef Source = R"(int x = U'P'; +#include <test.h> +// ' +)"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#include <test.h>\n", Out.data()); +} + +TEST(MinimizeSourceToDependencyDirectivesTest, CharacterLiteralPrefixu) { + SmallVector<char, 128> Out; + + StringRef Source = R"(int x = u'b'; +int y = u8'a'; +int z = 128'78; +#include <test.h> +// ' +)"; + ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out)); + EXPECT_STREQ("#include <test.h>\n", Out.data()); +} + } // end anonymous namespace Index: clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp =================================================================== --- clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp +++ clang/lib/Lex/DependencyDirectivesSourceMinimizer.cpp @@ -262,7 +262,14 @@ 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));
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits