Skip to content

Commit ce46e11

Browse files
committed
Merge pull request #2910 from gwillen/bug-2360
Better error when rustc fails to write output.
2 parents ac9cf98 + 28c1f21 commit ce46e11

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 ||
@@ -161,7 +176,8 @@ mod write {
161176
sess.targ_cfg.target_strs.target_triple,
162177
|buf_t| {
163178
str::as_c_str(output, |buf_o| {
164-
llvm::LLVMRustWriteOutputFile(
179+
WriteOutputFile(
180+
sess,
165181
pm.llpm,
166182
llmod,
167183
buf_t,
@@ -182,7 +198,8 @@ mod write {
182198
sess.targ_cfg.target_strs.target_triple,
183199
|buf_t| {
184200
str::as_c_str(output, |buf_o| {
185-
llvm::LLVMRustWriteOutputFile(
201+
WriteOutputFile(
202+
sess,
186203
pm.llpm,
187204
llmod,
188205
buf_t,
@@ -201,7 +218,8 @@ mod write {
201218
sess.targ_cfg.target_strs.target_triple,
202219
|buf_t| {
203220
str::as_c_str(output, |buf_o| {
204-
llvm::LLVMRustWriteOutputFile(
221+
WriteOutputFile(
222+
sess,
205223
pm.llpm,
206224
llmod,
207225
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)