From: Bill Wendling Date: Sun, 1 Dec 2013 02:07:35 +0000 (+0000) Subject: Merging r195877: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f91fc4bfa3561990bbb39d3ed2045a75cbaa0df4;p=clang Merging r195877: ------------------------------------------------------------------------ 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 --- diff --git a/lib/Rewrite/Frontend/InclusionRewriter.cpp b/lib/Rewrite/Frontend/InclusionRewriter.cpp index bd4250adaa..71ceb5f0b6 100644 --- a/lib/Rewrite/Frontend/InclusionRewriter.cpp +++ b/lib/Rewrite/Frontend/InclusionRewriter.cpp @@ -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 index 0000000000..7ba011fc2d --- /dev/null +++ b/test/Frontend/Inputs/rewrite-includes-bom.h @@ -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 index 0000000000..a1aa4c98f8 --- /dev/null +++ b/test/Frontend/rewrite-includes-bom.c @@ -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"