Convert tools to use tool_output_file, and introduce error
checking to places which previously lacked it.


git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@111651 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/tools/lto/LTOCodeGenerator.cpp b/tools/lto/LTOCodeGenerator.cpp
index b69bcc3..67b1765 100644
--- a/tools/lto/LTOCodeGenerator.cpp
+++ b/tools/lto/LTOCodeGenerator.cpp
@@ -155,8 +155,8 @@
 
   // create output file
   std::string ErrInfo;
-  raw_fd_ostream Out(path, ErrInfo,
-                     raw_fd_ostream::F_Binary);
+  tool_output_file Out(path, ErrInfo,
+                       raw_fd_ostream::F_Binary);
   if (!ErrInfo.empty()) {
     errMsg = "could not open bitcode file for writing: ";
     errMsg += path;
@@ -174,6 +174,7 @@
     return true;
   }
   
+  Out.keep();
   return false;
 }
 
@@ -189,11 +190,17 @@
     // generate assembly code
     bool genResult = false;
     {
-      raw_fd_ostream asmFD(uniqueAsmPath.c_str(), errMsg);
-      formatted_raw_ostream asmFile(asmFD);
+      tool_output_file asmFD(uniqueAsmPath.c_str(), errMsg);
+      formatted_tool_output_file asmFile(asmFD);
       if (!errMsg.empty())
         return NULL;
       genResult = this->generateAssemblyCode(asmFile, errMsg);
+      asmFile.close();
+      if (asmFile.has_error()) {
+        asmFile.clear_error();
+        return NULL;
+      }
+      asmFile.keep();
     }
     if ( genResult ) {
         uniqueAsmPath.eraseFromDisk();