Skip to content

Commit 7095a3b

Browse files
committed
Auto merge of #942 - rust-lang:rustup, r=oli-obk
Rustup
2 parents a58cb9c + 8349ead commit 7095a3b

File tree

5 files changed

+28
-43
lines changed

5 files changed

+28
-43
lines changed

rust-version

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
fdaf594bab31eec75fb6d582cd33e5a5b43de7f4
1+
4894123d21ed4b153a2e5c32c0870cb2d97f9b46

src/intptrcast.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,28 +47,28 @@ impl<'mir, 'tcx> GlobalState {
4747
}
4848

4949
let global_state = memory.extra.intptrcast.borrow();
50-
50+
5151
Ok(match global_state.int_to_ptr_map.binary_search_by_key(&int, |(addr, _)| *addr) {
5252
Ok(pos) => {
5353
let (_, alloc_id) = global_state.int_to_ptr_map[pos];
5454
// `int` is equal to the starting address for an allocation, the offset should be
5555
// zero. The pointer is untagged because it was created from a cast
5656
Pointer::new_with_tag(alloc_id, Size::from_bytes(0), Tag::Untagged)
5757
},
58-
Err(0) => throw_unsup!(DanglingPointerDeref),
58+
Err(0) => throw_unsup!(DanglingPointerDeref),
5959
Err(pos) => {
6060
// This is the largest of the adresses smaller than `int`,
6161
// i.e. the greatest lower bound (glb)
6262
let (glb, alloc_id) = global_state.int_to_ptr_map[pos - 1];
6363
// This never overflows because `int >= glb`
6464
let offset = int - glb;
6565
// If the offset exceeds the size of the allocation, this access is illegal
66-
if offset <= memory.get(alloc_id)?.bytes.len() as u64 {
66+
if offset <= memory.get(alloc_id)?.size.bytes() {
6767
// This pointer is untagged because it was created from a cast
6868
Pointer::new_with_tag(alloc_id, Size::from_bytes(offset), Tag::Untagged)
6969
} else {
7070
throw_unsup!(DanglingPointerDeref)
71-
}
71+
}
7272
}
7373
})
7474
}
@@ -108,7 +108,7 @@ impl<'mir, 'tcx> GlobalState {
108108
global_state.next_base_addr = base_addr.checked_add(max(size.bytes(), 1)).unwrap();
109109
// Given that `next_base_addr` increases in each allocation, pushing the
110110
// corresponding tuple keeps `int_to_ptr_map` sorted
111-
global_state.int_to_ptr_map.push((base_addr, ptr.alloc_id));
111+
global_state.int_to_ptr_map.push((base_addr, ptr.alloc_id));
112112

113113
base_addr
114114
}

src/machine.rs

Lines changed: 12 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
248248
None => tcx.item_name(def_id).as_str(),
249249
};
250250

251-
let alloc = match link_name.get() {
251+
let alloc = match &*link_name {
252252
"__cxa_thread_atexit_impl" => {
253253
// This should be all-zero, pointer-sized.
254254
let size = tcx.data_layout.pointer_size;
@@ -280,40 +280,25 @@ impl<'mir, 'tcx> Machine<'mir, 'tcx> for Evaluator<'tcx> {
280280
} else {
281281
let (stacks, base_tag) = Stacks::new_allocation(
282282
id,
283-
Size::from_bytes(alloc.bytes.len() as u64),
283+
alloc.size,
284284
Rc::clone(&memory_extra.stacked_borrows),
285285
kind,
286286
);
287287
(Some(stacks), base_tag)
288288
};
289-
if kind != MiriMemoryKind::Static.into() {
290-
assert!(alloc.relocations.is_empty(), "Only statics can come initialized with inner pointers");
291-
// Now we can rely on the inner pointers being static, too.
292-
}
293289
let mut stacked_borrows = memory_extra.stacked_borrows.borrow_mut();
294-
let alloc: Allocation<Tag, Self::AllocExtra> = Allocation {
295-
bytes: alloc.bytes,
296-
relocations: Relocations::from_presorted(
297-
alloc.relocations.iter()
298-
// The allocations in the relocations (pointers stored *inside* this allocation)
299-
// all get the base pointer tag.
300-
.map(|&(offset, ((), alloc))| {
301-
let tag = if !memory_extra.validate {
302-
Tag::Untagged
303-
} else {
304-
stacked_borrows.static_base_ptr(alloc)
305-
};
306-
(offset, (tag, alloc))
307-
})
308-
.collect()
309-
),
310-
undef_mask: alloc.undef_mask,
311-
align: alloc.align,
312-
mutability: alloc.mutability,
313-
extra: AllocExtra {
290+
let alloc: Allocation<Tag, Self::AllocExtra> = alloc.retag(
291+
|alloc| if !memory_extra.validate {
292+
Tag::Untagged
293+
} else {
294+
// Only statics may already contain pointers at this point
295+
assert_eq!(kind, MiriMemoryKind::Static.into());
296+
stacked_borrows.static_base_ptr(alloc)
297+
},
298+
AllocExtra {
314299
stacked_borrows: stacks,
315300
},
316-
};
301+
);
317302
(Cow::Owned(alloc), base_tag)
318303
}
319304

src/shims/foreign_items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
138138
None => this.tcx.item_name(def_id).as_str(),
139139
};
140140
// Strip linker suffixes (seen on 32-bit macOS).
141-
let link_name = link_name.get().trim_end_matches("$UNIX2003");
141+
let link_name = link_name.trim_end_matches("$UNIX2003");
142142
let tcx = &{this.tcx.tcx};
143143

144144
// First: functions that diverge.

src/shims/intrinsics.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2828
// (as opposed to through a place), we have to remember to erase any tag
2929
// that might still hang around!
3030

31-
let intrinsic_name = this.tcx.item_name(instance.def_id()).as_str();
32-
match intrinsic_name.get() {
31+
let intrinsic_name = &*this.tcx.item_name(instance.def_id()).as_str();
32+
match intrinsic_name {
3333
"arith_offset" => {
3434
let offset = this.read_scalar(args[1])?.to_isize(this)?;
3535
let ptr = this.read_scalar(args[0])?.not_undef()?;
@@ -228,7 +228,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
228228
"log10f32" | "log2f32" | "floorf32" | "ceilf32" | "truncf32" | "roundf32" => {
229229
// FIXME: Using host floats.
230230
let f = f32::from_bits(this.read_scalar(args[0])?.to_u32()?);
231-
let f = match intrinsic_name.get() {
231+
let f = match intrinsic_name {
232232
"sinf32" => f.sin(),
233233
"fabsf32" => f.abs(),
234234
"cosf32" => f.cos(),
@@ -251,7 +251,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
251251
"log10f64" | "log2f64" | "floorf64" | "ceilf64" | "truncf64" | "roundf64" => {
252252
// FIXME: Using host floats.
253253
let f = f64::from_bits(this.read_scalar(args[0])?.to_u64()?);
254-
let f = match intrinsic_name.get() {
254+
let f = match intrinsic_name {
255255
"sinf64" => f.sin(),
256256
"fabsf64" => f.abs(),
257257
"cosf64" => f.cos(),
@@ -273,7 +273,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
273273
"fadd_fast" | "fsub_fast" | "fmul_fast" | "fdiv_fast" | "frem_fast" => {
274274
let a = this.read_immediate(args[0])?;
275275
let b = this.read_immediate(args[1])?;
276-
let op = match intrinsic_name.get() {
276+
let op = match intrinsic_name {
277277
"fadd_fast" => mir::BinOp::Add,
278278
"fsub_fast" => mir::BinOp::Sub,
279279
"fmul_fast" => mir::BinOp::Mul,
@@ -287,7 +287,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
287287
"minnumf32" | "maxnumf32" => {
288288
let a = this.read_scalar(args[0])?.to_f32()?;
289289
let b = this.read_scalar(args[1])?.to_f32()?;
290-
let res = if intrinsic_name.get().starts_with("min") {
290+
let res = if intrinsic_name.starts_with("min") {
291291
a.min(b)
292292
} else {
293293
a.max(b)
@@ -298,7 +298,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
298298
"minnumf64" | "maxnumf64" => {
299299
let a = this.read_scalar(args[0])?.to_f64()?;
300300
let b = this.read_scalar(args[1])?.to_f64()?;
301-
let res = if intrinsic_name.get().starts_with("min") {
301+
let res = if intrinsic_name.starts_with("min") {
302302
a.min(b)
303303
} else {
304304
a.max(b)
@@ -509,15 +509,15 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
509509
"unchecked_add" | "unchecked_sub" | "unchecked_mul" => {
510510
let l = this.read_immediate(args[0])?;
511511
let r = this.read_immediate(args[1])?;
512-
let op = match intrinsic_name.get() {
512+
let op = match intrinsic_name {
513513
"unchecked_add" => mir::BinOp::Add,
514514
"unchecked_sub" => mir::BinOp::Sub,
515515
"unchecked_mul" => mir::BinOp::Mul,
516516
_ => bug!(),
517517
};
518518
let (res, overflowed, _ty) = this.overflowing_binary_op(op, l, r)?;
519519
if overflowed {
520-
throw_ub_format!("Overflowing arithmetic in {}", intrinsic_name.get());
520+
throw_ub_format!("Overflowing arithmetic in {}", intrinsic_name);
521521
}
522522
this.write_scalar(res, dest)?;
523523
}

0 commit comments

Comments
 (0)