diff options
author | Bill Wendling <isanbard@gmail.com> | 2013-12-01 02:07:35 +0000 |
---|---|---|
committer | Bill Wendling <isanbard@gmail.com> | 2013-12-01 02:07:35 +0000 |
commit | f91fc4bfa3561990bbb39d3ed2045a75cbaa0df4 (patch) | |
tree | 8b977bb14505f7839474b93f2192d90b8f46b820 | |
parent | ed14aa73a59dbc122c34d3c3c4f67a1ccd7b8abc (diff) | |
download | clang-f91fc4bfa3561990bbb39d3ed2045a75cbaa0df4.tar.gz clang-f91fc4bfa3561990bbb39d3ed2045a75cbaa0df4.tar.bz2 clang-f91fc4bfa3561990bbb39d3ed2045a75cbaa0df4.tar.xz |
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
-rw-r--r-- | lib/Rewrite/Frontend/InclusionRewriter.cpp | 5 | ||||
-rw-r--r-- | test/Frontend/Inputs/rewrite-includes-bom.h | 1 | ||||
-rw-r--r-- | test/Frontend/rewrite-includes-bom.c | 4 |
3 files changed, 10 insertions, 0 deletions
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" |