r195877 - strip UTF-8 BOM in -frewrite-includes (PR#15664)
Lubos Lunak
l.lunak at suse.cz
Wed Nov 27 13:14:43 PST 2013
Author: llunak
Date: Wed Nov 27 15:14:43 2013
New Revision: 195877
URL: http://llvm.org/viewvc/llvm-project?rev=195877&view=rev
Log:
strip UTF-8 BOM in -frewrite-includes (PR#15664)
Added:
cfe/trunk/test/Frontend/Inputs/rewrite-includes-bom.h
cfe/trunk/test/Frontend/rewrite-includes-bom.c
Modified:
cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
Modified: cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp?rev=195877&r1=195876&r2=195877&view=diff
==============================================================================
--- cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp (original)
+++ cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp Wed Nov 27 15:14:43 2013
@@ -367,6 +367,11 @@ bool InclusionRewriter::Process(FileID F
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);
Added: cfe/trunk/test/Frontend/Inputs/rewrite-includes-bom.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/Inputs/rewrite-includes-bom.h?rev=195877&view=auto
==============================================================================
--- cfe/trunk/test/Frontend/Inputs/rewrite-includes-bom.h (added)
+++ cfe/trunk/test/Frontend/Inputs/rewrite-includes-bom.h Wed Nov 27 15:14:43 2013
@@ -0,0 +1 @@
+// This file starts with UTF-8 BOM marker.
Added: cfe/trunk/test/Frontend/rewrite-includes-bom.c
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Frontend/rewrite-includes-bom.c?rev=195877&view=auto
==============================================================================
--- cfe/trunk/test/Frontend/rewrite-includes-bom.c (added)
+++ cfe/trunk/test/Frontend/rewrite-includes-bom.c Wed Nov 27 15:14:43 2013
@@ -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"
More information about the cfe-commits
mailing list