]> git.lizzy.rs Git - rust.git/commitdiff
Rustup to rustc 1.40.0-nightly (9e346646e 2019-11-08)
authorbjorn3 <bjorn3@users.noreply.github.com>
Sat, 9 Nov 2019 10:14:18 +0000 (11:14 +0100)
committerbjorn3 <bjorn3@users.noreply.github.com>
Sat, 9 Nov 2019 10:14:18 +0000 (11:14 +0100)
example/std_example.rs
src/abi/mod.rs
src/base.rs
src/common.rs
src/constant.rs
src/intrinsics.rs

index 71b2a34b61d56051366c5f3e2c0c93fa7955efc6..50f794733e32700d8bfadc0e8f6fa3d08e1a955e 100644 (file)
@@ -71,6 +71,8 @@ fn main() {
 
     let _a = 1u32 << 2u8;
 
+    println!("{:?}", unsafe { std::intrinsics::caller_location() });
+
     unsafe {
         test_simd();
     }
index dcd9a6ab932df5546114ba9b664581263866ada1..881174646afe7bbd32c025ec650debee2fd020b8 100644 (file)
@@ -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) => {
index ef32dafb2efc5adfc73f1246ac65d5077757ea9a..007ff5390de5d0a64d1bbce41aca53d52ae6aa37 100644 (file)
@@ -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.");
index c3563dc0533f9e11deaaf1b8495c70b81cdf403d..838c8d3315bfcb9b51c057ce7581814ef6ccd77b 100644 (file)
@@ -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 @@ pub fn set_debug_loc(&mut self, source_info: mir::SourceInfo) {
         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)
+    }
 }
index 3cf0e05e4462682a18fa6efb7e80f13e22fca541..d366cf4bf88ceec7f19eb62cc69dc7264d9d76ee 100644 (file)
@@ -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)
             }
index 0910b878890cb569194238f104047080ab265e3f..211c8a2443d4ac88a5e00d847df980e3f959ab54 100644 (file)
@@ -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 @@ fn swap(bcx: &mut FunctionBuilder, v: Value) -> Value {
             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) {