diff --git a/rust-version b/rust-version index 07e965d7c39..464b061edbd 100644 --- a/rust-version +++ b/rust-version @@ -1 +1 @@ -96d07e0ac9f0c56b95a2561c6cedac0b23a5d2a3 +a44881d892fb4f4a8ed93f8f392bab942fac7a41 diff --git a/src/bin/cargo-miri.rs b/src/bin/cargo-miri.rs index d92fc344e8a..43e8761d48c 100644 --- a/src/bin/cargo-miri.rs +++ b/src/bin/cargo-miri.rs @@ -288,9 +288,7 @@ fn setup(ask_user: bool) { default_features = false # We need the `panic_unwind` feature because we use the `unwind` panic strategy. # Using `abort` works for libstd, but then libtest will not compile. -# FIXME: Temporarily enabling backtrace feature to work around -# . -features = ["panic_unwind", "backtrace"] +features = ["panic_unwind"] [dependencies.test] "#).unwrap(); diff --git a/src/shims/mod.rs b/src/shims/mod.rs index 5fbe6e37998..a0da364ff0b 100644 --- a/src/shims/mod.rs +++ b/src/shims/mod.rs @@ -27,9 +27,25 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx } // There are some more lang items we want to hook that CTFE does not hook (yet). if this.tcx.lang_items().align_offset_fn() == Some(instance.def.def_id()) { - // FIXME: return a real value in case the target allocation has an - // alignment bigger than the one requested. - let n = u128::max_value(); + + let n = { + let ptr = this.force_ptr(this.read_scalar(args[0])?.not_undef()?)?; + let align = this.force_bits( + this.read_scalar(args[1])?.not_undef()?, + this.pointer_size() + )? as usize; + + let stride = this.memory().get(ptr.alloc_id)?.align.bytes() as usize; + // if the allocation alignment is at least the required alignment, we use the + // libcore implementation + if stride >= align { + ((stride + ptr.offset.bytes() as usize) as *const ()) + .align_offset(align) as u128 + } else { + u128::max_value() + } + }; + let dest = dest.unwrap(); let n = this.truncate(n, dest.layout); this.write_scalar(Scalar::from_uint(n, dest.layout.size), dest)?; diff --git a/tests/run-pass/aligned_utf8_check.rs b/tests/run-pass/aligned_utf8_check.rs new file mode 100644 index 00000000000..202856b3bde --- /dev/null +++ b/tests/run-pass/aligned_utf8_check.rs @@ -0,0 +1,13 @@ +fn main() { + const N: usize = 10; + + let x = vec![0x4141u16; N]; + + let mut y: Vec = unsafe { std::mem::transmute(x) }; + unsafe { y.set_len(2 * N) }; + + println!("{:?}", std::str::from_utf8(&y).unwrap()); + + let mut x: Vec = unsafe { std::mem::transmute(y) }; + unsafe { x.set_len(N) }; +} diff --git a/tests/run-pass/aligned_utf8_check.stdout b/tests/run-pass/aligned_utf8_check.stdout new file mode 100644 index 00000000000..8d08312cac7 --- /dev/null +++ b/tests/run-pass/aligned_utf8_check.stdout @@ -0,0 +1 @@ +"AAAAAAAAAAAAAAAAAAAA"