r195910 - InclusionRewriter: Avoid duplicated BOM check

Lubos Lunak l.lunak at centrum.cz
Tue Dec 3 12:01:47 PST 2013


On Tuesday 03 of December 2013, Reid Kleckner wrote:
> This seems like it has the side effect of trimming leading whitespace from
> the rewritten file, but that's probably fine.

 It's not. The main file does not start with any line markers, so it is 
possible that lines in warnings/errors will be wrong. Please fix this or 
revert the change to the previous one that works.

> On Wed, Nov 27, 2013 at 11:21 PM, Alp Toker <alp at nuanti.com> wrote:
> > Author: alp
> > Date: Thu Nov 28 01:21:44 2013
> > New Revision: 195910
> >
> > URL: http://llvm.org/viewvc/llvm-project?rev=195910&view=rev
> > Log:
> > InclusionRewriter: Avoid duplicated BOM check
> >
> > The lexer already knows its position in the file, so use that instead of
> > guessing it might be 3.
> >
> > Modified:
> >     cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
> >
> > Modified: cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp
> > URL:
> > http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Rewrite/Frontend/Inclus
> >ionRewriter.cpp?rev=195910&r1=195909&r2=195910&view=diff
> >
> > =========================================================================
> >===== --- cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp (original)
> > +++ cfe/trunk/lib/Rewrite/Frontend/InclusionRewriter.cpp Thu Nov 28
> > 01:21:44 2013
> > @@ -363,15 +363,11 @@ bool InclusionRewriter::Process(FileID F
> >    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);

-- 
 Lubos Lunak



More information about the cfe-commits mailing list