From 9be5694168044312a493503e1e53646c6978aa33 Mon Sep 17 00:00:00 2001 From: Tomas Lindquist Olsen Date: Sun, 17 May 2009 14:40:09 +0200 Subject: [PATCH] Added error messages when failed to open files for .bc and .ll output, instead of just trying to write to the stream, pretty similar to the #281 problem. --- gen/toobj.cpp | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/gen/toobj.cpp b/gen/toobj.cpp index 76977869..2bd60e31 100644 --- a/gen/toobj.cpp +++ b/gen/toobj.cpp @@ -210,6 +210,11 @@ void writeModule(llvm::Module* m, std::string filename) bcpath.appendSuffix(std::string(global.bc_ext)); Logger::println("Writing LLVM bitcode to: %s\n", bcpath.c_str()); std::ofstream bos(bcpath.c_str(), std::ios::binary); + if (bos.fail()) + { + error("cannot write LLVM bitcode, failed to open file '%s'", bcpath.c_str()); + fatal(); + } llvm::WriteBitcodeToFile(m, bos); } @@ -220,6 +225,11 @@ void writeModule(llvm::Module* m, std::string filename) llpath.appendSuffix(std::string(global.ll_ext)); Logger::println("Writing LLVM asm to: %s\n", llpath.c_str()); std::ofstream aos(llpath.c_str()); + if (aos.fail()) + { + error("cannot write LLVM asm, failed to open file '%s'", llpath.c_str()); + fatal(); + } m->print(aos, NULL); }