about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbjorn3 <bjorn3@users.noreply.github.com>2019-11-09 11:14:18 +0100
committerbjorn3 <bjorn3@users.noreply.github.com>2019-11-09 11:14:18 +0100
commit5407b51aa71f13b2d0deabd873c0a828cb8cd28f (patch)
treec1bf69b8f5cb541878cf2ac28080493b0bf9e98d
parent74ea53f1fbac83ee44addc6a3c08d152344aa356 (diff)
downloadrust-5407b51aa71f13b2d0deabd873c0a828cb8cd28f.tar.gz
rust-5407b51aa71f13b2d0deabd873c0a828cb8cd28f.zip
Rustup to rustc 1.40.0-nightly (9e346646e 2019-11-08)
-rw-r--r--example/std_example.rs2
-rw-r--r--src/abi/mod.rs3
-rw-r--r--src/base.rs8
-rw-r--r--src/common.rs19
-rw-r--r--src/constant.rs4
-rw-r--r--src/intrinsics.rs16
6 files changed, 43 insertions, 9 deletions
diff --git a/example/std_example.rs b/example/std_example.rs
index 71b2a34b61d..50f794733e3 100644
--- a/example/std_example.rs
+++ b/example/std_example.rs
@@ -71,6 +71,8 @@ fn main() {
 
     let _a = 1u32 << 2u8;
 
+    println!("{:?}", unsafe { std::intrinsics::caller_location() });
+
     unsafe {
         test_simd();
     }
diff --git a/src/abi/mod.rs b/src/abi/mod.rs
index dcd9a6ab932..881174646af 100644
--- a/src/abi/mod.rs
+++ b/src/abi/mod.rs
@@ -351,6 +351,7 @@ pub fn codegen_terminator_call<'tcx>(
     func: &Operand<'tcx>,
     args: &[Operand<'tcx>],
     destination: &Option<(Place<'tcx>, BasicBlock)>,
+    span: Span,
 ) {
     let fn_ty = fx.monomorphize(&func.ty(fx.mir, fx.tcx));
     let sig = fx
@@ -378,7 +379,7 @@ pub fn codegen_terminator_call<'tcx>(
 
         match instance.def {
             InstanceDef::Intrinsic(_) => {
-                crate::intrinsics::codegen_intrinsic_call(fx, instance, args, destination);
+                crate::intrinsics::codegen_intrinsic_call(fx, instance, args, destination, span);
                 return;
             }
             InstanceDef::DropGlue(_, None) => {
diff --git a/src/base.rs b/src/base.rs
index ef32dafb2ef..007ff5390de 100644
--- a/src/base.rs
+++ b/src/base.rs
@@ -208,7 +208,13 @@ fn codegen_fn_content(fx: &mut FunctionCx<'_, '_, impl Backend>) {
                 cleanup: _,
                 from_hir_call: _,
             } => {
-                crate::abi::codegen_terminator_call(fx, func, args, destination);
+                crate::abi::codegen_terminator_call(
+                    fx,
+                    func,
+                    args,
+                    destination,
+                    bb_data.terminator().source_info.span,
+                );
             }
             TerminatorKind::Resume | TerminatorKind::Abort => {
                 trap_unreachable(fx, "[corruption] Unwinding bb reached.");
diff --git a/src/common.rs b/src/common.rs
index c3563dc0533..838c8d3315b 100644
--- a/src/common.rs
+++ b/src/common.rs
@@ -1,4 +1,4 @@
-use rustc::ty::layout::{FloatTy, Integer, Primitive};
+use rustc::ty::layout::{Integer, Primitive};
 use rustc_target::spec::{HasTargetSpec, Target};
 
 use cranelift::codegen::ir::{InstructionData, Opcode, ValueDef};
@@ -27,10 +27,8 @@ pub fn scalar_to_clif_type(tcx: TyCtxt, scalar: Scalar) -> Type {
             Integer::I64 => types::I64,
             Integer::I128 => types::I128,
         },
-        Primitive::Float(flt) => match flt {
-            FloatTy::F32 => types::F32,
-            FloatTy::F64 => types::F64,
-        },
+        Primitive::F32 => types::F32,
+        Primitive::F64 => types::F64,
         Primitive::Pointer => pointer_ty(tcx),
     }
 }
@@ -370,4 +368,15 @@ impl<'tcx, B: Backend + 'static> FunctionCx<'_, 'tcx, B> {
         let (index, _) = self.source_info_set.insert_full((source_info.span, source_info.scope));
         self.bcx.set_srcloc(SourceLoc::new(index as u32));
     }
+
+    pub fn get_caller_location(&mut self, span: Span) -> CValue<'tcx> {
+        let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
+        let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
+        let const_loc = self.tcx.const_caller_location((
+            syntax::symbol::Symbol::intern(&caller.file.name.to_string()),
+            caller.line as u32,
+            caller.col_display as u32 + 1,
+        ));
+        crate::constant::trans_const_value(self, const_loc)
+    }
 }
diff --git a/src/constant.rs b/src/constant.rs
index 3cf0e05e446..d366cf4bf88 100644
--- a/src/constant.rs
+++ b/src/constant.rs
@@ -172,7 +172,7 @@ fn trans_const_place<'tcx>(
         ecx.copy_op(op, ptr.into())?;
         let alloc = ecx
             .memory
-            .get(ptr.to_ref().to_scalar()?.to_ptr()?.alloc_id)?;
+            .get_raw(ptr.to_ref().to_scalar()?.to_ptr()?.alloc_id)?;
         Ok(fx.tcx.intern_const_alloc(alloc.clone()))
     };
     let alloc = result().expect("unable to convert ConstValue to Allocation");
@@ -274,7 +274,7 @@ fn define_all_allocs(tcx: TyCtxt<'_>, module: &mut Module<impl Backend>, cx: &mu
         let (data_id, alloc) = match todo_item {
             TodoItem::Alloc(alloc_id) => {
                 //println!("alloc_id {}", alloc_id);
-                let alloc = memory.get(alloc_id).unwrap();
+                let alloc = memory.get_raw(alloc_id).unwrap();
                 let data_id = data_id_for_alloc_id(module, alloc_id, alloc.align);
                 (data_id, alloc)
             }
diff --git a/src/intrinsics.rs b/src/intrinsics.rs
index 0910b878890..211c8a2443d 100644
--- a/src/intrinsics.rs
+++ b/src/intrinsics.rs
@@ -338,6 +338,7 @@ pub fn codegen_intrinsic_call<'tcx>(
     instance: Instance<'tcx>,
     args: &[mir::Operand<'tcx>],
     destination: Option<(CPlace<'tcx>, BasicBlock)>,
+    span: Span,
 ) {
     let def_id = instance.def_id();
     let substs = instance.substs;
@@ -834,6 +835,21 @@ pub fn codegen_intrinsic_call<'tcx>(
             ret.write_cvalue(fx, val);
         };
 
+        ptr_offset_from, <T> (v ptr, v base) {
+            let isize_layout = fx.layout_of(fx.tcx.types.isize);
+
+            let pointee_size: u64 = fx.layout_of(T).size.bytes();
+            let diff = fx.bcx.ins().isub(ptr, base);
+            // FIXME this can be an exact division.
+            let val = CValue::by_val(fx.bcx.ins().udiv_imm(diff, pointee_size as i64), isize_layout);
+            ret.write_cvalue(fx, val);
+        };
+
+        caller_location, () {
+            let caller_location = fx.get_caller_location(span);
+            ret.write_cvalue(fx, caller_location);
+        };
+
         _ if intrinsic.starts_with("atomic_fence"), () {};
         _ if intrinsic.starts_with("atomic_singlethreadfence"), () {};
         _ if intrinsic.starts_with("atomic_load"), (c ptr) {