]> granicus.if.org Git - clang/commitdiff
Merging r195877:
authorBill Wendling <isanbard@gmail.com>
Sun, 1 Dec 2013 02:07:35 +0000 (02:07 +0000)
committerBill Wendling <isanbard@gmail.com>
Sun, 1 Dec 2013 02:07:35 +0000 (02:07 +0000)
------------------------------------------------------------------------
r195877 | llunak | 2013-11-27 13:14:43 -0800 (Wed, 27 Nov 2013) | 3 lines

strip UTF-8 BOM in -frewrite-includes (PR#15664)

------------------------------------------------------------------------

git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_34@195987 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"