[llvm-commits] [llvm] r111651 - in /llvm/trunk/tools: bugpoint/ExtractFunction.cpp bugpoint/OptimizerDriver.cpp gold/gold-plugin.cpp llvm-ld/llvm-ld.cpp lto/LTOCodeGenerator.cpp opt/GraphPrinters.cpp

Dan Gohman gohman at apple.com
Fri Aug 20 09:59:15 PDT 2010


Author: djg
Date: Fri Aug 20 11:59:15 2010
New Revision: 111651

URL: http://llvm.org/viewvc/llvm-project?rev=111651&view=rev
Log:
Convert tools to use tool_output_file, and introduce error
checking to places which previously lacked it.

Modified:
    llvm/trunk/tools/bugpoint/ExtractFunction.cpp
    llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
    llvm/trunk/tools/gold/gold-plugin.cpp
    llvm/trunk/tools/llvm-ld/llvm-ld.cpp
    llvm/trunk/tools/lto/LTOCodeGenerator.cpp
    llvm/trunk/tools/opt/GraphPrinters.cpp

Modified: llvm/trunk/tools/bugpoint/ExtractFunction.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/ExtractFunction.cpp?rev=111651&r1=111650&r2=111651&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/ExtractFunction.cpp (original)
+++ llvm/trunk/tools/bugpoint/ExtractFunction.cpp Fri Aug 20 11:59:15 2010
@@ -325,7 +325,7 @@
   sys::RemoveFileOnSignal(uniqueFilename);
 
   std::string ErrorInfo;
-  raw_fd_ostream BlocksToNotExtractFile(uniqueFilename.c_str(), ErrorInfo);
+  tool_output_file BlocksToNotExtractFile(uniqueFilename.c_str(), ErrorInfo);
   if (!ErrorInfo.empty()) {
     outs() << "*** Basic Block extraction failed!\n";
     errs() << "Error writing list of blocks to not extract: " << ErrorInfo
@@ -343,6 +343,14 @@
                            << BB->getName() << "\n";
   }
   BlocksToNotExtractFile.close();
+  if (BlocksToNotExtractFile.has_error()) {
+    errs() << "Error writing list of blocks to not extract: " << ErrorInfo
+           << "\n";
+    EmitProgressBitcode(M, "basicblockextractfail", true);
+    BlocksToNotExtractFile.clear_error();
+    return 0;
+  }
+  BlocksToNotExtractFile.keep();
 
   std::string uniqueFN = "--extract-blocks-file=" + uniqueFilename.str();
   const char *ExtraArg = uniqueFN.c_str();

Modified: llvm/trunk/tools/bugpoint/OptimizerDriver.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/bugpoint/OptimizerDriver.cpp?rev=111651&r1=111650&r2=111651&view=diff
==============================================================================
--- llvm/trunk/tools/bugpoint/OptimizerDriver.cpp (original)
+++ llvm/trunk/tools/bugpoint/OptimizerDriver.cpp Fri Aug 20 11:59:15 2010
@@ -54,12 +54,18 @@
 bool BugDriver::writeProgramToFile(const std::string &Filename,
                                    const Module *M) const {
   std::string ErrInfo;
-  raw_fd_ostream Out(Filename.c_str(), ErrInfo,
-                     raw_fd_ostream::F_Binary);
-  if (!ErrInfo.empty()) return true;
-  
-  WriteBitcodeToFile(M, Out);
-  return false;
+  tool_output_file Out(Filename.c_str(), ErrInfo,
+                       raw_fd_ostream::F_Binary);
+  if (ErrInfo.empty()) {
+    WriteBitcodeToFile(M, Out);
+    Out.close();
+    if (!Out.has_error()) {
+      Out.keep();
+      return false;
+    }
+  }
+  Out.clear_error();
+  return true;
 }
 
 
@@ -125,8 +131,8 @@
   }
   
   std::string ErrInfo;
-  raw_fd_ostream InFile(inputFilename.c_str(), ErrInfo,
-                        raw_fd_ostream::F_Binary);
+  tool_output_file InFile(inputFilename.c_str(), ErrInfo,
+                          raw_fd_ostream::F_Binary);
   
   
   if (!ErrInfo.empty()) {
@@ -135,6 +141,12 @@
   }
   WriteBitcodeToFile(Program, InFile);
   InFile.close();
+  if (InFile.has_error()) {
+    errs() << "Error writing bitcode file: " << inputFilename.str() << "\n";
+    InFile.clear_error();
+    return 1;
+  }
+  InFile.keep();
 
   // setup the child process' arguments
   SmallVector<const char*, 8> Args;

Modified: llvm/trunk/tools/gold/gold-plugin.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/gold/gold-plugin.cpp?rev=111651&r1=111650&r2=111651&view=diff
==============================================================================
--- llvm/trunk/tools/gold/gold-plugin.cpp (original)
+++ llvm/trunk/tools/gold/gold-plugin.cpp Fri Aug 20 11:59:15 2010
@@ -453,8 +453,8 @@
     (*message)(LDPL_ERROR, "%s", ErrMsg.c_str());
     return LDPS_ERR;
   }
-  raw_fd_ostream objFile(uniqueObjPath.c_str(), ErrMsg,
-                         raw_fd_ostream::F_Binary);
+  tool_output_file objFile(uniqueObjPath.c_str(), ErrMsg,
+                           raw_fd_ostream::F_Binary);
   if (!ErrMsg.empty()) {
     (*message)(LDPL_ERROR, "%s", ErrMsg.c_str());
     return LDPS_ERR;
@@ -462,6 +462,13 @@
 
   objFile.write(buffer, bufsize);
   objFile.close();
+  if (objFile.has_error()) {
+    (*message)(LDPL_ERROR, "Error writing output file '%s'",
+               uniqueObjPath.c_str());
+    objFile.clear_error();
+    return LDPS_ERR;
+  }
+  objFile.keep();
 
   lto_codegen_dispose(cg);
 

Modified: llvm/trunk/tools/llvm-ld/llvm-ld.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/llvm-ld/llvm-ld.cpp?rev=111651&r1=111650&r2=111651&view=diff
==============================================================================
--- llvm/trunk/tools/llvm-ld/llvm-ld.cpp (original)
+++ llvm/trunk/tools/llvm-ld/llvm-ld.cpp Fri Aug 20 11:59:15 2010
@@ -236,13 +236,16 @@
 
   // Create the output file.
   std::string ErrorInfo;
-  raw_fd_ostream Out(FileName.c_str(), ErrorInfo,
-                     raw_fd_ostream::F_Binary);
-  if (!ErrorInfo.empty())
+  tool_output_file Out(FileName.c_str(), ErrorInfo,
+                       raw_fd_ostream::F_Binary);
+  if (!ErrorInfo.empty()) {
     PrintAndExit(ErrorInfo, M);
+    return;
+  }
 
   // Write it out
   WriteBitcodeToFile(M, Out);
+  Out.keep();
 }
 
 /// GenerateAssembly - generates a native assembly language source file from the
@@ -425,7 +428,7 @@
 
   // Output the script to start the program...
   std::string ErrorInfo;
-  raw_fd_ostream Out2(OutputFilename.c_str(), ErrorInfo);
+  tool_output_file Out2(OutputFilename.c_str(), ErrorInfo);
   if (!ErrorInfo.empty())
     PrintAndExit(ErrorInfo, M);
 
@@ -466,6 +469,7 @@
       Out2 << "    -load=" << FullLibraryPath.str() << " \\\n";
   }
   Out2 << "    "  << BitcodeOutputFilename << " ${1+\"$@\"}\n";
+  Out2.keep();
 }
 
 // BuildLinkItems -- This function generates a LinkItemList for the LinkItems

Modified: llvm/trunk/tools/lto/LTOCodeGenerator.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/lto/LTOCodeGenerator.cpp?rev=111651&r1=111650&r2=111651&view=diff
==============================================================================
--- llvm/trunk/tools/lto/LTOCodeGenerator.cpp (original)
+++ llvm/trunk/tools/lto/LTOCodeGenerator.cpp Fri Aug 20 11:59:15 2010
@@ -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();

Modified: llvm/trunk/tools/opt/GraphPrinters.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/tools/opt/GraphPrinters.cpp?rev=111651&r1=111650&r2=111651&view=diff
==============================================================================
--- llvm/trunk/tools/opt/GraphPrinters.cpp (original)
+++ llvm/trunk/tools/opt/GraphPrinters.cpp Fri Aug 20 11:59:15 2010
@@ -28,13 +28,19 @@
   std::string Filename = GraphName + ".dot";
   O << "Writing '" << Filename << "'...";
   std::string ErrInfo;
-  raw_fd_ostream F(Filename.c_str(), ErrInfo);
+  tool_output_file F(Filename.c_str(), ErrInfo);
 
-  if (ErrInfo.empty())
+  if (ErrInfo.empty()) {
     WriteGraph(F, GT);
-  else
-    O << "  error opening file for writing!";
-  O << "\n";
+    F.close();
+    if (!F.has_error()) {
+      O << "\n";
+      F.keep();
+      return;
+    }
+  }
+  F.clear_error();
+  O << "  error opening file for writing!\n";
 }
 
 





More information about the llvm-commits mailing list