llvm-c: Don't assert in LLVMTargetMachineEmitToFile on nonexistent file
authorAnders Waldenborg <anders@0x63.nu>
Thu, 17 Oct 2013 10:39:35 +0000 (10:39 +0000)
committerAnders Waldenborg <anders@0x63.nu>
Thu, 17 Oct 2013 10:39:35 +0000 (10:39 +0000)
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

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@192881 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Target/TargetMachineC.cpp

index 9fccfcd9e22517c265b6f7e791d99223ed4ecb2b..2bb0f4c3e9a1e0a530e70c36ac47031f146a57d8 100644 (file)
@@ -205,11 +205,11 @@ LLVMBool LLVMTargetMachineEmitToFile(LLVMTargetMachineRef T, LLVMModuleRef M,
   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;