diff options
author | Lubos Lunak <l.lunak@suse.cz> | 2013-11-27 21:14:43 +0000 |
---|---|---|
committer | Lubos Lunak <l.lunak@suse.cz> | 2013-11-27 21:14:43 +0000 |
commit | c6b9270d047e07718586aca4825fe958c1850345 (patch) | |
tree | cd5b82c6537ce6ca4c86f2bc031ff3f5345950c7 /clang | |
parent | 72e5b93b821fabc022aae20b0b5ae8b94cf4f4cc (diff) | |
download | bcm5719-llvm-c6b9270d047e07718586aca4825fe958c1850345.tar.gz bcm5719-llvm-c6b9270d047e07718586aca4825fe958c1850345.zip |
strip UTF-8 BOM in -frewrite-includes (PR#15664)
llvm-svn: 195877
Diffstat (limited to 'clang')
-rw-r--r-- | clang/lib/Rewrite/Frontend/InclusionRewriter.cpp | 5 | ||||
-rw-r--r-- | clang/test/Frontend/Inputs/rewrite-includes-bom.h | 1 | ||||
-rw-r--r-- | clang/test/Frontend/rewrite-includes-bom.c | 4 |
3 files changed, 10 insertions, 0 deletions
diff --git a/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp b/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp index bd4250adaad..71ceb5f0b6a 100644 --- a/clang/lib/Rewrite/Frontend/InclusionRewriter.cpp +++ b/clang/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/clang/test/Frontend/Inputs/rewrite-includes-bom.h b/clang/test/Frontend/Inputs/rewrite-includes-bom.h new file mode 100644 index 00000000000..7ba011fc2d7 --- /dev/null +++ b/clang/test/Frontend/Inputs/rewrite-includes-bom.h @@ -0,0 +1 @@ +// This file starts with UTF-8 BOM marker. diff --git a/clang/test/Frontend/rewrite-includes-bom.c b/clang/test/Frontend/rewrite-includes-bom.c new file mode 100644 index 00000000000..a1aa4c98f86 --- /dev/null +++ b/clang/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" |