Don't silently ignore errors when opening output streams.
authorDan Gohman <gohman@apple.com>
Thu, 21 Aug 2008 15:33:45 +0000 (15:33 +0000)
committerDan Gohman <gohman@apple.com>
Thu, 21 Aug 2008 15:33:45 +0000 (15:33 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@55120 91177308-0d34-0410-b5e6-96231b3b80d8

tools/llc/llc.cpp
tools/lto/LTOCodeGenerator.cpp

index 2c725e8a2f1e00eacae08fa95c1865bc21c9f762..03972b10ca7fee8c94368e844bb6bffb58112061 100644 (file)
@@ -125,7 +125,14 @@ static raw_ostream *GetOutputStream(const char *ProgName) {
     sys::RemoveFileOnSignal(sys::Path(OutputFilename));
 
     std::string error;
-    return new raw_fd_ostream(OutputFilename.c_str(), error);
+    raw_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), error);
+    if (!error.empty()) {
+      std::cerr << error << '\n';
+      delete Out;
+      return 0;
+    }
+
+    return Out;
   }
   
   if (InputFilename == "-") {
@@ -170,7 +177,7 @@ static raw_ostream *GetOutputStream(const char *ProgName) {
   std::string error;
   raw_ostream *Out = new raw_fd_ostream(OutputFilename.c_str(), error);
   if (!error.empty()) {
-    std::cerr << error;
+    std::cerr << error << '\n';
     delete Out;
     return 0;
   }
index 275aac208f3f174ecfb1b1b4538d394cfd8ed971..c035be99873e7e1ea26aca041655709439e10ba9 100644 (file)
@@ -163,10 +163,11 @@ const void* LTOCodeGenerator::compile(size_t* length, std::string& errMsg)
     sys::RemoveFileOnSignal(uniqueAsmPath);
        
     // generate assembly code
-    std::string error;
     bool genResult = false;
     {
-      raw_fd_ostream asmFile(uniqueAsmPath.c_str(), error);
+      raw_fd_ostream asmFile(uniqueAsmPath.c_str(), errMsg);
+      if (!errMsg.empty())
+        return NULL;
       genResult = this->generateAssemblyCode(asmFile, errMsg);
     }
     if ( genResult ) {