From cc62d5d90ad591a3e8aeaa00a672702aa56f9584 Mon Sep 17 00:00:00 2001 From: Alp Toker Date: Thu, 28 Nov 2013 07:21:44 +0000 Subject: [PATCH] InclusionRewriter: Avoid duplicated BOM check The lexer already knows its position in the file, so use that instead of guessing it might be 3. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@195910 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Rewrite/Frontend/InclusionRewriter.cpp | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/lib/Rewrite/Frontend/InclusionRewriter.cpp b/lib/Rewrite/Frontend/InclusionRewriter.cpp index 71ceb5f0b6..176ea3f79d 100644 --- a/lib/Rewrite/Frontend/InclusionRewriter.cpp +++ b/lib/Rewrite/Frontend/InclusionRewriter.cpp @@ -363,15 +363,11 @@ bool InclusionRewriter::Process(FileID FileId, if (SM.getFileIDSize(FileId) == 0) return false; - // The next byte to be copied from the source file - unsigned NextToWrite = 0; + // The next byte to be copied from the source file, which may be non-zero if + // the lexer handled a BOM. + unsigned NextToWrite = SM.getFileOffset(RawLex.getSourceLocation()); 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); -- 2.40.0