Decouple more of clang-cc by moving ImplicitP[CT]H options into
PreprocessorOptions.

Global variables used as [in] [out] parameters considered harmful.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@86728 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/include/clang/Frontend/PreprocessorOptions.h b/include/clang/Frontend/PreprocessorOptions.h
index cae37e7..d2af829 100644
--- a/include/clang/Frontend/PreprocessorOptions.h
+++ b/include/clang/Frontend/PreprocessorOptions.h
@@ -28,6 +28,13 @@
   unsigned UsePredefines : 1; /// Initialize the preprocessor with the compiler
                               /// and target specific predefines.
 
+  /// The implicit PCH included at the start of the translation unit, or empty.
+  std::string ImplicitPCHInclude;
+
+  /// The implicit PTH input included at the start of the translation unit, or
+  /// empty.
+  std::string ImplicitPTHInclude;
+
 public:
   PreprocessorOptions() : UsePredefines(true) {}
 
@@ -36,6 +43,24 @@
     UsePredefines = Value;
   }
 
+  const std::string &getImplicitPCHInclude() const {
+    return ImplicitPCHInclude;
+  }
+  void setImplicitPCHInclude(llvm::StringRef Value) {
+    assert((Value.empty() || ImplicitPTHInclude.empty()) &&
+           "Cannot both implicit PCH and PTH includes!");
+    ImplicitPCHInclude = Value;
+  }
+
+  const std::string &getImplicitPTHInclude() const {
+    return ImplicitPTHInclude;
+  }
+  void setImplicitPTHInclude(llvm::StringRef Value) {
+    assert((ImplicitPCHInclude.empty() || Value.empty()) &&
+           "Cannot both implicit PCH and PTH includes!");
+    ImplicitPTHInclude = Value;
+  }
+
   void addMacroDef(const std::string &Name) {
     Macros.push_back(std::make_pair(Name, false));
   }
diff --git a/tools/clang-cc/clang-cc.cpp b/tools/clang-cc/clang-cc.cpp
index f08c768..74a8363 100644
--- a/tools/clang-cc/clang-cc.cpp
+++ b/tools/clang-cc/clang-cc.cpp
@@ -1090,6 +1090,9 @@
 }
 
 static void InitializePreprocessorOptions(PreprocessorOptions &InitOpts) {
+  InitOpts.setImplicitPCHInclude(ImplicitIncludePCH);
+  InitOpts.setImplicitPTHInclude(ImplicitIncludePTH);
+
   // Use predefines?
   InitOpts.setUsePredefines(!UndefMacros);
 
@@ -1143,7 +1146,7 @@
         std::string OriginalFile = PCHReader::getOriginalSourceFile(*Ptr);
         if (!OriginalFile.empty()) {
           InitOpts.addInclude(OriginalFile, false);
-          ImplicitIncludePCH.clear();
+          InitOpts.setImplicitPCHInclude("");
         }
       }
     }
@@ -1159,15 +1162,16 @@
                    const PreprocessorOptions &PPOpts, TargetInfo &Target,
                    SourceManager &SourceMgr, HeaderSearch &HeaderInfo) {
   PTHManager *PTHMgr = 0;
-  if (!TokenCache.empty() && !ImplicitIncludePTH.empty()) {
+  if (!TokenCache.empty() && !PPOpts.getImplicitPTHInclude().empty()) {
     fprintf(stderr, "error: cannot use both -token-cache and -include-pth "
             "options\n");
     exit(1);
   }
 
   // Use PTH?
-  if (!TokenCache.empty() || !ImplicitIncludePTH.empty()) {
-    const std::string& x = TokenCache.empty() ? ImplicitIncludePTH:TokenCache;
+  if (!TokenCache.empty() || !PPOpts.getImplicitPTHInclude().empty()) {
+    const std::string& x = TokenCache.empty() ?
+      PPOpts.getImplicitPTHInclude() : TokenCache;
     PTHMgr = PTHManager::Create(x, &Diags,
                                 TokenCache.empty() ? Diagnostic::Error
                                 : Diagnostic::Warning);
@@ -1736,7 +1740,9 @@
   llvm::OwningPtr<PCHReader> Reader;
   llvm::OwningPtr<ExternalASTSource> Source;
 
-  if (!ImplicitIncludePCH.empty()) {
+  const std::string &ImplicitPCHInclude =
+    CompOpts.getPreprocessorOpts().getImplicitPCHInclude();
+  if (!ImplicitPCHInclude.empty()) {
     // If the user specified -isysroot, it will be used for relocatable PCH
     // files.
     const char *isysrootPCH = 0;
@@ -1747,7 +1753,7 @@
 
     // The user has asked us to include a precompiled header. Load
     // the precompiled header into the AST context.
-    switch (Reader->ReadPCH(ImplicitIncludePCH)) {
+    switch (Reader->ReadPCH(ImplicitPCHInclude)) {
     case PCHReader::Success: {
       // Set the predefines buffer as suggested by the PCH
       // reader. Typically, the predefines buffer will be empty.
@@ -2206,7 +2212,7 @@
                               PhonyDependencyTarget);
     }
 
-    if (ImplicitIncludePCH.empty()) {
+    if (CompOpts.getPreprocessorOpts().getImplicitPCHInclude().empty()) {
       if (InitializeSourceManager(*PP.get(), InFile))
         continue;