[PATCH] D133674: [Lex/DependencyDirectivesScanner] Handle the case where the source line starts with a `tok::hashhash`
Argyrios Kyrtzidis via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Sun Sep 11 10:20:28 PDT 2022
akyrtzi created this revision.
Herald added a project: All.
akyrtzi requested review of this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D133674
Files:
clang/lib/Lex/DependencyDirectivesScanner.cpp
clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
Index: clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
===================================================================
--- clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
+++ clang/unittests/Lex/DependencyDirectivesScannerTest.cpp
@@ -124,6 +124,21 @@
EXPECT_STREQ("#define MACRO a\n", Out.data());
}
+TEST(MinimizeSourceToDependencyDirectivesTest, HashHash) {
+ SmallVector<char, 128> Out;
+
+ StringRef Source = R"(
+ #define S
+ #if 0
+ ##pragma cool
+ ##include "t.h"
+ #endif
+ #define E
+ )";
+ ASSERT_FALSE(minimizeSourceToDependencyDirectives(Source, Out));
+ EXPECT_STREQ("#define S\n#if 0\n#endif\n#define E\n", Out.data());
+}
+
TEST(MinimizeSourceToDependencyDirectivesTest, Define) {
SmallVector<char, 128> Out;
SmallVector<dependency_directives_scan::Token, 4> Tokens;
Index: clang/lib/Lex/DependencyDirectivesScanner.cpp
===================================================================
--- clang/lib/Lex/DependencyDirectivesScanner.cpp
+++ clang/lib/Lex/DependencyDirectivesScanner.cpp
@@ -742,6 +742,11 @@
// Lex '#'.
const dependency_directives_scan::Token &HashTok = lexToken(First, End);
+ if (HashTok.is(tok::hashhash)) {
+ skipLine(First, End);
+ assert(First <= End);
+ return false;
+ }
assert(HashTok.is(tok::hash));
(void)HashTok;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D133674.459381.patch
Type: text/x-patch
Size: 1348 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220911/6e498839/attachment.bin>
More information about the cfe-commits
mailing list