]> granicus.if.org Git - clang/commitdiff
InclusionRewriter: Avoid duplicated BOM check
authorAlp Toker <alp@nuanti.com>
Thu, 28 Nov 2013 07:21:44 +0000 (07:21 +0000)
committerAlp Toker <alp@nuanti.com>
Thu, 28 Nov 2013 07:21:44 +0000 (07:21 +0000)
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

index 71ceb5f0b6aa6917ee12b29076bf86fc001f4f77..176ea3f79dc13ad9d8a6e01b8f22cda5bb692f60 100644 (file)
@@ -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);