Skip to content

Commit c0a5e34

Browse files
committed
auto merge of #13531 : alexcrichton/rust/fix-some-ices, r=brson
See the commits for the affected issues.
2 parents 8678989 + b0d85e3 commit c0a5e34

File tree

9 files changed

+95
-37
lines changed

9 files changed

+95
-37
lines changed

src/librustc/back/link.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub fn llvm_err(sess: &Session, msg: ~str) -> ! {
6060
if cstr == ptr::null() {
6161
sess.fatal(msg);
6262
} else {
63-
let err = CString::new(cstr, false);
63+
let err = CString::new(cstr, true);
6464
let err = str::from_utf8_lossy(err.as_bytes());
6565
sess.fatal(msg + ": " + err.as_slice());
6666
}
@@ -516,7 +516,10 @@ pub mod write {
516516

517517
pub fn find_crate_id(attrs: &[ast::Attribute], out_filestem: &str) -> CrateId {
518518
match attr::find_crateid(attrs) {
519-
None => from_str(out_filestem).unwrap(),
519+
None => from_str(out_filestem).unwrap_or_else(|| {
520+
let mut s = out_filestem.chars().filter(|c| c.is_XID_continue());
521+
from_str(s.collect::<~str>()).or(from_str("rust-out")).unwrap()
522+
}),
520523
Some(s) => s,
521524
}
522525
}

src/librustc/driver/driver.rs

+25-19
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ pub fn stop_after_phase_5(sess: &Session) -> bool {
493493
fn write_out_deps(sess: &Session,
494494
input: &Input,
495495
outputs: &OutputFilenames,
496-
krate: &ast::Crate) -> io::IoResult<()> {
496+
krate: &ast::Crate) {
497497
let id = link::find_crate_id(krate.attrs.as_slice(), outputs.out_filestem);
498498

499499
let mut out_filenames = Vec::new();
@@ -522,28 +522,34 @@ fn write_out_deps(sess: &Session,
522522
StrInput(..) => {
523523
sess.warn("can not write --dep-info without a filename \
524524
when compiling stdin.");
525-
return Ok(());
525+
return
526526
},
527527
},
528-
_ => return Ok(()),
528+
_ => return,
529529
};
530530

531-
// Build a list of files used to compile the output and
532-
// write Makefile-compatible dependency rules
533-
let files: Vec<~str> = sess.codemap().files.borrow()
534-
.iter().filter_map(|fmap| {
535-
if fmap.is_real_file() {
536-
Some(fmap.name.clone())
537-
} else {
538-
None
539-
}
540-
}).collect();
541-
let mut file = try!(io::File::create(&deps_filename));
542-
for path in out_filenames.iter() {
543-
try!(write!(&mut file as &mut Writer,
544-
"{}: {}\n\n", path.display(), files.connect(" ")));
531+
let result = (|| {
532+
// Build a list of files used to compile the output and
533+
// write Makefile-compatible dependency rules
534+
let files: Vec<~str> = sess.codemap().files.borrow()
535+
.iter().filter(|fmap| fmap.is_real_file())
536+
.map(|fmap| fmap.name.clone())
537+
.collect();
538+
let mut file = try!(io::File::create(&deps_filename));
539+
for path in out_filenames.iter() {
540+
try!(write!(&mut file as &mut Writer,
541+
"{}: {}\n\n", path.display(), files.connect(" ")));
542+
}
543+
Ok(())
544+
})();
545+
546+
match result {
547+
Ok(()) => {}
548+
Err(e) => {
549+
sess.fatal(format!("error writing dependencies to `{}`: {}",
550+
deps_filename.display(), e));
551+
}
545552
}
546-
Ok(())
547553
}
548554

549555
pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
@@ -567,7 +573,7 @@ pub fn compile_input(sess: Session, cfg: ast::CrateConfig, input: &Input,
567573
krate, &id);
568574
(outputs, expanded_crate, ast_map)
569575
};
570-
write_out_deps(&sess, input, &outputs, &expanded_crate).unwrap();
576+
write_out_deps(&sess, input, &outputs, &expanded_crate);
571577

572578
if stop_after_phase_2(&sess) { return; }
573579

src/rustllvm/PassWrapper.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ LLVMRustCreateTargetMachine(const char *triple,
7575
const llvm::Target *TheTarget = TargetRegistry::lookupTarget(Trip.getTriple(),
7676
Error);
7777
if (TheTarget == NULL) {
78-
LLVMRustError = Error.c_str();
78+
LLVMRustSetLastError(Error.c_str());
7979
return NULL;
8080
}
8181

@@ -178,7 +178,7 @@ LLVMRustWriteOutputFile(LLVMTargetMachineRef Target,
178178
raw_fd_ostream OS(path, ErrorInfo, raw_fd_ostream::F_Binary);
179179
#endif
180180
if (ErrorInfo != "") {
181-
LLVMRustError = ErrorInfo.c_str();
181+
LLVMRustSetLastError(ErrorInfo.c_str());
182182
return false;
183183
}
184184
formatted_raw_ostream FOS(OS);

src/rustllvm/RustWrapper.cpp

+23-13
Original file line numberDiff line numberDiff line change
@@ -23,18 +23,28 @@ using namespace llvm;
2323
using namespace llvm::sys;
2424
using namespace llvm::object;
2525

26-
const char *LLVMRustError;
26+
static char *LastError;
2727

2828
extern "C" LLVMMemoryBufferRef
2929
LLVMRustCreateMemoryBufferWithContentsOfFile(const char *Path) {
3030
LLVMMemoryBufferRef MemBuf = NULL;
31-
LLVMCreateMemoryBufferWithContentsOfFile(Path, &MemBuf,
32-
const_cast<char **>(&LLVMRustError));
31+
char *err = NULL;
32+
LLVMCreateMemoryBufferWithContentsOfFile(Path, &MemBuf, &err);
33+
if (err != NULL) {
34+
LLVMRustSetLastError(err);
35+
}
3336
return MemBuf;
3437
}
3538

36-
extern "C" const char *LLVMRustGetLastError(void) {
37-
return LLVMRustError;
39+
extern "C" char *LLVMRustGetLastError(void) {
40+
char *ret = LastError;
41+
LastError = NULL;
42+
return ret;
43+
}
44+
45+
void LLVMRustSetLastError(const char *err) {
46+
free((void*) LastError);
47+
LastError = strdup(err);
3848
}
3949

4050
extern "C" void
@@ -609,14 +619,14 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
609619
MemoryBuffer* buf = MemoryBuffer::getMemBufferCopy(StringRef(bc, len));
610620
ErrorOr<Module *> Src = llvm::getLazyBitcodeModule(buf, Dst->getContext());
611621
if (!Src) {
612-
LLVMRustError = Src.getError().message().c_str();
622+
LLVMRustSetLastError(Src.getError().message().c_str());
613623
delete buf;
614624
return false;
615625
}
616626

617627
std::string Err;
618628
if (Linker::LinkModules(Dst, *Src, Linker::DestroySource, &Err)) {
619-
LLVMRustError = Err.c_str();
629+
LLVMRustSetLastError(Err.c_str());
620630
return false;
621631
}
622632
return true;
@@ -629,13 +639,13 @@ LLVMRustLinkInExternalBitcode(LLVMModuleRef dst, char *bc, size_t len) {
629639
std::string Err;
630640
Module *Src = llvm::getLazyBitcodeModule(buf, Dst->getContext(), &Err);
631641
if (!Src) {
632-
LLVMRustError = Err.c_str();
642+
LLVMRustSetLastError(Err.c_str());
633643
delete buf;
634644
return false;
635645
}
636646

637647
if (Linker::LinkModules(Dst, Src, Linker::DestroySource, &Err)) {
638-
LLVMRustError = Err.c_str();
648+
LLVMRustSetLastError(Err.c_str());
639649
return false;
640650
}
641651
return true;
@@ -648,12 +658,12 @@ LLVMRustOpenArchive(char *path) {
648658
std::unique_ptr<MemoryBuffer> buf;
649659
error_code err = MemoryBuffer::getFile(path, buf);
650660
if (err) {
651-
LLVMRustError = err.message().c_str();
661+
LLVMRustSetLastError(err.message().c_str());
652662
return NULL;
653663
}
654664
Archive *ret = new Archive(buf.release(), err);
655665
if (err) {
656-
LLVMRustError = err.message().c_str();
666+
LLVMRustSetLastError(err.message().c_str());
657667
return NULL;
658668
}
659669
return ret;
@@ -664,12 +674,12 @@ LLVMRustOpenArchive(char *path) {
664674
OwningPtr<MemoryBuffer> buf;
665675
error_code err = MemoryBuffer::getFile(path, buf);
666676
if (err) {
667-
LLVMRustError = err.message().c_str();
677+
LLVMRustSetLastError(err.message().c_str());
668678
return NULL;
669679
}
670680
Archive *ret = new Archive(buf.take(), err);
671681
if (err) {
672-
LLVMRustError = err.message().c_str();
682+
LLVMRustSetLastError(err.message().c_str());
673683
return NULL;
674684
}
675685
return ret;

src/rustllvm/rustllvm.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,4 +68,4 @@
6868
#include <unistd.h>
6969
#endif
7070

71-
extern const char* LLVMRustError;
71+
void LLVMRustSetLastError(const char*);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
-include ../tools.mk
2+
3+
all:
4+
# Let's get a nice error message
5+
$(RUSTC) foo.rs --dep-info foo/bar/baz 2>&1 | \
6+
grep "error writing dependencies"
7+
# Make sure the filename shows up
8+
$(RUSTC) foo.rs --dep-info foo/bar/baz 2>&1 | grep "baz"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
-include ../tools.mk
2+
3+
all:
4+
$(RUSTC) foo.rs -o $(TMPDIR)/.foo
5+
rm $(TMPDIR)/.foo
6+
$(RUSTC) foo.rs -o $(TMPDIR)/.foo.bar
7+
rm $(TMPDIR)/.foo.bar
8+
$(RUSTC) foo.rs -o $(TMPDIR)/+foo+bar
9+
rm $(TMPDIR)/+foo+bar
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// Copyright 2014 The Rust Project Developers. See the COPYRIGHT
2+
// file at the top-level directory of this distribution and at
3+
// http://rust-lang.org/COPYRIGHT.
4+
//
5+
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6+
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7+
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8+
// option. This file may not be copied, modified, or distributed
9+
// except according to those terms.
10+
11+
fn main() {}

0 commit comments

Comments
 (0)