[llvm] r192881 - llvm-c: Don't assert in LLVMTargetMachineEmitToFile on nonexistent file

Anders Waldenborg anders at 0x63.nu
Thu Oct 17 03:39:36 PDT 2013


Author: andersg
Date: Thu Oct 17 05:39:35 2013
New Revision: 192881

URL: http://llvm.org/viewvc/llvm-project?rev=192881&view=rev
Log:
llvm-c: Don't assert in LLVMTargetMachineEmitToFile on nonexistent file

Error handling code for raw_fd_ostream constructor is present, but
never used, because formatted_raw_ostream will always assert on closed
fd's before.

Patch by Peter Zotov

Differential Revision: http://llvm-reviews.chandlerc.com/D1909


Modified:
    llvm/trunk/lib/Target/TargetMachineC.cpp

Modified: llvm/trunk/lib/Target/TargetMachineC.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Target/TargetMachineC.cpp?rev=192881&r1=192880&r2=192881&view=diff
==============================================================================
--- llvm/trunk/lib/Target/TargetMachineC.cpp (original)
+++ llvm/trunk/lib/Target/TargetMachineC.cpp Thu Oct 17 05:39:35 2013
@@ -205,11 +205,11 @@ LLVMBool LLVMTargetMachineEmitToFile(LLV
   char* Filename, LLVMCodeGenFileType codegen, char** ErrorMessage) {
   std::string error;
   raw_fd_ostream dest(Filename, error, sys::fs::F_Binary);
-  formatted_raw_ostream destf(dest);
   if (!error.empty()) {
     *ErrorMessage = strdup(error.c_str());
     return true;
   }
+  formatted_raw_ostream destf(dest);
   bool Result = LLVMTargetMachineEmit(T, M, destf, codegen, ErrorMessage);
   dest.flush();
   return Result;





More information about the llvm-commits mailing list