From 42ac31182bab6735cfe9ad77d8f4292fad51bfa8 Mon Sep 17 00:00:00 2001 From: Peter Atashian Date: Wed, 31 May 2017 23:24:19 -0400 Subject: [PATCH] Add test for vecs with overaligned data --- src/libcollections/tests/lib.rs | 2 ++ src/libcollections/tests/vec.rs | 15 +++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/src/libcollections/tests/lib.rs b/src/libcollections/tests/lib.rs index 6ad5781c5d5..66918e0f5f8 100644 --- a/src/libcollections/tests/lib.rs +++ b/src/libcollections/tests/lib.rs @@ -10,6 +10,7 @@ #![deny(warnings)] +#![feature(attr_literals)] #![feature(box_syntax)] #![feature(inclusive_range_syntax)] #![feature(collection_placement)] @@ -19,6 +20,7 @@ #![feature(pattern)] #![feature(placement_in_syntax)] #![feature(rand)] +#![feature(repr_align)] #![feature(slice_rotate)] #![feature(splice)] #![feature(step_by)] diff --git a/src/libcollections/tests/vec.rs b/src/libcollections/tests/vec.rs index 29f18274962..fdf453b39cf 100644 --- a/src/libcollections/tests/vec.rs +++ b/src/libcollections/tests/vec.rs @@ -781,3 +781,18 @@ fn from_into_inner() { assert_eq!(vec, [2, 3]); assert!(ptr != vec.as_ptr()); } + +#[test] +fn overaligned_allocations() { + #[repr(align(256))] + struct Foo(usize); + let mut v = vec![Foo(273)]; + for i in 0..0x1000 { + v.reserve_exact(i); + assert!(v[0].0 == 273); + assert!(v.as_ptr() as usize & 0xff == 0); + v.shrink_to_fit(); + assert!(v[0].0 == 273); + assert!(v.as_ptr() as usize & 0xff == 0); + } +} -- 2.44.0