Skip to content

Commit 39e2a76

Browse files
committed
Merge remote-tracking branch 'origin/master' into rustup-retag
2 parents 130f948 + 44ca0f6 commit 39e2a76

File tree

5 files changed

+35
-7
lines changed

5 files changed

+35
-7
lines changed

rust-version

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
96d07e0ac9f0c56b95a2561c6cedac0b23a5d2a3
1+
a44881d892fb4f4a8ed93f8f392bab942fac7a41

src/bin/cargo-miri.rs

+1-3
Original file line numberDiff line numberDiff line change
@@ -288,9 +288,7 @@ fn setup(ask_user: bool) {
288288
default_features = false
289289
# We need the `panic_unwind` feature because we use the `unwind` panic strategy.
290290
# Using `abort` works for libstd, but then libtest will not compile.
291-
# FIXME: Temporarily enabling backtrace feature to work around
292-
# <https://github.com/rust-lang/rust/issues/64410>.
293-
features = ["panic_unwind", "backtrace"]
291+
features = ["panic_unwind"]
294292
295293
[dependencies.test]
296294
"#).unwrap();

src/shims/mod.rs

+19-3
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
2727
}
2828
// There are some more lang items we want to hook that CTFE does not hook (yet).
2929
if this.tcx.lang_items().align_offset_fn() == Some(instance.def.def_id()) {
30-
// FIXME: return a real value in case the target allocation has an
31-
// alignment bigger than the one requested.
32-
let n = u128::max_value();
30+
31+
let n = {
32+
let ptr = this.force_ptr(this.read_scalar(args[0])?.not_undef()?)?;
33+
let align = this.force_bits(
34+
this.read_scalar(args[1])?.not_undef()?,
35+
this.pointer_size()
36+
)? as usize;
37+
38+
let stride = this.memory().get(ptr.alloc_id)?.align.bytes() as usize;
39+
// if the allocation alignment is at least the required alignment, we use the
40+
// libcore implementation
41+
if stride >= align {
42+
((stride + ptr.offset.bytes() as usize) as *const ())
43+
.align_offset(align) as u128
44+
} else {
45+
u128::max_value()
46+
}
47+
};
48+
3349
let dest = dest.unwrap();
3450
let n = this.truncate(n, dest.layout);
3551
this.write_scalar(Scalar::from_uint(n, dest.layout.size), dest)?;

tests/run-pass/aligned_utf8_check.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
fn main() {
2+
const N: usize = 10;
3+
4+
let x = vec![0x4141u16; N];
5+
6+
let mut y: Vec<u8> = unsafe { std::mem::transmute(x) };
7+
unsafe { y.set_len(2 * N) };
8+
9+
println!("{:?}", std::str::from_utf8(&y).unwrap());
10+
11+
let mut x: Vec<u16> = unsafe { std::mem::transmute(y) };
12+
unsafe { x.set_len(N) };
13+
}
+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
"AAAAAAAAAAAAAAAAAAAA"

0 commit comments

Comments
 (0)