[PATCH] D66511: [clang-scan-deps] Skip UTF-8 BOM in source minimizer

Alexandre Ganea via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon Aug 26 17:14:01 PDT 2019


This revision was automatically updated to reflect the committed changes.
Closed by commit rL369993: [clang-scan-deps] Skip UTF-8 BOM in source minimizer (authored by aganea, committed by ).
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

Changed prior to commit:
  https://reviews.llvm.org/D66511?vs=216311&id=217275#toc

Repository:
  rL LLVM

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D66511/new/

https://reviews.llvm.org/D66511

Files:
  cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
  cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_utf8bom.c


Index: cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
===================================================================
--- cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
+++ cfe/trunk/lib/Lex/DependencyDirectivesSourceMinimizer.cpp
@@ -834,7 +834,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;
Index: cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_utf8bom.c
===================================================================
--- cfe/trunk/test/Lexer/minimize_source_to_dependency_directives_utf8bom.c
+++ cfe/trunk/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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D66511.217275.patch
Type: text/x-patch
Size: 1423 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20190827/771690da/attachment.bin>


More information about the llvm-commits mailing list