arphaman created this revision.

We should clear the error on the output stream to prevent the call to 
`report_fatal_error` from `raw_fd_ostreams`'s destructor.

I couldn't think of a way to test this, do you think it's possible to have a 
test for this?


Repository:
  rL LLVM

https://reviews.llvm.org/D33357

Files:
  lib/Serialization/ASTReader.cpp


Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -3650,9 +3650,13 @@
   std::string TimestampFilename = MF.getTimestampFilename();
   std::error_code EC;
   llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text);
-  if (EC)
+  if (EC) {
+    OS.clear_error(); // Avoid triggering a fatal error.
     return;
+  }
   OS << "Timestamp file\n";
+  OS.close();
+  OS.clear_error(); // Avoid triggering a fatal error.
 }
 
 /// \brief Given a cursor at the start of an AST file, scan ahead and drop the


Index: lib/Serialization/ASTReader.cpp
===================================================================
--- lib/Serialization/ASTReader.cpp
+++ lib/Serialization/ASTReader.cpp
@@ -3650,9 +3650,13 @@
   std::string TimestampFilename = MF.getTimestampFilename();
   std::error_code EC;
   llvm::raw_fd_ostream OS(TimestampFilename, EC, llvm::sys::fs::F_Text);
-  if (EC)
+  if (EC) {
+    OS.clear_error(); // Avoid triggering a fatal error.
     return;
+  }
   OS << "Timestamp file\n";
+  OS.close();
+  OS.clear_error(); // Avoid triggering a fatal error.
 }
 
 /// \brief Given a cursor at the start of an AST file, scan ahead and drop the
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to