Merge pull request #3716 from Blei/fix-3656
rustc: fix size computation of structs for the FFI
This commit is contained in:
@@ -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;
|
||||
|
||||
20
src/test/run-pass/issue-3656.rs
Normal file
20
src/test/run-pass/issue-3656.rs
Normal 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() {
|
||||
}
|
||||
Reference in New Issue
Block a user