Skip to content

Commit e8d2706

Browse files
committed
Merge branch 'master' of https://github.com/rust-lang/rust
2 parents 33113f8 + 8ad12c3 commit e8d2706

File tree

9 files changed

+561
-29
lines changed

9 files changed

+561
-29
lines changed

src/librustc_trans/trans/mir/block.rs

Lines changed: 64 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@
99
// except according to those terms.
1010

1111
use llvm::BasicBlockRef;
12+
use middle::infer;
13+
use middle::ty;
1214
use rustc::mir::repr as mir;
1315
use trans::adt;
1416
use trans::base;
1517
use trans::build;
16-
use trans::common::Block;
18+
use trans::common::{self, Block};
1719
use trans::debuginfo::DebugLoc;
20+
use trans::type_of;
1821

1922
use super::MirContext;
23+
use super::operand::OperandValue::{FatPtr, Immediate, Ref};
2024

2125
impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
2226
pub fn trans_block(&mut self, bb: mir::BasicBlock) {
@@ -101,29 +105,65 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
101105
base::build_return_block(bcx.fcx, bcx, return_ty, DebugLoc::None);
102106
}
103107

104-
mir::Terminator::Call { .. } => {
105-
unimplemented!()
106-
//let llbb = unimplemented!(); // self.make_landing_pad(panic_bb);
107-
//
108-
//let tr_dest = self.trans_lvalue(bcx, &data.destination);
109-
//
110-
//// Create the callee. This will always be a fn
111-
//// ptr and hence a kind of scalar.
112-
//let callee = self.trans_operand(bcx, &data.func);
113-
//
114-
//// Process the arguments.
115-
//
116-
//let args = unimplemented!();
117-
//
118-
//callee::trans_call_inner(bcx,
119-
// DebugLoc::None,
120-
// |bcx, _| Callee {
121-
// bcx: bcx,
122-
// data: CalleeData::Fn(callee.llval),
123-
// ty: callee.ty,
124-
// },
125-
// args,
126-
// Some(Dest::SaveIn(tr_dest.llval)));
108+
mir::Terminator::Call { ref data, targets } => {
109+
// The location we'll write the result of the call into.
110+
let call_dest = self.trans_lvalue(bcx, &data.destination);
111+
112+
// Create the callee. This will always be a fn
113+
// ptr and hence a kind of scalar.
114+
let callee = self.trans_operand(bcx, &data.func);
115+
let ret_ty = if let ty::TyBareFn(_, ref f) = callee.ty.sty {
116+
let sig = bcx.tcx().erase_late_bound_regions(&f.sig);
117+
let sig = infer::normalize_associated_type(bcx.tcx(), &sig);
118+
sig.output
119+
} else {
120+
panic!("trans_block: expected TyBareFn as callee");
121+
};
122+
123+
// The arguments we'll be passing
124+
let mut llargs = vec![];
125+
126+
// Does the fn use an outptr? If so, that's the first arg.
127+
if let ty::FnConverging(ret_ty) = ret_ty {
128+
if type_of::return_uses_outptr(bcx.ccx(), ret_ty) {
129+
llargs.push(call_dest.llval);
130+
}
131+
}
132+
133+
// Process the rest of the args.
134+
for arg in &data.args {
135+
let arg_op = self.trans_operand(bcx, arg);
136+
match arg_op.val {
137+
Ref(llval) | Immediate(llval) => llargs.push(llval),
138+
FatPtr(base, extra) => {
139+
// The two words in a fat ptr are passed separately
140+
llargs.push(base);
141+
llargs.push(extra);
142+
}
143+
}
144+
}
145+
146+
// FIXME: Handle panics
147+
//let panic_bb = self.llblock(targets.1);
148+
//self.make_landing_pad(panic_bb);
149+
150+
// Do the actual call.
151+
let (llret, b) = base::invoke(bcx,
152+
callee.immediate(),
153+
&llargs[..],
154+
callee.ty,
155+
DebugLoc::None);
156+
bcx = b;
157+
158+
// Copy the return value into the destination.
159+
if let ty::FnConverging(ret_ty) = ret_ty {
160+
if !type_of::return_uses_outptr(bcx.ccx(), ret_ty) &&
161+
!common::type_is_zero_size(bcx.ccx(), ret_ty) {
162+
base::store_ty(bcx, llret, call_dest.llval, ret_ty);
163+
}
164+
}
165+
166+
build::Br(bcx, self.llblock(targets.0), DebugLoc::None)
127167
}
128168
}
129169
}

src/libstd/ffi/c_str.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use io;
1919
use iter::Iterator;
2020
use libc;
2121
use mem;
22+
use memchr;
2223
use ops::Deref;
2324
use option::Option::{self, Some, None};
2425
use os::raw::c_char;
@@ -188,7 +189,7 @@ impl CString {
188189
}
189190

190191
fn _new(bytes: Vec<u8>) -> Result<CString, NulError> {
191-
match bytes.iter().position(|x| *x == 0) {
192+
match memchr::memchr(0, &bytes) {
192193
Some(i) => Err(NulError(i, bytes)),
193194
None => Ok(unsafe { CString::from_vec_unchecked(bytes) }),
194195
}

src/libstd/io/buffered.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use cmp;
1818
use error;
1919
use fmt;
2020
use io::{self, DEFAULT_BUF_SIZE, Error, ErrorKind, SeekFrom};
21+
use memchr;
2122

2223
/// The `BufReader` struct adds buffering to any reader.
2324
///
@@ -746,7 +747,7 @@ impl<W: Write> LineWriter<W> {
746747
#[stable(feature = "rust1", since = "1.0.0")]
747748
impl<W: Write> Write for LineWriter<W> {
748749
fn write(&mut self, buf: &[u8]) -> io::Result<usize> {
749-
match buf.iter().rposition(|b| *b == b'\n') {
750+
match memchr::memrchr(b'\n', buf) {
750751
Some(i) => {
751752
let n = try!(self.inner.write(&buf[..i + 1]));
752753
if n != i + 1 { return Ok(n) }

src/libstd/io/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ use result;
254254
use string::String;
255255
use str;
256256
use vec::Vec;
257+
use memchr;
257258

258259
#[stable(feature = "rust1", since = "1.0.0")]
259260
pub use self::buffered::{BufReader, BufWriter, LineWriter};
@@ -1194,7 +1195,7 @@ fn read_until<R: BufRead + ?Sized>(r: &mut R, delim: u8, buf: &mut Vec<u8>)
11941195
Err(ref e) if e.kind() == ErrorKind::Interrupted => continue,
11951196
Err(e) => return Err(e)
11961197
};
1197-
match available.iter().position(|x| *x == delim) {
1198+
match memchr::memchr(delim, available) {
11981199
Some(i) => {
11991200
buf.extend_from_slice(&available[..i + 1]);
12001201
(true, i + 1)

src/libstd/lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,7 @@
248248
#![feature(link_args)]
249249
#![feature(linkage)]
250250
#![feature(macro_reexport)]
251+
#![feature(num_bits_bytes)]
251252
#![feature(on_unimplemented)]
252253
#![feature(oom)]
253254
#![feature(optin_builtin_traits)]
@@ -429,6 +430,7 @@ pub mod path;
429430
pub mod process;
430431
pub mod sync;
431432
pub mod time;
433+
mod memchr;
432434

433435
#[macro_use]
434436
#[path = "sys/common/mod.rs"] mod sys_common;

0 commit comments

Comments
 (0)