Skip to content

Commit 1ba4dd9

Browse files
committed
Auto merge of #132831 - workingjubilee:rollup-6fdif44, r=workingjubilee
Rollup of 6 pull requests Successful merges: - #131258 (Stabilize s390x inline assembly) - #132801 (interpret: get_alloc_info: also return mutability) - #132823 (require const_impl_trait gate for all conditional and trait const calls) - #132824 (Update grammar in wasm-c-abi's compiler flag documentation) - #132825 (Exclude relnotes-tracking-issue from needs-triage) - #132828 (Additional tests to ensure let is rejected during parsing) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 0df35fc + c4a58c9 commit 1ba4dd9

File tree

6 files changed

+20
-20
lines changed

6 files changed

+20
-20
lines changed

src/alloc_addresses/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
134134
// entered for addresses that are not the base address, so even zero-sized
135135
// allocations will get recognized at their base address -- but all other
136136
// allocations will *not* be recognized at their "end" address.
137-
let size = ecx.get_alloc_info(alloc_id).0;
137+
let size = ecx.get_alloc_info(alloc_id).size;
138138
if offset < size.bytes() { Some(alloc_id) } else { None }
139139
}
140140
}?;
@@ -157,25 +157,25 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
157157
) -> InterpResult<'tcx, u64> {
158158
let ecx = self.eval_context_ref();
159159
let mut rng = ecx.machine.rng.borrow_mut();
160-
let (size, align, kind) = ecx.get_alloc_info(alloc_id);
160+
let info = ecx.get_alloc_info(alloc_id);
161161
// This is either called immediately after allocation (and then cached), or when
162162
// adjusting `tcx` pointers (which never get freed). So assert that we are looking
163163
// at a live allocation. This also ensures that we never re-assign an address to an
164164
// allocation that previously had an address, but then was freed and the address
165165
// information was removed.
166-
assert!(!matches!(kind, AllocKind::Dead));
166+
assert!(!matches!(info.kind, AllocKind::Dead));
167167

168168
// This allocation does not have a base address yet, pick or reuse one.
169169
if ecx.machine.native_lib.is_some() {
170170
// In native lib mode, we use the "real" address of the bytes for this allocation.
171171
// This ensures the interpreted program and native code have the same view of memory.
172-
let base_ptr = match kind {
172+
let base_ptr = match info.kind {
173173
AllocKind::LiveData => {
174174
if ecx.tcx.try_get_global_alloc(alloc_id).is_some() {
175175
// For new global allocations, we always pre-allocate the memory to be able use the machine address directly.
176-
let prepared_bytes = MiriAllocBytes::zeroed(size, align)
176+
let prepared_bytes = MiriAllocBytes::zeroed(info.size, info.align)
177177
.unwrap_or_else(|| {
178-
panic!("Miri ran out of memory: cannot create allocation of {size:?} bytes")
178+
panic!("Miri ran out of memory: cannot create allocation of {size:?} bytes", size = info.size)
179179
});
180180
let ptr = prepared_bytes.as_ptr();
181181
// Store prepared allocation space to be picked up for use later.
@@ -204,7 +204,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
204204
}
205205
// We are not in native lib mode, so we control the addresses ourselves.
206206
if let Some((reuse_addr, clock)) =
207-
global_state.reuse.take_addr(&mut *rng, size, align, memory_kind, ecx.active_thread())
207+
global_state.reuse.take_addr(&mut *rng, info.size, info.align, memory_kind, ecx.active_thread())
208208
{
209209
if let Some(clock) = clock {
210210
ecx.acquire_clock(&clock);
@@ -220,14 +220,14 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
220220
.next_base_addr
221221
.checked_add(slack)
222222
.ok_or_else(|| err_exhaust!(AddressSpaceFull))?;
223-
let base_addr = align_addr(base_addr, align.bytes());
223+
let base_addr = align_addr(base_addr, info.align.bytes());
224224

225225
// Remember next base address. If this allocation is zero-sized, leave a gap of at
226226
// least 1 to avoid two allocations having the same base address. (The logic in
227227
// `alloc_id_from_addr` assumes unique addresses, and different function/vtable pointers
228228
// need to be distinguishable!)
229229
global_state.next_base_addr = base_addr
230-
.checked_add(max(size.bytes(), 1))
230+
.checked_add(max(info.size.bytes(), 1))
231231
.ok_or_else(|| err_exhaust!(AddressSpaceFull))?;
232232
// Even if `Size` didn't overflow, we might still have filled up the address space.
233233
if global_state.next_base_addr > ecx.target_usize_max() {

src/borrow_tracker/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -363,7 +363,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
363363
// If it does exist, then we have the guarantee that the
364364
// pointer is readable, and the implicit read access inserted
365365
// will never cause UB on the pointer itself.
366-
let (_, _, kind) = this.get_alloc_info(*alloc_id);
366+
let kind = this.get_alloc_info(*alloc_id).kind;
367367
if matches!(kind, AllocKind::LiveData) {
368368
let alloc_extra = this.get_alloc_extra(*alloc_id)?; // can still fail for `extern static`
369369
let alloc_borrow_tracker = &alloc_extra.borrow_tracker.as_ref().unwrap();

src/borrow_tracker/stacked_borrows/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ trait EvalContextPrivExt<'tcx, 'ecx>: crate::MiriInterpCxExt<'tcx> {
626626
return interp_ok(())
627627
};
628628

629-
let (_size, _align, alloc_kind) = this.get_alloc_info(alloc_id);
629+
let alloc_kind = this.get_alloc_info(alloc_id).kind;
630630
match alloc_kind {
631631
AllocKind::LiveData => {
632632
// This should have alloc_extra data, but `get_alloc_extra` can still fail
@@ -1017,7 +1017,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
10171017
// Function pointers and dead objects don't have an alloc_extra so we ignore them.
10181018
// This is okay because accessing them is UB anyway, no need for any Stacked Borrows checks.
10191019
// NOT using `get_alloc_extra_mut` since this might be a read-only allocation!
1020-
let (_size, _align, kind) = this.get_alloc_info(alloc_id);
1020+
let kind = this.get_alloc_info(alloc_id).kind;
10211021
match kind {
10221022
AllocKind::LiveData => {
10231023
// This should have alloc_extra data, but `get_alloc_extra` can still fail

src/borrow_tracker/tree_borrows/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ trait EvalContextPrivExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
274274
.insert(new_tag, protect);
275275
}
276276

277-
let alloc_kind = this.get_alloc_info(alloc_id).2;
277+
let alloc_kind = this.get_alloc_info(alloc_id).kind;
278278
if !matches!(alloc_kind, AllocKind::LiveData) {
279279
assert_eq!(ptr_size, Size::ZERO); // we did the deref check above, size has to be 0 here
280280
// There's not actually any bytes here where accesses could even be tracked.
@@ -538,7 +538,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
538538
// Function pointers and dead objects don't have an alloc_extra so we ignore them.
539539
// This is okay because accessing them is UB anyway, no need for any Tree Borrows checks.
540540
// NOT using `get_alloc_extra_mut` since this might be a read-only allocation!
541-
let (_size, _align, kind) = this.get_alloc_info(alloc_id);
541+
let kind = this.get_alloc_info(alloc_id).kind;
542542
match kind {
543543
AllocKind::LiveData => {
544544
// This should have alloc_extra data, but `get_alloc_extra` can still fail

src/machine.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1125,10 +1125,10 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
11251125
let Provenance::Concrete { alloc_id, .. } = ptr.provenance else {
11261126
panic!("extern_statics cannot contain wildcards")
11271127
};
1128-
let (shim_size, shim_align, _kind) = ecx.get_alloc_info(alloc_id);
1128+
let info = ecx.get_alloc_info(alloc_id);
11291129
let def_ty = ecx.tcx.type_of(def_id).instantiate_identity();
11301130
let extern_decl_layout = ecx.tcx.layout_of(ty::ParamEnv::empty().and(def_ty)).unwrap();
1131-
if extern_decl_layout.size != shim_size || extern_decl_layout.align.abi != shim_align {
1131+
if extern_decl_layout.size != info.size || extern_decl_layout.align.abi != info.align {
11321132
throw_unsup_format!(
11331133
"extern static `{link_name}` has been declared as `{krate}::{name}` \
11341134
with a size of {decl_size} bytes and alignment of {decl_align} bytes, \
@@ -1138,8 +1138,8 @@ impl<'tcx> Machine<'tcx> for MiriMachine<'tcx> {
11381138
krate = ecx.tcx.crate_name(def_id.krate),
11391139
decl_size = extern_decl_layout.size.bytes(),
11401140
decl_align = extern_decl_layout.align.abi.bytes(),
1141-
shim_size = shim_size.bytes(),
1142-
shim_align = shim_align.bytes(),
1141+
shim_size = info.size.bytes(),
1142+
shim_align = info.align.bytes(),
11431143
)
11441144
}
11451145
interp_ok(ptr)

src/shims/foreign_items.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
300300
let id = this.read_scalar(id)?.to_u64()?;
301301
let show_unnamed = this.read_scalar(show_unnamed)?.to_bool()?;
302302
if let Some(id) = std::num::NonZero::new(id).map(AllocId)
303-
&& this.get_alloc_info(id).2 == AllocKind::LiveData
303+
&& this.get_alloc_info(id).kind == AllocKind::LiveData
304304
{
305305
this.print_borrow_state(id, show_unnamed)?;
306306
} else {
@@ -409,7 +409,7 @@ trait EvalContextExtPriv<'tcx>: crate::MiriInterpCxExt<'tcx> {
409409
);
410410
}
411411
if let Ok((alloc_id, offset, ..)) = this.ptr_try_get_alloc_id(ptr, 0) {
412-
let (_size, alloc_align, _kind) = this.get_alloc_info(alloc_id);
412+
let alloc_align = this.get_alloc_info(alloc_id).align;
413413
// If the newly promised alignment is bigger than the native alignment of this
414414
// allocation, and bigger than the previously promised alignment, then set it.
415415
if align > alloc_align

0 commit comments

Comments
 (0)