mirror of
https://github.com/rust-lang/rust.git
synced 2025-05-14 02:49:40 +00:00
rt: Fix some record alignment issues on windows
This commit is contained in:
parent
e2910bf264
commit
1e410f6206
@ -127,6 +127,7 @@ rust_alignof<double>() {
|
|||||||
// On 32-bit x86 the alignment of 64-bit ints in structures is 4 bytes
|
// On 32-bit x86 the alignment of 64-bit ints in structures is 4 bytes
|
||||||
// Which is different from the preferred 8-byte alignment reported
|
// Which is different from the preferred 8-byte alignment reported
|
||||||
// by __alignof__ (at least on gcc).
|
// by __alignof__ (at least on gcc).
|
||||||
|
#ifndef __WIN32__
|
||||||
#ifdef __i386__
|
#ifdef __i386__
|
||||||
template<>
|
template<>
|
||||||
inline size_t
|
inline size_t
|
||||||
@ -134,6 +135,7 @@ rust_alignof<uint64_t>() {
|
|||||||
return 4;
|
return 4;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
// Utility classes
|
// Utility classes
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
// xfail-win32 need to investigate alignment on windows
|
// xfail-fast Does not work with main in a submodule
|
||||||
|
|
||||||
#[abi = "rust-intrinsic"]
|
#[abi = "rust-intrinsic"]
|
||||||
native mod rusti {
|
native mod rusti {
|
||||||
@ -6,14 +6,28 @@ native mod rusti {
|
|||||||
fn min_align_of<T>() -> uint;
|
fn min_align_of<T>() -> uint;
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(target_os = "linux")]
|
||||||
fn main() {
|
#[cfg(target_os = "macos")]
|
||||||
assert rusti::pref_align_of::<u64>() == 8u;
|
#[cfg(target_os = "freebsd")]
|
||||||
assert rusti::min_align_of::<u64>() == 4u;
|
mod m {
|
||||||
|
#[cfg(target_arch = "x86")]
|
||||||
|
fn main() {
|
||||||
|
assert rusti::pref_align_of::<u64>() == 8u;
|
||||||
|
assert rusti::min_align_of::<u64>() == 4u;
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
fn main() {
|
||||||
|
assert rusti::pref_align_of::<u64>() == 8u;
|
||||||
|
assert rusti::min_align_of::<u64>() == 8u;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_os = "win32")]
|
||||||
fn main() {
|
mod m {
|
||||||
assert rusti::pref_align_of::<u64>() == 8u;
|
#[cfg(target_arch = "x86")]
|
||||||
assert rusti::min_align_of::<u64>() == 8u;
|
fn main() {
|
||||||
|
assert rusti::pref_align_of::<u64>() == 8u;
|
||||||
|
assert rusti::min_align_of::<u64>() == 8u;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
// xfail-pretty
|
// xfail-pretty
|
||||||
// xfail-win32
|
|
||||||
// Issue #2303
|
// Issue #2303
|
||||||
|
|
||||||
#[abi = "rust-intrinsic"]
|
#[abi = "rust-intrinsic"]
|
||||||
@ -10,7 +9,7 @@ native mod rusti {
|
|||||||
|
|
||||||
// This is the type with the questionable alignment
|
// This is the type with the questionable alignment
|
||||||
type inner = {
|
type inner = {
|
||||||
c64: u64
|
c64: u32
|
||||||
};
|
};
|
||||||
|
|
||||||
// This is the type that contains the type with the
|
// This is the type that contains the type with the
|
||||||
@ -20,10 +19,22 @@ type outer = {
|
|||||||
t: inner
|
t: inner
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86")]
|
#[cfg(target_arch = "x86")]
|
||||||
|
mod m {
|
||||||
|
fn align() -> uint { 4u }
|
||||||
|
fn size() -> uint { 8u }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
mod m {
|
||||||
|
fn align() -> uint { 4u }
|
||||||
|
fn size() -> uint { 8u }
|
||||||
|
}
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
|
|
||||||
let x = {c8: 22u8, t: {c64: 44u64}};
|
let x = {c8: 22u8, t: {c64: 44u32}};
|
||||||
|
|
||||||
// Send it through the shape code
|
// Send it through the shape code
|
||||||
let y = #fmt["%?", x];
|
let y = #fmt["%?", x];
|
||||||
@ -33,14 +44,11 @@ fn main() {
|
|||||||
#debug("y = %s", y);
|
#debug("y = %s", y);
|
||||||
|
|
||||||
// per clang/gcc the alignment of `inner` is 4 on x86.
|
// per clang/gcc the alignment of `inner` is 4 on x86.
|
||||||
assert rusti::min_align_of::<inner>() == 4u;
|
assert rusti::min_align_of::<inner>() == m::align();
|
||||||
|
|
||||||
// per clang/gcc the size of `outer` should be 12
|
// per clang/gcc the size of `outer` should be 12
|
||||||
// because `inner`s alignment was 4.
|
// because `inner`s alignment was 4.
|
||||||
assert sys::size_of::<outer>() == 12u;
|
assert sys::size_of::<outer>() == m::size();
|
||||||
|
|
||||||
assert y == "(22, (44))";
|
assert y == "(22, (44))";
|
||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
|
||||||
fn main() { }
|
|
68
src/test/run-pass/rec-align-u64.rs
Normal file
68
src/test/run-pass/rec-align-u64.rs
Normal file
@ -0,0 +1,68 @@
|
|||||||
|
// xfail-pretty
|
||||||
|
// Issue #2303
|
||||||
|
|
||||||
|
#[abi = "rust-intrinsic"]
|
||||||
|
native mod rusti {
|
||||||
|
fn pref_align_of<T>() -> uint;
|
||||||
|
fn min_align_of<T>() -> uint;
|
||||||
|
}
|
||||||
|
|
||||||
|
// This is the type with the questionable alignment
|
||||||
|
type inner = {
|
||||||
|
c64: u64
|
||||||
|
};
|
||||||
|
|
||||||
|
// This is the type that contains the type with the
|
||||||
|
// questionable alignment, for testing
|
||||||
|
type outer = {
|
||||||
|
c8: u8,
|
||||||
|
t: inner
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#[cfg(target_os = "linux")]
|
||||||
|
#[cfg(target_os = "macos")]
|
||||||
|
#[cfg(target_os = "freebsd")]
|
||||||
|
mod m {
|
||||||
|
#[cfg(target_arch = "x86")]
|
||||||
|
mod m {
|
||||||
|
fn align() -> uint { 4u }
|
||||||
|
fn size() -> uint { 12u }
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
mod m {
|
||||||
|
fn align() -> uint { 8u }
|
||||||
|
fn size() -> uint { 16u }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(target_os = "win32")]
|
||||||
|
mod m {
|
||||||
|
#[cfg(target_arch = "x86")]
|
||||||
|
mod m {
|
||||||
|
fn align() -> uint { 8u }
|
||||||
|
fn size() -> uint { 16u }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn main() {
|
||||||
|
|
||||||
|
let x = {c8: 22u8, t: {c64: 44u64}};
|
||||||
|
|
||||||
|
// Send it through the shape code
|
||||||
|
let y = #fmt["%?", x];
|
||||||
|
|
||||||
|
#debug("align inner = %?", rusti::min_align_of::<inner>());
|
||||||
|
#debug("size outer = %?", sys::size_of::<outer>());
|
||||||
|
#debug("y = %s", y);
|
||||||
|
|
||||||
|
// per clang/gcc the alignment of `inner` is 4 on x86.
|
||||||
|
assert rusti::min_align_of::<inner>() == m::m::align();
|
||||||
|
|
||||||
|
// per clang/gcc the size of `outer` should be 12
|
||||||
|
// because `inner`s alignment was 4.
|
||||||
|
assert sys::size_of::<outer>() == m::m::size();
|
||||||
|
|
||||||
|
assert y == "(22, (44))";
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user