[PATCH] D66511: [clang-scan-deps] Skip UTF-8 BOM in source minimizer
Alexandre Ganea via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Aug 20 18:42:49 PDT 2019
aganea created this revision.
aganea added reviewers: arphaman, dexonsmith, Bigcheese.
aganea added a project: clang.
Herald added a subscriber: tschuett.
As per title.
Repository:
rC Clang
https://reviews.llvm.org/D66511
Files:
lib/Lex/DependencyDirectivesSourceMinimizer.cpp
test/Lexer/minimize_source_to_dependency_directives_utf8bom.c
Index: test/Lexer/minimize_source_to_dependency_directives_utf8bom.c
===================================================================
--- test/Lexer/minimize_source_to_dependency_directives_utf8bom.c
+++ test/Lexer/minimize_source_to_dependency_directives_utf8bom.c
@@ -0,0 +1,10 @@
+// Test UTF8 BOM at start of file
+// RUN: printf '\xef\xbb\xbf' > %t.c
+// RUN: echo '#ifdef TEST\n' >> %t.c
+// RUN: echo '#include <string>' >> %t.c
+// RUN: echo '#endif' >> %t.c
+// RUN: %clang_cc1 -DTEST -print-dependency-directives-minimized-source %t.c 2>&1 | FileCheck %s
+
+// CHECK: #ifdef TEST
+// CHECK-NEXT: #include <string>
+// CHECK-NEXT: #endif
Index: lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===================================================================
--- lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -812,7 +812,14 @@
return lexDefault(Kind, Id.Name, First, End);
}
+static void skipUTF8ByteOrderMark(const char *&First, const char *const End) {
+ if ((End - First) >= 3 && First[0] == '\xef' && First[1] == '\xbb' &&
+ First[2] == '\xbf')
+ First += 3;
+}
+
bool Minimizer::minimizeImpl(const char *First, const char *const End) {
+ skipUTF8ByteOrderMark(First, End);
while (First != End)
if (lexPPLine(First, End))
return true;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66511.216311.patch
Type: text/x-patch
Size: 1363 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20190821/fd57aaf7/attachment.bin>
More information about the cfe-commits
mailing list