Closed
Description
packed.c:
#include <stdio.h>
struct __attribute__((packed)) Foo {
char a;
short b;
char c;
};
void foo(struct Foo foo) {
printf("%d, %d, %d", foo.a, foo.b, foo.c);
}
ffi.rs
#[packed]
struct Foo {
a: i8,
b: i16,
c: i8,
}
#[link(name = "packed")]
extern {
fn foo(f: Foo);
}
fn main() {
unsafe {
foo(Foo {
a: 1,
b: 2,
c: 3,
});
}
}
Output (different each time when compiled with optimizations):
-96, -32761, 88
This happens because the expected function signature is:
define void @foo(%struct.B* byval nocapture readonly align 8 %b) #0
but rust generates:
declare void @foo({ i64 }) unnamed_addr #0