]> granicus.if.org Git - clang/commitdiff
Take into account that there may be a BOM at the beginning of the file,
authorArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 25 Oct 2012 01:51:45 +0000 (01:51 +0000)
committerArgyrios Kyrtzidis <akyrtzi@gmail.com>
Thu, 25 Oct 2012 01:51:45 +0000 (01:51 +0000)
when computing the size of the precompiled preamble.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@166659 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Lex/Lexer.cpp
test/Index/preamble-reparse-with-BOM.m [new file with mode: 0644]

index 6ac3f3fafc8975ee23301ef2662a957ad45fb7a9..fa911feed26bd67455116d4c06e80e678bd37c75 100644 (file)
@@ -513,10 +513,13 @@ Lexer::ComputePreamble(const llvm::MemoryBuffer *Buffer,
   // "fake" file source location at offset 1 so that the lexer will track our
   // position within the file.
   const unsigned StartOffset = 1;
-  SourceLocation StartLoc = SourceLocation::getFromRawEncoding(StartOffset);
-  Lexer TheLexer(StartLoc, LangOpts, Buffer->getBufferStart(),
+  SourceLocation FileLoc = SourceLocation::getFromRawEncoding(StartOffset);
+  Lexer TheLexer(FileLoc, LangOpts, Buffer->getBufferStart(),
                  Buffer->getBufferStart(), Buffer->getBufferEnd());
-  
+
+  // StartLoc will differ from FileLoc if there is a BOM that was skipped.
+  SourceLocation StartLoc = TheLexer.getSourceLocation();
+
   bool InPreprocessorDirective = false;
   Token TheTok;
   Token IfStartTok;
diff --git a/test/Index/preamble-reparse-with-BOM.m b/test/Index/preamble-reparse-with-BOM.m
new file mode 100644 (file)
index 0000000..a2a89c8
--- /dev/null
@@ -0,0 +1,6 @@
+
+@interface I2
+@end
+
+// RUN: env CINDEXTEST_EDITING=1 CINDEXTEST_FAILONERROR=1 \
+// RUN:   c-index-test -test-load-source-reparse 1 local %s