Skip to content

Commit 63bffd7

Browse files
committed
---
yaml --- r: 282037 b: refs/heads/stable c: 3e98220 h: refs/heads/master i: 282035: ffdb1ec
1 parent 9723a58 commit 63bffd7

File tree

4 files changed

+107
-32
lines changed

4 files changed

+107
-32
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ refs/heads/tmp: e06d2ad9fcd5027bcaac5b08fc9aa39a49d0ecd3
2929
refs/tags/1.0.0-alpha.2: 4c705f6bc559886632d3871b04f58aab093bfa2f
3030
refs/tags/homu-tmp: 3c795e08d6f4a532f12f3f8e1837db5e0647f8b0
3131
refs/tags/1.0.0-beta: 8cbb92b53468ee2b0c2d3eeb8567005953d40828
32-
refs/heads/stable: ee7687a5e5063dd57e7c790523c2ffea1cf49c5e
32+
refs/heads/stable: 3e98220a1cc9059807961472a9132157cdf3c047
3333
refs/tags/1.0.0: 55bd4f8ff2b323f317ae89e254ce87162d52a375
3434
refs/tags/1.1.0: bc3c16f09287e5545c1d3f76b7abd54f2eca868b
3535
refs/tags/1.2.0: f557861f822c34f07270347b94b5280de20a597e

branches/stable/src/librustc_trans/trans/callee.rs

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use trans::build::*;
3636
use trans::cleanup;
3737
use trans::cleanup::CleanupMethods;
3838
use trans::closure;
39-
use trans::common::{self, Block, Result, NodeIdAndSpan, CrateContext, FunctionContext};
39+
use trans::common::{self, Block, Result, CrateContext, FunctionContext};
4040
use trans::common::{C_uint, C_undef};
4141
use trans::consts;
4242
use trans::datum::*;
@@ -56,7 +56,6 @@ use trans::Disr;
5656
use middle::ty::{self, Ty, TyCtxt, TypeFoldable};
5757
use rustc_front::hir;
5858

59-
use syntax::ast;
6059
use syntax::codemap::DUMMY_SP;
6160
use syntax::errors;
6261
use syntax::ptr::P;
@@ -624,18 +623,9 @@ fn trans_call_inner<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
624623
assert!(abi == Abi::RustIntrinsic || abi == Abi::PlatformIntrinsic);
625624
assert!(dest.is_some());
626625

627-
let call_info = match debug_loc {
628-
DebugLoc::At(id, span) => NodeIdAndSpan { id: id, span: span },
629-
DebugLoc::None => {
630-
bcx.sess().bug("No call info for intrinsic call?")
631-
}
632-
};
633-
634-
let arg_cleanup_scope = fcx.push_custom_cleanup_scope();
635626
return intrinsic::trans_intrinsic_call(bcx, callee.ty, &fn_ty,
636-
arg_cleanup_scope, args,
637-
dest.unwrap(),
638-
call_info);
627+
args, dest.unwrap(),
628+
debug_loc);
639629
}
640630
NamedTupleConstructor(disr) => {
641631
assert!(dest.is_some());

branches/stable/src/librustc_trans/trans/intrinsic.rs

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ use syntax::parse::token;
4747

4848
use rustc::lint;
4949
use rustc::session::Session;
50-
use syntax::codemap::Span;
50+
use syntax::codemap::{Span, DUMMY_SP};
5151

5252
use std::cmp::Ordering;
5353

@@ -173,10 +173,9 @@ pub fn check_intrinsics(ccx: &CrateContext) {
173173
pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
174174
callee_ty: Ty<'tcx>,
175175
fn_ty: &FnType,
176-
cleanup_scope: cleanup::CustomScopeIndex,
177176
args: callee::CallArgs<'a, 'tcx>,
178177
dest: expr::Dest,
179-
call_info: NodeIdAndSpan)
178+
call_debug_location: DebugLoc)
180179
-> Result<'blk, 'tcx> {
181180
let fcx = bcx.fcx;
182181
let ccx = fcx.ccx;
@@ -195,7 +194,12 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
195194
let ret_ty = sig.output;
196195
let name = tcx.item_name(def_id).as_str();
197196

198-
let call_debug_location = DebugLoc::At(call_info.id, call_info.span);
197+
let span = match call_debug_location {
198+
DebugLoc::At(_, span) => span,
199+
DebugLoc::None => fcx.span.unwrap_or(DUMMY_SP)
200+
};
201+
202+
let cleanup_scope = fcx.push_custom_cleanup_scope();
199203

200204
// For `transmute` we can just trans the input expr directly into dest
201205
if name == "transmute" {
@@ -644,7 +648,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
644648
},
645649
None => {
646650
span_invalid_monomorphization_error(
647-
tcx.sess, call_info.span,
651+
tcx.sess, span,
648652
&format!("invalid monomorphization of `{}` intrinsic: \
649653
expected basic integer type, found `{}`", name, sty));
650654
C_null(llret_ty)
@@ -656,7 +660,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
656660

657661
(_, "return_address") => {
658662
if !fcx.fn_ty.ret.is_indirect() {
659-
span_err!(tcx.sess, call_info.span, E0510,
663+
span_err!(tcx.sess, span, E0510,
660664
"invalid use of `return_address` intrinsic: function \
661665
does not use out pointer");
662666
C_null(Type::i8p(ccx))
@@ -684,7 +688,7 @@ pub fn trans_intrinsic_call<'a, 'blk, 'tcx>(mut bcx: Block<'blk, 'tcx>,
684688
&llargs,
685689
ret_ty, llret_ty,
686690
call_debug_location,
687-
call_info)
691+
span)
688692
}
689693
// This requires that atomic intrinsics follow a specific naming pattern:
690694
// "atomic_<operation>[_<ordering>]", and no ordering means SeqCst
@@ -1404,7 +1408,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
14041408
ret_ty: Ty<'tcx>,
14051409
llret_ty: Type,
14061410
call_debug_location: DebugLoc,
1407-
call_info: NodeIdAndSpan) -> ValueRef
1411+
span: Span) -> ValueRef
14081412
{
14091413
// macros for error handling:
14101414
macro_rules! emit_error {
@@ -1413,7 +1417,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
14131417
};
14141418
($msg: tt, $($fmt: tt)*) => {
14151419
span_invalid_monomorphization_error(
1416-
bcx.sess(), call_info.span,
1420+
bcx.sess(), span,
14171421
&format!(concat!("invalid monomorphization of `{}` intrinsic: ",
14181422
$msg),
14191423
name, $($fmt)*));
@@ -1482,7 +1486,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
14821486
if name.starts_with("simd_shuffle") {
14831487
let n: usize = match name["simd_shuffle".len()..].parse() {
14841488
Ok(n) => n,
1485-
Err(_) => tcx.sess.span_bug(call_info.span,
1489+
Err(_) => tcx.sess.span_bug(span,
14861490
"bad `simd_shuffle` instruction only caught in trans?")
14871491
};
14881492

@@ -1502,14 +1506,14 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
15021506

15031507
let vector = match args {
15041508
Some(args) => &args[2],
1505-
None => bcx.sess().span_bug(call_info.span,
1509+
None => bcx.sess().span_bug(span,
15061510
"intrinsic call with unexpected argument shape"),
15071511
};
15081512
let vector = match consts::const_expr(bcx.ccx(), vector, substs, None,
15091513
consts::TrueConst::Yes, // this should probably help simd error reporting
15101514
) {
15111515
Ok((vector, _)) => vector,
1512-
Err(err) => bcx.sess().span_fatal(call_info.span, &err.description()),
1516+
Err(err) => bcx.sess().span_fatal(span, &err.description()),
15131517
};
15141518

15151519
let indices: Option<Vec<_>> = (0..n)
@@ -1652,7 +1656,7 @@ fn generic_simd_intrinsic<'blk, 'tcx, 'a>
16521656
simd_or: TyUint, TyInt => Or;
16531657
simd_xor: TyUint, TyInt => Xor;
16541658
}
1655-
bcx.sess().span_bug(call_info.span, "unknown SIMD intrinsic");
1659+
bcx.sess().span_bug(span, "unknown SIMD intrinsic");
16561660
}
16571661

16581662
// Returns the width of an int TypeVariant, and if it's signed or not

branches/stable/src/librustc_trans/trans/mir/block.rs

Lines changed: 86 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,18 +15,19 @@ use trans::abi::{Abi, FnType};
1515
use trans::adt;
1616
use trans::base;
1717
use trans::build;
18-
use trans::callee::{Callee, CalleeData, Fn, Virtual};
18+
use trans::callee::{Callee, CalleeData, Fn, Intrinsic, NamedTupleConstructor, Virtual};
1919
use trans::common::{self, Block, BlockAndBuilder, C_undef};
2020
use trans::debuginfo::DebugLoc;
2121
use trans::Disr;
22-
use trans::machine::llalign_of_min;
22+
use trans::machine::{llalign_of_min, llbitsize_of_real};
2323
use trans::meth;
2424
use trans::type_of;
2525
use trans::glue;
2626
use trans::type_::Type;
2727

2828
use super::{MirContext, drop};
2929
use super::lvalue::LvalueRef;
30+
use super::operand::OperandRef;
3031
use super::operand::OperandValue::{self, FatPtr, Immediate, Ref};
3132

3233
impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
@@ -168,8 +169,51 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
168169
_ => unreachable!("{} is not callable", callee.ty)
169170
};
170171

171-
// We do not translate intrinsics here (they shouldn’t be functions)
172-
assert!(abi != Abi::RustIntrinsic && abi != Abi::PlatformIntrinsic);
172+
// Handle intrinsics old trans wants Expr's for, ourselves.
173+
let intrinsic = match (&callee.ty.sty, &callee.data) {
174+
(&ty::TyFnDef(def_id, _, _), &Intrinsic) => {
175+
Some(bcx.tcx().item_name(def_id).as_str())
176+
}
177+
_ => None
178+
};
179+
let intrinsic = intrinsic.as_ref().map(|s| &s[..]);
180+
181+
if intrinsic == Some("move_val_init") {
182+
let &(_, target) = destination.as_ref().unwrap();
183+
// The first argument is a thin destination pointer.
184+
let llptr = self.trans_operand(&bcx, &args[0]).immediate();
185+
let val = self.trans_operand(&bcx, &args[1]);
186+
self.store_operand(&bcx, llptr, val);
187+
self.set_operand_dropped(&bcx, &args[1]);
188+
funclet_br(bcx, self.llblock(target));
189+
return;
190+
}
191+
192+
if intrinsic == Some("transmute") {
193+
let &(ref dest, target) = destination.as_ref().unwrap();
194+
let dst = self.trans_lvalue(&bcx, dest);
195+
let mut val = self.trans_operand(&bcx, &args[0]);
196+
if let ty::TyFnDef(def_id, substs, _) = val.ty.sty {
197+
let llouttype = type_of::type_of(bcx.ccx(), dst.ty.to_ty(bcx.tcx()));
198+
let out_type_size = llbitsize_of_real(bcx.ccx(), llouttype);
199+
if out_type_size != 0 {
200+
// FIXME #19925 Remove this hack after a release cycle.
201+
let f = Callee::def(bcx.ccx(), def_id, substs);
202+
let datum = f.reify(bcx.ccx());
203+
val = OperandRef {
204+
val: OperandValue::Immediate(datum.val),
205+
ty: datum.ty
206+
};
207+
}
208+
}
209+
210+
let llty = type_of::type_of(bcx.ccx(), val.ty);
211+
let cast_ptr = bcx.pointercast(dst.llval, llty.ptr_to());
212+
self.store_operand(&bcx, cast_ptr, val);
213+
self.set_operand_dropped(&bcx, &args[0]);
214+
funclet_br(bcx, self.llblock(target));
215+
return;
216+
}
173217

174218
let extra_args = &args[sig.0.inputs.len()..];
175219
let extra_args = extra_args.iter().map(|op_arg| {
@@ -215,7 +259,44 @@ impl<'bcx, 'tcx> MirContext<'bcx, 'tcx> {
215259
&mut idx, &mut callee.data)
216260
}
217261

218-
let fn_ptr = callee.reify(bcx.ccx()).val;
262+
let fn_ptr = match callee.data {
263+
NamedTupleConstructor(_) => {
264+
// FIXME translate this like mir::Rvalue::Aggregate.
265+
callee.reify(bcx.ccx()).val
266+
}
267+
Intrinsic => {
268+
use trans::callee::ArgVals;
269+
use trans::expr::{Ignore, SaveIn};
270+
use trans::intrinsic::trans_intrinsic_call;
271+
272+
let (dest, llargs) = if fn_ty.ret.is_indirect() {
273+
(SaveIn(llargs[0]), &llargs[1..])
274+
} else if let Some(dest) = ret_dest {
275+
(SaveIn(dest.llval), &llargs[..])
276+
} else {
277+
(Ignore, &llargs[..])
278+
};
279+
280+
bcx.with_block(|bcx| {
281+
let res = trans_intrinsic_call(bcx, callee.ty, &fn_ty,
282+
ArgVals(llargs), dest,
283+
DebugLoc::None);
284+
let bcx = res.bcx.build();
285+
if let Some((_, target)) = *destination {
286+
for op in args {
287+
self.set_operand_dropped(&bcx, op);
288+
}
289+
funclet_br(bcx, self.llblock(target));
290+
} else {
291+
// trans_intrinsic_call already used Unreachable.
292+
// bcx.unreachable();
293+
}
294+
});
295+
return;
296+
}
297+
Fn(f) => f,
298+
Virtual(_) => unreachable!("Virtual fn ptr not extracted")
299+
};
219300

220301
// Many different ways to call a function handled here
221302
if let Some(cleanup) = cleanup.map(|bb| self.bcx(bb)) {

0 commit comments

Comments
 (0)