]> git.lizzy.rs Git - rust.git/blob - src/lib.rs
6b1ada69d3975dfc38e9e8e8e6acd833a1699f55
[rust.git] / src / lib.rs
1 #![feature(rustc_private)]
2
3 #![allow(clippy::cast_lossless)]
4
5 #[macro_use]
6 extern crate log;
7 // From rustc.
8 extern crate syntax;
9 extern crate rustc_apfloat;
10 #[macro_use] extern crate rustc;
11 extern crate rustc_data_structures;
12 extern crate rustc_mir;
13 extern crate rustc_target;
14
15 mod fn_call;
16 mod operator;
17 mod intrinsic;
18 mod helpers;
19 mod tls;
20 mod range_map;
21 mod mono_hash_map;
22 mod stacked_borrows;
23 mod intptrcast;
24 mod memory;
25
26 use std::collections::HashMap;
27 use std::borrow::Cow;
28 use std::rc::Rc;
29
30 use rand::rngs::StdRng;
31 use rand::SeedableRng;
32
33 use rustc::ty::{self, TyCtxt, query::TyCtxtAt};
34 use rustc::ty::layout::{LayoutOf, Size, Align};
35 use rustc::hir::def_id::DefId;
36 use rustc::mir;
37 pub use rustc_mir::interpret::*;
38 // Resolve ambiguity.
39 pub use rustc_mir::interpret::{self, AllocMap, PlaceTy};
40 use syntax::attr;
41 use syntax::source_map::DUMMY_SP;
42 use syntax::symbol::sym;
43
44 pub use crate::fn_call::EvalContextExt as MissingFnsEvalContextExt;
45 pub use crate::operator::EvalContextExt as OperatorEvalContextExt;
46 pub use crate::intrinsic::EvalContextExt as IntrinsicEvalContextExt;
47 pub use crate::tls::{EvalContextExt as TlsEvalContextExt, TlsData};
48 use crate::range_map::RangeMap;
49 #[allow(unused_imports)] // FIXME: rustc bug, issue <https://github.com/rust-lang/rust/issues/53682>.
50 pub use crate::helpers::{EvalContextExt as HelpersEvalContextExt};
51 use crate::mono_hash_map::MonoHashMap;
52 pub use crate::stacked_borrows::{EvalContextExt as StackedBorEvalContextExt};
53 use crate::memory::AllocExtra;
54
55 // Used by priroda.
56 pub use crate::stacked_borrows::{Tag, Permission, Stack, Stacks, Item};
57
58 /// Insert rustc arguments at the beginning of the argument list that Miri wants to be
59 /// set per default, for maximal validation power.
60 pub fn miri_default_args() -> &'static [&'static str] {
61     // The flags here should be kept in sync with what bootstrap adds when `test-miri` is
62     // set, which happens in `bootstrap/bin/rustc.rs` in the rustc sources.
63     &["-Zalways-encode-mir", "-Zmir-emit-retag", "-Zmir-opt-level=0", "--cfg=miri"]
64 }
65
66 /// Configuration needed to spawn a Miri instance.
67 #[derive(Clone)]
68 pub struct MiriConfig {
69     pub validate: bool,
70     pub args: Vec<String>,
71
72     // The seed to use when non-determinism is required (e.g. getrandom())
73     pub seed: Option<u64>
74 }
75
76 // Used by priroda.
77 pub fn create_ecx<'mir, 'tcx: 'mir>(
78     tcx: TyCtxt<'tcx>,
79     main_id: DefId,
80     config: MiriConfig,
81 ) -> InterpResult<'tcx, InterpretCx<'mir, 'tcx, Evaluator<'tcx>>> {
82     let mut ecx = InterpretCx::new(
83         tcx.at(syntax::source_map::DUMMY_SP),
84         ty::ParamEnv::reveal_all(),
85         Evaluator::new(config.validate),
86     );
87
88     // FIXME: InterpretCx::new should take an initial MemoryExtra
89     ecx.memory_mut().extra.rng = config.seed.map(StdRng::seed_from_u64);
90     
91     let main_instance = ty::Instance::mono(ecx.tcx.tcx, main_id);
92     let main_mir = ecx.load_mir(main_instance.def)?;
93
94     if !main_mir.return_ty().is_unit() || main_mir.arg_count != 0 {
95         return err!(Unimplemented(
96             "miri does not support main functions without `fn()` type signatures"
97                 .to_owned(),
98         ));
99     }
100
101     let start_id = tcx.lang_items().start_fn().unwrap();
102     let main_ret_ty = tcx.fn_sig(main_id).output();
103     let main_ret_ty = main_ret_ty.no_bound_vars().unwrap();
104     let start_instance = ty::Instance::resolve(
105         ecx.tcx.tcx,
106         ty::ParamEnv::reveal_all(),
107         start_id,
108         ecx.tcx.mk_substs(
109             ::std::iter::once(ty::subst::Kind::from(main_ret_ty)))
110         ).unwrap();
111     let start_mir = ecx.load_mir(start_instance.def)?;
112
113     if start_mir.arg_count != 3 {
114         return err!(AbiViolation(format!(
115             "'start' lang item should have three arguments, but has {}",
116             start_mir.arg_count
117         )));
118     }
119
120     // Return value (in static memory so that it does not count as leak).
121     let ret = ecx.layout_of(start_mir.return_ty())?;
122     let ret_ptr = ecx.allocate(ret, MiriMemoryKind::Static.into());
123
124     // Push our stack frame.
125     ecx.push_stack_frame(
126         start_instance,
127         // There is no call site.
128         DUMMY_SP,
129         start_mir,
130         Some(ret_ptr.into()),
131         StackPopCleanup::None { cleanup: true },
132     )?;
133
134     let mut args = ecx.frame().body.args_iter();
135
136     // First argument: pointer to `main()`.
137     let main_ptr = ecx.memory_mut().create_fn_alloc(main_instance);
138     let dest = ecx.eval_place(&mir::Place::Base(mir::PlaceBase::Local(args.next().unwrap())))?;
139     ecx.write_scalar(Scalar::Ptr(main_ptr), dest)?;
140
141     // Second argument (argc): `1`.
142     let dest = ecx.eval_place(&mir::Place::Base(mir::PlaceBase::Local(args.next().unwrap())))?;
143     let argc = Scalar::from_uint(config.args.len() as u128, dest.layout.size);
144     ecx.write_scalar(argc, dest)?;
145     // Store argc for macOS's `_NSGetArgc`.
146     {
147         let argc_place = ecx.allocate(dest.layout, MiriMemoryKind::Env.into());
148         ecx.write_scalar(argc, argc_place.into())?;
149         ecx.machine.argc = Some(argc_place.ptr.to_ptr()?);
150     }
151
152     // FIXME: extract main source file path.
153     // Third argument (`argv`): created from `config.args`.
154     let dest = ecx.eval_place(&mir::Place::Base(mir::PlaceBase::Local(args.next().unwrap())))?;
155     // For Windows, construct a command string with all the aguments.
156     let mut cmd = String::new();
157     for arg in config.args.iter() {
158         if !cmd.is_empty() {
159             cmd.push(' ');
160         }
161         cmd.push_str(&*shell_escape::windows::escape(arg.as_str().into()));
162     }
163     // Don't forget `0` terminator.
164     cmd.push(std::char::from_u32(0).unwrap());
165     // Collect the pointers to the individual strings.
166     let mut argvs = Vec::<Pointer<Tag>>::new();
167     for arg in config.args {
168         // Add `0` terminator.
169         let mut arg = arg.into_bytes();
170         arg.push(0);
171         argvs.push(ecx.memory_mut().allocate_static_bytes(arg.as_slice(), MiriMemoryKind::Static.into()));
172     }
173     // Make an array with all these pointers, in the Miri memory.
174     let argvs_layout = ecx.layout_of(ecx.tcx.mk_array(ecx.tcx.mk_imm_ptr(ecx.tcx.types.u8), argvs.len() as u64))?;
175     let argvs_place = ecx.allocate(argvs_layout, MiriMemoryKind::Env.into());
176     for (idx, arg) in argvs.into_iter().enumerate() {
177         let place = ecx.mplace_field(argvs_place, idx as u64)?;
178         ecx.write_scalar(Scalar::Ptr(arg), place.into())?;
179     }
180     ecx.memory_mut().mark_immutable(argvs_place.to_ptr()?.alloc_id)?;
181     // Write a pointer to that place as the argument.
182     let argv = argvs_place.ptr;
183     ecx.write_scalar(argv, dest)?;
184     // Store `argv` for macOS `_NSGetArgv`.
185     {
186         let argv_place = ecx.allocate(dest.layout, MiriMemoryKind::Env.into());
187         ecx.write_scalar(argv, argv_place.into())?;
188         ecx.machine.argv = Some(argv_place.ptr.to_ptr()?);
189     }
190     // Store command line as UTF-16 for Windows `GetCommandLineW`.
191     {
192         let tcx = &{ecx.tcx.tcx};
193         let cmd_utf16: Vec<u16> = cmd.encode_utf16().collect();
194         let cmd_ptr = ecx.memory_mut().allocate(
195             Size::from_bytes(cmd_utf16.len() as u64 * 2),
196             Align::from_bytes(2).unwrap(),
197             MiriMemoryKind::Env.into(),
198         );
199         ecx.machine.cmd_line = Some(cmd_ptr);
200         // Store the UTF-16 string.
201         let char_size = Size::from_bytes(2);
202         let cmd_alloc = ecx.memory_mut().get_mut(cmd_ptr.alloc_id)?;
203         let mut cur_ptr = cmd_ptr;
204         for &c in cmd_utf16.iter() {
205             cmd_alloc.write_scalar(
206                 tcx,
207                 cur_ptr,
208                 Scalar::from_uint(c, char_size).into(),
209                 char_size,
210             )?;
211             cur_ptr = cur_ptr.offset(char_size, tcx)?;
212         }
213     }
214  
215     assert!(args.next().is_none(), "start lang item has more arguments than expected");
216
217     Ok(ecx)
218 }
219
220 pub fn eval_main<'tcx>(
221     tcx: TyCtxt<'tcx>,
222     main_id: DefId,
223     config: MiriConfig,
224 ) {
225     let mut ecx = match create_ecx(tcx, main_id, config) {
226         Ok(ecx) => ecx,
227         Err(mut err) => {
228             err.print_backtrace();
229             panic!("Miri initialziation error: {}", err.kind)
230         }
231     };
232
233     // Perform the main execution.
234     let res: InterpResult = (|| {
235         ecx.run()?;
236         ecx.run_tls_dtors()
237     })();
238
239     // Process the result.
240     match res {
241         Ok(()) => {
242             let leaks = ecx.memory().leak_report();
243             // Disable the leak test on some platforms where we do not
244             // correctly implement TLS destructors.
245             let target_os = ecx.tcx.tcx.sess.target.target.target_os.to_lowercase();
246             let ignore_leaks = target_os == "windows" || target_os == "macos";
247             if !ignore_leaks && leaks != 0 {
248                 tcx.sess.err("the evaluated program leaked memory");
249             }
250         }
251         Err(mut e) => {
252             // Special treatment for some error kinds
253             let msg = match e.kind {
254                 InterpError::Exit(code) => std::process::exit(code),
255                 InterpError::NoMirFor(..) =>
256                     format!("{}. Did you set `MIRI_SYSROOT` to a Miri-enabled sysroot? You can prepare one with `cargo miri setup`.", e),
257                 _ => e.to_string()
258             };
259             e.print_backtrace();
260             if let Some(frame) = ecx.stack().last() {
261                 let block = &frame.body.basic_blocks()[frame.block];
262                 let span = if frame.stmt < block.statements.len() {
263                     block.statements[frame.stmt].source_info.span
264                 } else {
265                     block.terminator().source_info.span
266                 };
267
268                 let msg = format!("Miri evaluation error: {}", msg);
269                 let mut err = struct_error(ecx.tcx.tcx.at(span), msg.as_str());
270                 let frames = ecx.generate_stacktrace(None);
271                 err.span_label(span, msg);
272                 // We iterate with indices because we need to look at the next frame (the caller).
273                 for idx in 0..frames.len() {
274                     let frame_info = &frames[idx];
275                     let call_site_is_local = frames.get(idx+1).map_or(false,
276                         |caller_info| caller_info.instance.def_id().is_local());
277                     if call_site_is_local {
278                         err.span_note(frame_info.call_site, &frame_info.to_string());
279                     } else {
280                         err.note(&frame_info.to_string());
281                     }
282                 }
283                 err.emit();
284             } else {
285                 ecx.tcx.sess.err(&msg);
286             }
287
288             for (i, frame) in ecx.stack().iter().enumerate() {
289                 trace!("-------------------");
290                 trace!("Frame {}", i);
291                 trace!("    return: {:?}", frame.return_place.map(|p| *p));
292                 for (i, local) in frame.locals.iter().enumerate() {
293                     trace!("    local {}: {:?}", i, local.value);
294                 }
295             }
296         }
297     }
298 }
299
300 #[derive(Debug, Copy, Clone, PartialEq, Eq)]
301 pub enum MiriMemoryKind {
302     /// `__rust_alloc` memory.
303     Rust,
304     /// `malloc` memory.
305     C,
306     /// Part of env var emulation.
307     Env,
308     /// Statics.
309     Static,
310 }
311
312 impl Into<MemoryKind<MiriMemoryKind>> for MiriMemoryKind {
313     #[inline(always)]
314     fn into(self) -> MemoryKind<MiriMemoryKind> {
315         MemoryKind::Machine(self)
316     }
317 }
318
319 impl MayLeak for MiriMemoryKind {
320     #[inline(always)]
321     fn may_leak(self) -> bool {
322         use self::MiriMemoryKind::*;
323         match self {
324             Rust | C => false,
325             Env | Static => true,
326         }
327     }
328 }
329
330 pub struct Evaluator<'tcx> {
331     /// Environment variables set by `setenv`.
332     /// Miri does not expose env vars from the host to the emulated program.
333     pub(crate) env_vars: HashMap<Vec<u8>, Pointer<Tag>>,
334
335     /// Program arguments (`Option` because we can only initialize them after creating the ecx).
336     /// These are *pointers* to argc/argv because macOS.
337     /// We also need the full command line as one string because of Windows.
338     pub(crate) argc: Option<Pointer<Tag>>,
339     pub(crate) argv: Option<Pointer<Tag>>,
340     pub(crate) cmd_line: Option<Pointer<Tag>>,
341
342     /// Last OS error.
343     pub(crate) last_error: u32,
344
345     /// TLS state.
346     pub(crate) tls: TlsData<'tcx>,
347
348     /// Whether to enforce the validity invariant.
349     pub(crate) validate: bool,
350 }
351
352 impl<'tcx> Evaluator<'tcx> {
353     fn new(validate: bool) -> Self {
354         Evaluator {
355             env_vars: HashMap::default(),
356             argc: None,
357             argv: None,
358             cmd_line: None,
359             last_error: 0,
360             tls: TlsData::default(),
361             validate,
362         }
363     }
364 }
365
366 // FIXME: rustc issue <https://github.com/rust-lang/rust/issues/47131>.
367 #[allow(dead_code)]
368 type MiriEvalContext<'mir, 'tcx> = InterpretCx<'mir, 'tcx, Evaluator<'tcx>>;
369
370 // A little trait that's useful to be inherited by extension traits.
371 pub trait MiriEvalContextExt<'mir, 'tcx> {
372     fn eval_context_ref(&self) -> &MiriEvalContext<'mir, 'tcx>;
373     fn eval_context_mut(&mut self) -> &mut MiriEvalContext<'mir, 'tcx>;
374 }
375 impl<'mir, 'tcx> MiriEvalContextExt<'mir, 'tcx> for MiriEvalContext<'mir, 'tcx> {
376     #[inline(always)]
377     fn eval_context_ref(&self) -> &MiriEvalContext<'mir, 'tcx> {
378         self
379     }
380     #[inline(always)]
381     fn eval_context_mut(&mut self) -> &mut MiriEvalContext<'mir, 'tcx> {
382         self
383     }
384 }
385
386 impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
387     type MemoryKinds = MiriMemoryKind;
388
389     type FrameExtra = stacked_borrows::CallId;
390     type MemoryExtra = memory::MemoryExtra;
391     type AllocExtra = memory::AllocExtra;
392     type PointerTag = Tag;
393
394     type MemoryMap = MonoHashMap<AllocId, (MemoryKind<MiriMemoryKind>, Allocation<Tag, Self::AllocExtra>)>;
395
396     const STATIC_KIND: Option<MiriMemoryKind> = Some(MiriMemoryKind::Static);
397
398     #[inline(always)]
399     fn enforce_validity(ecx: &InterpretCx<'mir, 'tcx, Self>) -> bool {
400         ecx.machine.validate
401     }
402
403     /// Returns `Ok()` when the function was handled; fail otherwise.
404     #[inline(always)]
405     fn find_fn(
406         ecx: &mut InterpretCx<'mir, 'tcx, Self>,
407         instance: ty::Instance<'tcx>,
408         args: &[OpTy<'tcx, Tag>],
409         dest: Option<PlaceTy<'tcx, Tag>>,
410         ret: Option<mir::BasicBlock>,
411     ) -> InterpResult<'tcx, Option<&'mir mir::Body<'tcx>>> {
412         ecx.find_fn(instance, args, dest, ret)
413     }
414
415     #[inline(always)]
416     fn call_intrinsic(
417         ecx: &mut rustc_mir::interpret::InterpretCx<'mir, 'tcx, Self>,
418         instance: ty::Instance<'tcx>,
419         args: &[OpTy<'tcx, Tag>],
420         dest: PlaceTy<'tcx, Tag>,
421     ) -> InterpResult<'tcx> {
422         ecx.call_intrinsic(instance, args, dest)
423     }
424
425     #[inline(always)]
426     fn ptr_op(
427         ecx: &rustc_mir::interpret::InterpretCx<'mir, 'tcx, Self>,
428         bin_op: mir::BinOp,
429         left: ImmTy<'tcx, Tag>,
430         right: ImmTy<'tcx, Tag>,
431     ) -> InterpResult<'tcx, (Scalar<Tag>, bool)> {
432         ecx.ptr_op(bin_op, left, right)
433     }
434
435     fn box_alloc(
436         ecx: &mut InterpretCx<'mir, 'tcx, Self>,
437         dest: PlaceTy<'tcx, Tag>,
438     ) -> InterpResult<'tcx> {
439         trace!("box_alloc for {:?}", dest.layout.ty);
440         // Call the `exchange_malloc` lang item.
441         let malloc = ecx.tcx.lang_items().exchange_malloc_fn().unwrap();
442         let malloc = ty::Instance::mono(ecx.tcx.tcx, malloc);
443         let malloc_mir = ecx.load_mir(malloc.def)?;
444         ecx.push_stack_frame(
445             malloc,
446             malloc_mir.span,
447             malloc_mir,
448             Some(dest),
449             // Don't do anything when we are done. The `statement()` function will increment
450             // the old stack frame's stmt counter to the next statement, which means that when
451             // `exchange_malloc` returns, we go on evaluating exactly where we want to be.
452             StackPopCleanup::None { cleanup: true },
453         )?;
454
455         let mut args = ecx.frame().body.args_iter();
456         let layout = ecx.layout_of(dest.layout.ty.builtin_deref(false).unwrap().ty)?;
457
458         // First argument: `size`.
459         // (`0` is allowed here -- this is expected to be handled by the lang item).
460         let arg = ecx.eval_place(&mir::Place::Base(mir::PlaceBase::Local(args.next().unwrap())))?;
461         let size = layout.size.bytes();
462         ecx.write_scalar(Scalar::from_uint(size, arg.layout.size), arg)?;
463
464         // Second argument: `align`.
465         let arg = ecx.eval_place(&mir::Place::Base(mir::PlaceBase::Local(args.next().unwrap())))?;
466         let align = layout.align.abi.bytes();
467         ecx.write_scalar(Scalar::from_uint(align, arg.layout.size), arg)?;
468
469         // No more arguments.
470         assert!(
471             args.next().is_none(),
472             "`exchange_malloc` lang item has more arguments than expected"
473         );
474         Ok(())
475     }
476
477     fn find_foreign_static(
478         def_id: DefId,
479         tcx: TyCtxtAt<'tcx>,
480     ) -> InterpResult<'tcx, Cow<'tcx, Allocation>> {
481         let attrs = tcx.get_attrs(def_id);
482         let link_name = match attr::first_attr_value_str_by_name(&attrs, sym::link_name) {
483             Some(name) => name.as_str(),
484             None => tcx.item_name(def_id).as_str(),
485         };
486
487         let alloc = match link_name.get() {
488             "__cxa_thread_atexit_impl" => {
489                 // This should be all-zero, pointer-sized.
490                 let size = tcx.data_layout.pointer_size;
491                 let data = vec![0; size.bytes() as usize];
492                 Allocation::from_bytes(&data, tcx.data_layout.pointer_align.abi)
493             }
494             _ => return err!(Unimplemented(
495                     format!("can't access foreign static: {}", link_name),
496                 )),
497         };
498         Ok(Cow::Owned(alloc))
499     }
500
501     #[inline(always)]
502     fn before_terminator(_ecx: &mut InterpretCx<'mir, 'tcx, Self>) -> InterpResult<'tcx>
503     {
504         // We are not interested in detecting loops.
505         Ok(())
506     }
507
508     fn tag_allocation<'b>(
509         id: AllocId,
510         alloc: Cow<'b, Allocation>,
511         kind: Option<MemoryKind<Self::MemoryKinds>>,
512         memory: &Memory<'mir, 'tcx, Self>,
513     ) -> (Cow<'b, Allocation<Self::PointerTag, Self::AllocExtra>>, Self::PointerTag) {
514         let kind = kind.expect("we set our STATIC_KIND so this cannot be None");
515         let alloc = alloc.into_owned();
516         let (stacks, base_tag) = Stacks::new_allocation(
517             id,
518             Size::from_bytes(alloc.bytes.len() as u64),
519             Rc::clone(&memory.extra.stacked_borrows),
520             kind,
521         );
522         if kind != MiriMemoryKind::Static.into() {
523             assert!(alloc.relocations.is_empty(), "Only statics can come initialized with inner pointers");
524             // Now we can rely on the inner pointers being static, too.
525         }
526         let mut memory_extra = memory.extra.stacked_borrows.borrow_mut();
527         let alloc: Allocation<Tag, Self::AllocExtra> = Allocation {
528             bytes: alloc.bytes,
529             relocations: Relocations::from_presorted(
530                 alloc.relocations.iter()
531                     // The allocations in the relocations (pointers stored *inside* this allocation)
532                     // all get the base pointer tag.
533                     .map(|&(offset, ((), alloc))| (offset, (memory_extra.static_base_ptr(alloc), alloc)))
534                     .collect()
535             ),
536             undef_mask: alloc.undef_mask,
537             align: alloc.align,
538             mutability: alloc.mutability,
539             extra: AllocExtra {
540                 stacked_borrows: stacks,
541                 intptrcast: Default::default(),
542             },
543         };
544         (Cow::Owned(alloc), base_tag)
545     }
546
547     #[inline(always)]
548     fn tag_static_base_pointer(
549         id: AllocId,
550         memory: &Memory<'mir, 'tcx, Self>,
551     ) -> Self::PointerTag {
552         memory.extra.stacked_borrows.borrow_mut().static_base_ptr(id)
553     }
554
555     #[inline(always)]
556     fn retag(
557         ecx: &mut InterpretCx<'mir, 'tcx, Self>,
558         kind: mir::RetagKind,
559         place: PlaceTy<'tcx, Tag>,
560     ) -> InterpResult<'tcx> {
561         if !ecx.tcx.sess.opts.debugging_opts.mir_emit_retag || !Self::enforce_validity(ecx) {
562             // No tracking, or no retagging. The latter is possible because a dependency of ours
563             // might be called with different flags than we are, so there are `Retag`
564             // statements but we do not want to execute them.
565             // Also, honor the whitelist in `enforce_validity` because otherwise we might retag
566             // uninitialized data.
567              Ok(())
568         } else {
569             ecx.retag(kind, place)
570         }
571     }
572
573     #[inline(always)]
574     fn stack_push(
575         ecx: &mut InterpretCx<'mir, 'tcx, Self>,
576     ) -> InterpResult<'tcx, stacked_borrows::CallId> {
577         Ok(ecx.memory().extra.stacked_borrows.borrow_mut().new_call())
578     }
579
580     #[inline(always)]
581     fn stack_pop(
582         ecx: &mut InterpretCx<'mir, 'tcx, Self>,
583         extra: stacked_borrows::CallId,
584     ) -> InterpResult<'tcx> {
585         Ok(ecx.memory().extra.stacked_borrows.borrow_mut().end_call(extra))
586     }
587
588     fn int_to_ptr(
589         int: u64,
590         memory: &Memory<'mir, 'tcx, Self>,
591     ) -> InterpResult<'tcx, Pointer<Self::PointerTag>> {
592         if int == 0 {
593             err!(InvalidNullPointerUsage)
594         } else if memory.extra.rng.is_none() {
595             err!(ReadBytesAsPointer)
596         } else {
597            intptrcast::GlobalState::int_to_ptr(int, memory)
598         }
599     }
600  
601     fn ptr_to_int(
602         ptr: Pointer<Self::PointerTag>,
603         memory: &Memory<'mir, 'tcx, Self>,
604     ) -> InterpResult<'tcx, u64> {
605         if memory.extra.rng.is_none() {
606             err!(ReadPointerAsBytes)
607         } else {
608             intptrcast::GlobalState::ptr_to_int(ptr, memory)
609         }
610     }
611 }