For source location entries that describe instantiations, encode the
token length in the PCH file rather than trying (and failing) to
reconstruct it be getting the spelling token's length.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@69191 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Frontend/PCHWriter.cpp b/lib/Frontend/PCHWriter.cpp
index 6c3056a..0b5a2a6 100644
--- a/lib/Frontend/PCHWriter.cpp
+++ b/lib/Frontend/PCHWriter.cpp
@@ -736,6 +736,7 @@
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Spelling location
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // Start location
   Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 8)); // End location
+  Abbrev->Add(BitCodeAbbrevOp(BitCodeAbbrevOp::VBR, 6)); // Token length
   return S.EmitAbbrev(Abbrev);
 }
 
@@ -818,6 +819,13 @@
       Record.push_back(Inst.getInstantiationLocStart().getRawEncoding());
       Record.push_back(Inst.getInstantiationLocEnd().getRawEncoding());
 
+      // Compute the token length for this macro expansion.
+      unsigned NextOffset = SourceMgr.getNextOffset();
+      SourceManager::sloc_entry_iterator NextSLoc = SLoc;
+      if (++NextSLoc != SLocEnd)
+        NextOffset = NextSLoc->getOffset();
+      Record.push_back(NextOffset - SLoc->getOffset() - 1);
+
       if (SLocInstantiationAbbrv == -1)
         SLocInstantiationAbbrv = CreateSLocInstantiationAbbrev(S);
       S.EmitRecordWithAbbrev(SLocInstantiationAbbrv, Record);