Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions src/rustc/middle/trans/foreign.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 20 additions & 0 deletions src/test/run-pass/issue-3656.rs
Original file line number Diff line number Diff line change
@@ -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() {
}