From aafe2c6da93373b5f612c406037c5b75ba9deb46 Mon Sep 17 00:00:00 2001 From: Josh Stone Date: Fri, 5 Apr 2019 17:48:23 -0700 Subject: Show better errors for LLVM IR output I was trying to output LLVM IR directly to the console: $ rustc hello.rs --emit=llvm-ir -o /dev/stdout LLVM ERROR: IO failure on output stream: Bad file descriptor Now `LLVMRustPrintModule` returns an error, and we print: error: failed to write LLVM IR to /dev/stdout.hello.7rcbfp3g-cgu.0.rcgu.ll: Permission denied ... which is more informative. --- src/rustllvm/PassWrapper.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) (limited to 'src/rustllvm/PassWrapper.cpp') diff --git a/src/rustllvm/PassWrapper.cpp b/src/rustllvm/PassWrapper.cpp index 25595e14982..319c66a21f1 100644 --- a/src/rustllvm/PassWrapper.cpp +++ b/src/rustllvm/PassWrapper.cpp @@ -646,8 +646,9 @@ char RustPrintModulePass::ID = 0; INITIALIZE_PASS(RustPrintModulePass, "print-rust-module", "Print rust module to stderr", false, false) -extern "C" void LLVMRustPrintModule(LLVMPassManagerRef PMR, LLVMModuleRef M, - const char *Path, DemangleFn Demangle) { +extern "C" LLVMRustResult +LLVMRustPrintModule(LLVMPassManagerRef PMR, LLVMModuleRef M, + const char *Path, DemangleFn Demangle) { llvm::legacy::PassManager *PM = unwrap(PMR); std::string ErrorInfo; @@ -655,12 +656,18 @@ extern "C" void LLVMRustPrintModule(LLVMPassManagerRef PMR, LLVMModuleRef M, raw_fd_ostream OS(Path, EC, sys::fs::F_None); if (EC) ErrorInfo = EC.message(); + if (ErrorInfo != "") { + LLVMRustSetLastError(ErrorInfo.c_str()); + return LLVMRustResult::Failure; + } formatted_raw_ostream FOS(OS); PM->add(new RustPrintModulePass(FOS, Demangle)); PM->run(*unwrap(M)); + + return LLVMRustResult::Success; } extern "C" void LLVMRustPrintPasses() { -- cgit 1.4.1-3-g733a5