]> git.lizzy.rs Git - rust.git/blobdiff - src/librustc_mir/interpret/intrinsics.rs
Return Ok(false) instead of throwing when handling a diverging intrinsic
[rust.git] / src / librustc_mir / interpret / intrinsics.rs
index 04032847385e9aaaceba08fe18f0dbb169f6aa2e..66b6d4ac12c402c38381c942a3d39df43ef52f30 100644 (file)
@@ -91,14 +91,21 @@ pub fn emulate_intrinsic(
         span: Span,
         instance: ty::Instance<'tcx>,
         args: &[OpTy<'tcx, M::PointerTag>],
-        dest: PlaceTy<'tcx, M::PointerTag>,
+        dest: Option<PlaceTy<'tcx, M::PointerTag>>,
     ) -> InterpResult<'tcx, bool> {
         let substs = instance.substs;
 
-        let intrinsic_name = &self.tcx.item_name(instance.def_id()).as_str()[..];
+        // We currently do not handle any diverging intrinsics.
+        let dest = match dest {
+            Some(dest) => dest,
+            None => return Ok(false)
+        };
+        let intrinsic_name = &*self.tcx.item_name(instance.def_id()).as_str();
+
         match intrinsic_name {
             "caller_location" => {
-                let caller = self.tcx.sess.source_map().lookup_char_pos(span.lo());
+                let topmost = span.ctxt().outer_expn().expansion_cause().unwrap_or(span);
+                let caller = self.tcx.sess.source_map().lookup_char_pos(topmost.lo());
                 let location = self.alloc_caller_location(
                     Symbol::intern(&caller.file.name.to_string()),
                     caller.line as u32,
@@ -262,8 +269,8 @@ pub fn emulate_intrinsic(
                 // This is the dual to the special exception for offset-by-0
                 // in the inbounds pointer offset operation (see the Miri code, `src/operator.rs`).
                 if a.is_bits() && b.is_bits() {
-                    let a = a.to_usize(self)?;
-                    let b = b.to_usize(self)?;
+                    let a = a.to_machine_usize(self)?;
+                    let b = b.to_machine_usize(self)?;
                     if a == b && a != 0 {
                         self.write_scalar(Scalar::from_int(0, isize_layout.size), dest)?;
                         return Ok(true);
@@ -346,9 +353,10 @@ pub fn emulate_intrinsic(
         Ok(true)
     }
 
-    /// "Intercept" a function call because we have something special to do for it.
+    /// "Intercept" a function call to a panic-related function
+    /// because we have something special to do for it.
     /// Returns `true` if an intercept happened.
-    pub fn hook_fn(
+    pub fn hook_panic_fn(
         &mut self,
         instance: ty::Instance<'tcx>,
         args: &[OpTy<'tcx, M::PointerTag>],