]> granicus.if.org Git - clang/commitdiff
strip UTF-8 BOM in -frewrite-includes (PR#15664)
authorLubos Lunak <l.lunak@suse.cz>
Wed, 27 Nov 2013 21:14:43 +0000 (21:14 +0000)
committerLubos Lunak <l.lunak@suse.cz>
Wed, 27 Nov 2013 21:14:43 +0000 (21:14 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195877 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Rewrite/Frontend/InclusionRewriter.cpp
test/Frontend/Inputs/rewrite-includes-bom.h [new file with mode: 0644]
test/Frontend/rewrite-includes-bom.c [new file with mode: 0644]

index bd4250adaadc5bf080231dc50356ceb73bb97123..71ceb5f0b6aa6917ee12b29076bf86fc001f4f77 100644 (file)
@@ -367,6 +367,11 @@ bool InclusionRewriter::Process(FileID FileId,
   unsigned NextToWrite = 0;
   int Line = 1; // The current input file line number.
 
+  // Ignore UTF-8 BOM, otherwise it'd end up somewhere else than the start
+  // of the resulting file.
+  if (FromFile.getBuffer().startswith("\xEF\xBB\xBF"))
+    NextToWrite = 3;
+
   Token RawToken;
   RawLex.LexFromRawLexer(RawToken);
 
diff --git a/test/Frontend/Inputs/rewrite-includes-bom.h b/test/Frontend/Inputs/rewrite-includes-bom.h
new file mode 100644 (file)
index 0000000..7ba011f
--- /dev/null
@@ -0,0 +1 @@
+// This file starts with UTF-8 BOM marker.
diff --git a/test/Frontend/rewrite-includes-bom.c b/test/Frontend/rewrite-includes-bom.c
new file mode 100644 (file)
index 0000000..a1aa4c9
--- /dev/null
@@ -0,0 +1,4 @@
+// RUN: %clang -E -frewrite-includes -I %S/Inputs %s -o - | %clang -fsyntax-only -Xclang -verify -x c -
+// expected-no-diagnostics
+
+#include "rewrite-includes-bom.h"