[PATCH] D33357: Avoid calling report_fatal_error in the destructor of raw_fd_ostream when saving a module timestamp file

Alex Lorenz via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri May 19 07:54:07 PDT 2017


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


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D33357.99568.patch
Type: text/x-patch
Size: 646 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20170519/e8f71442/attachment-0001.bin>


More information about the cfe-commits mailing list