Driver: Construct temporary file names.
 - This is still suboptimal, but should at least be workable.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@67223 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Driver/Driver.cpp b/lib/Driver/Driver.cpp
index 49a4dca..9d913a1 100644
--- a/lib/Driver/Driver.cpp
+++ b/lib/Driver/Driver.cpp
@@ -808,11 +808,9 @@
 
   // Output to a temporary file?
   if (!AtTopLevel && !C.getArgs().hasArg(options::OPT_save_temps)) {
-    // FIXME: Get temporary name.
-    std::string Name("/tmp/foo");
-    Name += '.';
-    Name += types::getTypeTempSuffix(JA.getType());
-    return C.addTempFile(C.getArgs().MakeArgString(Name.c_str()));
+    std::string TmpName = 
+      GetTemporaryPath(types::getTypeTempSuffix(JA.getType()));
+    return C.addTempFile(C.getArgs().MakeArgString(TmpName.c_str()));
   }
 
   llvm::sys::Path BasePath(BaseInput);
@@ -861,6 +859,20 @@
   return llvm::sys::Path(Name);
 }
 
+std::string Driver::GetTemporaryPath(const char *Suffix) const {
+  // FIXME: This is lame; sys::Path should provide this function (in
+  // particular, it should know how to find the temporary files dir).
+  std::string Error;
+  llvm::sys::Path P("/tmp/cc");
+  if (P.makeUnique(false, &Error)) {
+    Diag(clang::diag::err_drv_unable_to_make_temp) << Error;
+    return "";
+  }
+
+  P.appendSuffix(Suffix);
+  return P.toString();
+}
+
 const HostInfo *Driver::GetHostInfo(const char *Triple) const {
   llvm::PrettyStackTraceString CrashInfo("Constructing host");
   // Dice into arch, platform, and OS. This matches