Skip to content

Commit 28c1f21

Browse files
committed
Better error when rustc fails to write output.
1 parent 05ff4f4 commit 28c1f21

File tree

3 files changed

+29
-6
lines changed

3 files changed

+29
-6
lines changed

src/rustc/back/link.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import libc::{c_int, c_uint};
1+
import libc::{c_int, c_uint, c_char};
22
import driver::session;
33
import session::session;
44
import lib::llvm::llvm;
@@ -32,6 +32,21 @@ fn llvm_err(sess: session, msg: str) -> ! unsafe {
3232
} else { sess.fatal(msg + ": " + str::unsafe::from_c_str(cstr)); }
3333
}
3434

35+
fn WriteOutputFile(sess:session,
36+
PM: lib::llvm::PassManagerRef, M: ModuleRef,
37+
Triple: *c_char,
38+
// FIXME: When #2334 is fixed, change
39+
// c_uint to FileType
40+
Output: *c_char, FileType: c_uint,
41+
OptLevel: c_int,
42+
EnableSegmentedStacks: bool) {
43+
let result = llvm::LLVMRustWriteOutputFile(
44+
PM, M, Triple, Output, FileType, OptLevel, EnableSegmentedStacks);
45+
if (!result) {
46+
llvm_err(sess, "Could not write output");
47+
}
48+
}
49+
3550
mod write {
3651
fn is_object_or_assembly_or_exe(ot: output_type) -> bool {
3752
if ot == output_type_assembly || ot == output_type_object ||
@@ -160,7 +175,8 @@ mod write {
160175
sess.targ_cfg.target_strs.target_triple,
161176
|buf_t| {
162177
str::as_c_str(output, |buf_o| {
163-
llvm::LLVMRustWriteOutputFile(
178+
WriteOutputFile(
179+
sess,
164180
pm.llpm,
165181
llmod,
166182
buf_t,
@@ -181,7 +197,8 @@ mod write {
181197
sess.targ_cfg.target_strs.target_triple,
182198
|buf_t| {
183199
str::as_c_str(output, |buf_o| {
184-
llvm::LLVMRustWriteOutputFile(
200+
WriteOutputFile(
201+
sess,
185202
pm.llpm,
186203
llmod,
187204
buf_t,
@@ -200,7 +217,8 @@ mod write {
200217
sess.targ_cfg.target_strs.target_triple,
201218
|buf_t| {
202219
str::as_c_str(output, |buf_o| {
203-
llvm::LLVMRustWriteOutputFile(
220+
WriteOutputFile(
221+
sess,
204222
pm.llpm,
205223
llmod,
206224
buf_t,

src/rustc/lib/llvm.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -941,7 +941,7 @@ extern mod llvm {
941941
// c_uint to FileType
942942
Output: *c_char, FileType: c_uint,
943943
OptLevel: c_int,
944-
EnableSegmentedStacks: bool);
944+
EnableSegmentedStacks: bool) -> bool;
945945

946946
/** Returns a string describing the last error caused by an LLVMRust*
947947
call. */

src/rustllvm/RustWrapper.cpp

+6-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ extern "C" bool LLVMLinkModules(LLVMModuleRef Dest, LLVMModuleRef Src) {
7575
return true;
7676
}
7777

78-
extern "C" void
78+
extern "C" bool
7979
LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
8080
LLVMModuleRef M,
8181
const char *triple,
@@ -107,13 +107,18 @@ LLVMRustWriteOutputFile(LLVMPassManagerRef PMR,
107107
std::string ErrorInfo;
108108
raw_fd_ostream OS(path, ErrorInfo,
109109
raw_fd_ostream::F_Binary);
110+
if (ErrorInfo != "") {
111+
LLVMRustError = ErrorInfo.c_str();
112+
return false;
113+
}
110114
formatted_raw_ostream FOS(OS);
111115

112116
bool foo = Target->addPassesToEmitFile(*PM, FOS, FileType, NoVerify);
113117
assert(!foo);
114118
(void)foo;
115119
PM->run(*unwrap(M));
116120
delete Target;
121+
return true;
117122
}
118123

119124
extern "C" LLVMModuleRef LLVMRustParseAssemblyFile(const char *Filename) {

0 commit comments

Comments
 (0)