Skip to content

Commit 4ee6e60

Browse files
committed
manual fmt adjustments, fmt, adjust and bless miri native test
1 parent 8745d7a commit 4ee6e60

File tree

6 files changed

+19
-13
lines changed

6 files changed

+19
-13
lines changed

compiler/rustc_middle/src/mir/interpret/allocation.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ impl Allocation {
362362
mut adjust_ptr: impl FnMut(Pointer<CtfeProvenance>) -> Result<Pointer<Prov>, Err>,
363363
) -> Result<Allocation<Prov, (), Bytes>, Err> {
364364
// Copy the data.
365-
let mut bytes = alloc_bytes(&*self.bytes, self.align);
365+
let mut bytes = alloc_bytes(&*self.bytes, self.align);
366366
// Adjust provenance of pointers stored in this allocation.
367367
let mut new_provenance = Vec::with_capacity(self.provenance.ptrs().len());
368368
let ptr_size = cx.data_layout().pointer_size.bytes_usize();

src/tools/miri/src/alloc_addresses/mod.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,10 @@ pub struct GlobalStateInner {
4242
/// they do not have an `AllocExtra`.
4343
/// This is the inverse of `int_to_ptr_map`.
4444
base_addr: FxHashMap<AllocId, u64>,
45-
// Temporarily store prepared memory space for global allocations the first time their memory address is required. This is used to ensure that the memory is allocated before Miri assigns it an internal address, which is important for matching the internal address to the machine address so FFI can read from pointers.
45+
/// Temporarily store prepared memory space for global allocations the first time their memory
46+
/// address is required. This is used to ensure that the memory is allocated before Miri assigns
47+
/// it an internal address, which is important for matching the internal address to the machine
48+
/// address so FFI can read from pointers.
4649
prepared_alloc_bytes: FxHashMap<AllocId, MiriAllocBytes>,
4750
/// A pool of addresses we can reuse for future allocations.
4851
reuse: ReusePool,
@@ -348,13 +351,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
348351
Ok(base_ptr.wrapping_offset(offset, ecx))
349352
}
350353

351-
// This returns some prepared `MiriAllocBytes`, either because `addr_from_alloc_id` was called in the past and reserved memory space, or by doing the pre-allocation right upon being called.
354+
// This returns some prepared `MiriAllocBytes`, either because `addr_from_alloc_id` reserved
355+
// memory space in the past, or by doing the pre-allocation right upon being called.
352356
fn take_prepared_alloc_bytes(&self, id: AllocId, kind: MemoryKind) -> InterpResult<'tcx, MiriAllocBytes> {
353357
let ecx = self.eval_context_ref();
354358
// This additional call ensures that some `MiriAllocBytes` are prepared.
355359
ecx.addr_from_alloc_id(id, kind)?;
356360
// TODO: Better debug message?
357-
let prepared_alloc_bytes = ecx.machine.alloc_addresses.borrow_mut().prepared_alloc_bytes.remove(&id).expect("alloc bytes for alloc_id could not prepared");
361+
let mut global_state = ecx.machine.alloc_addresses.borrow_mut();
362+
let prepared_alloc_bytes = global_state
363+
.prepared_alloc_bytes
364+
.remove(&id)
365+
.expect("alloc bytes for alloc_id could not prepared");
358366
Ok(prepared_alloc_bytes)
359367
}
360368

src/tools/miri/src/machine.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1244,11 +1244,13 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
12441244
// based on their particular choice for `Provenance`, `AllocExtra`, and `Bytes`.
12451245
let kind = Self::GLOBAL_KIND
12461246
.expect("if GLOBAL_KIND is None, adjust_global_allocation must be overwritten");
1247-
// This closure is special in that it always relies on `take_prepared_alloc_bytes` to give it some reserved memory space.
1247+
// This closure is special in that it always relies on `take_prepared_alloc_bytes`
1248+
// to give it some reserved memory space.
12481249
let alloc = alloc.adjust_from_tcx(&ecx.tcx, |bytes, align| {
12491250
assert_eq!(alloc.align, align);
1251+
let kind = MemoryKind::Machine(kind);
12501252
// TODO: is this unwrap warranted?
1251-
let mut alloc_bytes = ecx.take_prepared_alloc_bytes(id, MemoryKind::Machine(kind)).unwrap();
1253+
let mut alloc_bytes = ecx.take_prepared_alloc_bytes(id, kind).unwrap();
12521254
assert_eq!(alloc_bytes.len(), bytes.len());
12531255
// SAFETY: `alloc_bytes` and `bytes` span the same number of bytes.
12541256
unsafe { alloc_bytes.as_mut_ptr().copy_from(bytes.as_ptr(), bytes.len()) };

src/tools/miri/tests/native-lib/pass/call_extern_c_fn.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,12 +44,9 @@ fn main() {
4444
// test void function that prints from C
4545
printer();
4646

47-
// test void function that dereferences a pointer and prints from C
47+
// test void function that dereferences a pointer and prints its contents from C
4848
let mut x = 42i32;
4949
let ptr = &mut x as *mut i32;
50-
println!("pointer address from Rust: {:?}", ptr);
51-
println!("printing dereference from Rust: {}", *ptr);
5250
ptr_printer(ptr);
53-
5451
}
5552
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
printing from C
2+
printing pointer dereference from C: 42

src/tools/miri/tests/native-lib/test.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,7 @@ void printer() {
99
}
1010

1111
void ptr_printer(int *ptr) {
12-
printf("printing address from C: %p\n", ptr);
13-
// TODO: Get *this* to work.
14-
printf("printing dereference from C: %d\n", *ptr);
12+
printf("printing pointer dereference from C: %d\n", *ptr);
1513
}
1614

1715
// function with many arguments, to test functionality when some args are stored

0 commit comments

Comments
 (0)