Skip to content

Commit b71297f

Browse files
author
The Miri Cronjob Bot
committed
fmt
1 parent a9477c7 commit b71297f

File tree

5 files changed

+37
-21
lines changed

5 files changed

+37
-21
lines changed

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

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,8 +185,11 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
185185
panic!("Miri ran out of memory: cannot create allocation of {size:?} bytes")
186186
});
187187
let ptr = prepared_bytes.as_ptr();
188-
// Store prepared allocation space to be picked up for use later.
189-
global_state.prepared_alloc_bytes.try_insert(alloc_id, prepared_bytes).unwrap();
188+
// Store prepared allocation space to be picked up for use later.
189+
global_state
190+
.prepared_alloc_bytes
191+
.try_insert(alloc_id, prepared_bytes)
192+
.unwrap();
190193
ptr
191194
} else {
192195
ecx.get_alloc_bytes_unchecked_raw(alloc_id)?
@@ -196,16 +199,19 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
196199
}
197200
AllocKind::Function | AllocKind::VTable => {
198201
// Allocate some dummy memory to get a unique address for this function/vtable.
199-
let alloc_bytes = MiriAllocBytes::from_bytes(&[0u8; 1], Align::from_bytes(1).unwrap());
202+
let alloc_bytes = MiriAllocBytes::from_bytes(
203+
&[0u8; 1],
204+
Align::from_bytes(1).unwrap(),
205+
);
200206
// We don't need to expose these bytes as nobody is allowed to access them.
201207
let addr = alloc_bytes.as_ptr().addr().try_into().unwrap();
202208
// Leak the underlying memory to ensure it remains unique.
203209
std::mem::forget(alloc_bytes);
204210
addr
205211
}
206-
AllocKind::Dead => unreachable!()
212+
AllocKind::Dead => unreachable!(),
207213
}
208-
} else if let Some((reuse_addr, clock)) = global_state.reuse.take_addr(
214+
} else if let Some((reuse_addr, clock)) = global_state.reuse.take_addr(
209215
&mut *rng,
210216
size,
211217
align,
@@ -359,7 +365,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
359365

360366
// This returns some prepared `MiriAllocBytes`, either because `addr_from_alloc_id` reserved
361367
// memory space in the past, or by doing the pre-allocation right upon being called.
362-
fn get_global_alloc_bytes(&self, id: AllocId, kind: MemoryKind, bytes: &[u8], align: Align) -> InterpResult<'tcx, MiriAllocBytes> {
368+
fn get_global_alloc_bytes(
369+
&self,
370+
id: AllocId,
371+
kind: MemoryKind,
372+
bytes: &[u8],
373+
align: Align,
374+
) -> InterpResult<'tcx, MiriAllocBytes> {
363375
let ecx = self.eval_context_ref();
364376
Ok(if ecx.machine.native_lib.is_some() {
365377
// In native lib mode, MiriAllocBytes for global allocations are handled via `prepared_alloc_bytes`.

src/tools/miri/src/concurrency/thread.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -888,8 +888,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
888888
}
889889
let alloc = this.ctfe_query(|tcx| tcx.eval_static_initializer(def_id))?;
890890
// We make a full copy of this allocation.
891-
let mut alloc =
892-
alloc.inner().adjust_from_tcx(&this.tcx, |bytes, align| Ok(MiriAllocBytes::from_bytes(std::borrow::Cow::Borrowed(bytes), align)), |ptr| this.global_root_pointer(ptr))?;
891+
let mut alloc = alloc.inner().adjust_from_tcx(
892+
&this.tcx,
893+
|bytes, align| {
894+
Ok(MiriAllocBytes::from_bytes(std::borrow::Cow::Borrowed(bytes), align))
895+
},
896+
|ptr| this.global_root_pointer(ptr),
897+
)?;
893898
// This allocation will be deallocated when the thread dies, so it is not in read-only memory.
894899
alloc.mutability = Mutability::Mut;
895900
// Create a fresh allocation with this content.

src/tools/miri/src/machine.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1277,12 +1277,12 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
12771277
) -> InterpResult<'tcx, Cow<'b, Allocation<Self::Provenance, Self::AllocExtra, Self::Bytes>>>
12781278
{
12791279
let kind = Self::GLOBAL_KIND.unwrap().into();
1280-
let alloc = alloc.adjust_from_tcx(&ecx.tcx,
1280+
let alloc = alloc.adjust_from_tcx(
1281+
&ecx.tcx,
12811282
|bytes, align| ecx.get_global_alloc_bytes(id, kind, bytes, align),
12821283
|ptr| ecx.global_root_pointer(ptr),
12831284
)?;
1284-
let extra =
1285-
Self::init_alloc_extra(ecx, id, kind, alloc.size(), alloc.align)?;
1285+
let extra = Self::init_alloc_extra(ecx, id, kind, alloc.size(), alloc.align)?;
12861286
Ok(Cow::Owned(alloc.with_extra(extra)))
12871287
}
12881288

src/tools/miri/src/shims/native_lib.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -240,13 +240,16 @@ fn imm_to_carg<'tcx>(v: ImmTy<'tcx>, cx: &impl HasDataLayout) -> InterpResult<'t
240240
ty::RawPtr(_, mutability) => {
241241
// Arbitrary mutable pointer accesses are not currently supported in Miri.
242242
if mutability.is_mut() {
243-
throw_unsup_format!("unsupported mutable pointer type for native call: {}", v.layout.ty);
243+
throw_unsup_format!(
244+
"unsupported mutable pointer type for native call: {}",
245+
v.layout.ty
246+
);
244247
} else {
245248
let s = v.to_scalar().to_pointer(cx)?.addr();
246249
// This relies on the `expose_provenance` in `addr_from_alloc_id`.
247250
CArg::RawPtr(std::ptr::with_exposed_provenance_mut(s.bytes_usize()))
248251
}
249-
},
252+
}
250253
_ => throw_unsup_format!("unsupported argument type for native call: {}", v.layout.ty),
251254
})
252255
}

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

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ fn test_pointer() {
2626
fn test_simple() {
2727
#[repr(C)]
2828
struct Simple {
29-
field: i32
29+
field: i32,
3030
}
3131

3232
extern "C" {
@@ -41,7 +41,7 @@ fn test_simple() {
4141
// Test function that dereferences nested struct pointers and accesses fields.
4242
fn test_nested() {
4343
use std::ptr::NonNull;
44-
44+
4545
#[derive(Debug, PartialEq, Eq)]
4646
#[repr(C)]
4747
struct Nested {
@@ -62,7 +62,6 @@ fn test_nested() {
6262

6363
// Test function that dereferences static struct pointers and accesses fields.
6464
fn test_static() {
65-
6665
#[repr(C)]
6766
struct Static {
6867
value: i32,
@@ -72,11 +71,8 @@ fn test_static() {
7271
extern "C" {
7372
fn access_static(n_ptr: *const Static) -> i32;
7473
}
75-
76-
static STATIC: Static = Static {
77-
value: 9001,
78-
recurse: &STATIC,
79-
};
74+
75+
static STATIC: Static = Static { value: 9001, recurse: &STATIC };
8076

8177
assert_eq!(unsafe { access_static(&STATIC) }, 9001);
8278
}

0 commit comments

Comments
 (0)