PTH-- Remove feature entirely-

When debugging a boost build with a modified
version of Clang, I discovered that the PTH implementation
stores TokenKind in 8 bits. However, we currently have 368
TokenKinds.

The result is that the value gets truncated and the wrong token
gets picked up when including PTH files. It seems that this will
go wrong every time someone uses a token that uses the 9th bit.

Upon asking on IRC, it was brought up that this was a highly
experimental features that was considered a failure. I discovered
via googling that BoostBuild (mostly Boost.Math) is the only user of
this
feature, using the CC1 flag directly. I believe that this can be
transferred over to normal PCH with minimal effort:
https://github.com/boostorg/build/issues/367

Based on advice on IRC and research showing that this is a nearly
completely unused feature, this patch removes it entirely.

Note: I considered leaving the build-flags in place and making them
emit an error/warning, however since I've basically identified and
warned the only user, it seemed better to just remove them.

Differential Revision: https://reviews.llvm.org/D54547

Change-Id: If32744275ef1f585357bd6c1c813d96973c4d8d9
llvm-svn: 348266
diff --git a/clang/lib/Lex/PPLexerChange.cpp b/clang/lib/Lex/PPLexerChange.cpp
index 76ccfb7..e321dd3 100644
--- a/clang/lib/Lex/PPLexerChange.cpp
+++ b/clang/lib/Lex/PPLexerChange.cpp
@@ -19,7 +19,6 @@
 #include "clang/Lex/HeaderSearch.h"
 #include "clang/Lex/LexDiagnostic.h"
 #include "clang/Lex/MacroInfo.h"
-#include "clang/Lex/PTHManager.h"
 #include "llvm/ADT/StringSwitch.h"
 #include "llvm/Support/FileSystem.h"
 #include "llvm/Support/MemoryBuffer.h"
@@ -76,13 +75,6 @@
   if (MaxIncludeStackDepth < IncludeMacroStack.size())
     MaxIncludeStackDepth = IncludeMacroStack.size();
 
-  if (PTH) {
-    if (PTHLexer *PL = PTH->CreateLexer(FID)) {
-      EnterSourceFileWithPTH(PL, CurDir);
-      return false;
-    }
-  }
-
   // Get the MemoryBuffer for this FID, if it fails, we fail.
   bool Invalid = false;
   const llvm::MemoryBuffer *InputFile =
@@ -131,31 +123,6 @@
   }
 }
 
-/// EnterSourceFileWithPTH - Add a source file to the top of the include stack
-/// and start getting tokens from it using the PTH cache.
-void Preprocessor::EnterSourceFileWithPTH(PTHLexer *PL,
-                                          const DirectoryLookup *CurDir) {
-
-  if (CurPPLexer || CurTokenLexer)
-    PushIncludeMacroStack();
-
-  CurDirLookup = CurDir;
-  CurPTHLexer.reset(PL);
-  CurPPLexer = CurPTHLexer.get();
-  CurLexerSubmodule = nullptr;
-  if (CurLexerKind != CLK_LexAfterModuleImport)
-    CurLexerKind = CLK_PTHLexer;
-
-  // Notify the client, if desired, that we are in a new source file.
-  if (Callbacks) {
-    FileID FID = CurPPLexer->getFileID();
-    SourceLocation EnterLoc = SourceMgr.getLocForStartOfFile(FID);
-    SrcMgr::CharacteristicKind FileType =
-      SourceMgr.getFileCharacteristic(EnterLoc);
-    Callbacks->FileChanged(EnterLoc, PPCallbacks::EnterFile, FileType);
-  }
-}
-
 /// EnterMacro - Add a Macro to the top of the include stack and start lexing
 /// tokens from it instead of the current buffer.
 void Preprocessor::EnterMacro(Token &Tok, SourceLocation ILEnd,
@@ -340,7 +307,6 @@
 
   // If we have an unclosed module region from a pragma at the end of a
   // module, complain and close it now.
-  // FIXME: This is not correct if we are building a module from PTH.
   const bool LeavingSubmodule = CurLexer && CurLexerSubmodule;
   if ((LeavingSubmodule || IncludeMacroStack.empty()) &&
       !BuildingSubmoduleStack.empty() &&
@@ -437,15 +403,10 @@
     if (isCodeCompletionEnabled() && CurPPLexer &&
         SourceMgr.getLocForStartOfFile(CurPPLexer->getFileID()) ==
             CodeCompletionFileLoc) {
-      if (CurLexer) {
-        Result.startToken();
-        CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
-        CurLexer.reset();
-      } else {
-        assert(CurPTHLexer && "Got EOF but no current lexer set!");
-        CurPTHLexer->getEOF(Result);
-        CurPTHLexer.reset();
-      }
+      assert(CurLexer && "Got EOF but no current lexer set!");
+      Result.startToken();
+      CurLexer->FormTokenWithChars(Result, CurLexer->BufferEnd, tok::eof);
+      CurLexer.reset();
 
       CurPPLexer = nullptr;
       recomputeCurLexerKind();
@@ -523,38 +484,33 @@
   }
 
   // If this is the end of the main file, form an EOF token.
-  if (CurLexer) {
-    const char *EndPos = getCurLexerEndPos();
-    Result.startToken();
-    CurLexer->BufferPtr = EndPos;
-    CurLexer->FormTokenWithChars(Result, EndPos, tok::eof);
+  assert(CurLexer && "Got EOF but no current lexer set!");
+  const char *EndPos = getCurLexerEndPos();
+  Result.startToken();
+  CurLexer->BufferPtr = EndPos;
+  CurLexer->FormTokenWithChars(Result, EndPos, tok::eof);
 
-    if (isCodeCompletionEnabled()) {
-      // Inserting the code-completion point increases the source buffer by 1,
-      // but the main FileID was created before inserting the point.
-      // Compensate by reducing the EOF location by 1, otherwise the location
-      // will point to the next FileID.
-      // FIXME: This is hacky, the code-completion point should probably be
-      // inserted before the main FileID is created.
-      if (CurLexer->getFileLoc() == CodeCompletionFileLoc)
-        Result.setLocation(Result.getLocation().getLocWithOffset(-1));
-    }
-
-    if (creatingPCHWithThroughHeader() && !LeavingPCHThroughHeader) {
-      // Reached the end of the compilation without finding the through header.
-      Diag(CurLexer->getFileLoc(), diag::err_pp_through_header_not_seen)
-          << PPOpts->PCHThroughHeader << 0;
-    }
-
-    if (!isIncrementalProcessingEnabled())
-      // We're done with lexing.
-      CurLexer.reset();
-  } else {
-    assert(CurPTHLexer && "Got EOF but no current lexer set!");
-    CurPTHLexer->getEOF(Result);
-    CurPTHLexer.reset();
+  if (isCodeCompletionEnabled()) {
+    // Inserting the code-completion point increases the source buffer by 1,
+    // but the main FileID was created before inserting the point.
+    // Compensate by reducing the EOF location by 1, otherwise the location
+    // will point to the next FileID.
+    // FIXME: This is hacky, the code-completion point should probably be
+    // inserted before the main FileID is created.
+    if (CurLexer->getFileLoc() == CodeCompletionFileLoc)
+      Result.setLocation(Result.getLocation().getLocWithOffset(-1));
   }
 
+  if (creatingPCHWithThroughHeader() && !LeavingPCHThroughHeader) {
+    // Reached the end of the compilation without finding the through header.
+    Diag(CurLexer->getFileLoc(), diag::err_pp_through_header_not_seen)
+        << PPOpts->PCHThroughHeader << 0;
+  }
+
+  if (!isIncrementalProcessingEnabled())
+    // We're done with lexing.
+    CurLexer.reset();
+
   if (!isIncrementalProcessingEnabled())
     CurPPLexer = nullptr;