Merge pull request #3716 from Blei/fix-3656

rustc: fix size computation of structs for the FFI
This commit is contained in:
Tim Chevalier
2012-10-17 11:00:36 -07:00
2 changed files with 24 additions and 3 deletions

View File

@@ -112,9 +112,10 @@ fn classify_ty(ty: TypeRef) -> ~[x86_64_reg_class] {
Float => 4,
Double => 8,
Struct => {
do vec::foldl(0, struct_tys(ty)) |s, t| {
s + ty_size(*t)
}
let size = do vec::foldl(0, struct_tys(ty)) |s, t| {
align(s, *t) + ty_size(*t)
};
align(size, ty)
}
Array => {
let len = llvm::LLVMGetArrayLength(ty) as uint;

View File

@@ -0,0 +1,20 @@
// Issue #3656
// Incorrect struct size computation in the FFI, because of not taking
// the alignment of elements into account.
use libc::*;
struct KEYGEN {
hash_algorithm: [c_uint]/2,
count: uint32_t,
salt: *c_void,
salt_size: uint32_t,
}
extern {
// Bogus signature, just need to test if it compiles.
pub fn malloc(++data: KEYGEN);
}
fn main() {
}