From 2cd4fd4b7554480cbea67b48de5e5d467d06e292 Mon Sep 17 00:00:00 2001
From: Douglas Gregor <dgregor@apple.com>
Date: Sat, 11 Sep 2010 17:56:52 +0000
Subject: [PATCH] If we fail to create a temporary file for the precompiled
 preamble, just abort creation of the precompiled preamble rather than doing
 silly things. This is the second part of the fix for the weird
 preamble-related failures on Windows. Big thanks to Francois Pichet for the
 great detective work!

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@113697 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Frontend/ASTUnit.cpp | 11 ++++++++++-
 1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/lib/Frontend/ASTUnit.cpp b/lib/Frontend/ASTUnit.cpp
index 9fbaeeaac04..4cbb2a3f13a 100644
--- a/lib/Frontend/ASTUnit.cpp
+++ b/lib/Frontend/ASTUnit.cpp
@@ -1093,6 +1093,15 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
     return 0;
   }
 
+  // Create a temporary file for the precompiled preamble. In rare 
+  // circumstances, this can fail.
+  std::string PreamblePCHPath = GetPreamblePCHPath();
+  if (PreamblePCHPath.empty()) {
+    // Try again next time.
+    PreambleRebuildCounter = 1;
+    return 0;
+  }
+  
   // We did not previously compute a preamble, or it can't be reused anyway.
   llvm::Timer *PreambleTimer = 0;
   if (TimerGroup.get()) {
@@ -1138,7 +1147,7 @@ llvm::MemoryBuffer *ASTUnit::getMainBufferWithPrecompiledPreamble(
   if (::getenv("LIBCLANG_CHAINING"))
     FrontendOpts.ChainedPCH = true;
   // FIXME: Generate the precompiled header into memory?
-  FrontendOpts.OutputFile = GetPreamblePCHPath();
+  FrontendOpts.OutputFile = PreamblePCHPath;
   
   // Create the compiler instance to use for building the precompiled preamble.
   CompilerInstance Clang;
-- 
GitLab