diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2021-08-31 07:14:47 -0700 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2021-10-20 05:35:52 -0700 |
commit | 92456a4e5658e138e2cea79e390e3306b07685b0 (patch) | |
tree | 6ef878e933b504a902035f1ae89510fde96a976d /libffi/testsuite/libffi.call/struct10.c | |
parent | d738405e7fe62cc8eb9580948a6ea39005cd7170 (diff) | |
download | gcc-92456a4e5658e138e2cea79e390e3306b07685b0.zip gcc-92456a4e5658e138e2cea79e390e3306b07685b0.tar.gz gcc-92456a4e5658e138e2cea79e390e3306b07685b0.tar.bz2 |
libffi: Sync with libffi 3.4.2
Merged commit: f9ea41683444ebe11cfa45b05223899764df28fb
Diffstat (limited to 'libffi/testsuite/libffi.call/struct10.c')
-rw-r--r-- | libffi/testsuite/libffi.call/struct10.c | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/libffi/testsuite/libffi.call/struct10.c b/libffi/testsuite/libffi.call/struct10.c new file mode 100644 index 0000000..17b1377 --- /dev/null +++ b/libffi/testsuite/libffi.call/struct10.c @@ -0,0 +1,57 @@ +/* Area: ffi_call + Purpose: Check structures. + Limitations: none. + PR: none. + Originator: Sergei Trofimovich <slyfox@gentoo.org> + + The test originally discovered in ruby's bindings + for ffi in https://bugs.gentoo.org/634190 */ + +/* { dg-do run } */ +#include "ffitest.h" + +struct s { + int s32; + float f32; + signed char s8; +}; + +struct s make_s(void) { + struct s r; + r.s32 = 0x1234; + r.f32 = 7.0; + r.s8 = 0x78; + return r; +} + +int main() { + ffi_cif cif; + struct s r; + ffi_type rtype; + ffi_type* s_fields[] = { + &ffi_type_sint, + &ffi_type_float, + &ffi_type_schar, + NULL, + }; + + rtype.size = 0; + rtype.alignment = 0, + rtype.type = FFI_TYPE_STRUCT, + rtype.elements = s_fields, + + r.s32 = 0xbad; + r.f32 = 999.999; + r.s8 = 0x51; + + // Here we emulate the following call: + //r = make_s(); + + CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 0, &rtype, NULL) == FFI_OK); + ffi_call(&cif, FFI_FN(make_s), &r, NULL); + + CHECK(r.s32 == 0x1234); + CHECK(r.f32 == 7.0); + CHECK(r.s8 == 0x78); + exit(0); +} |