summaryrefslogtreecommitdiff
path: root/libffi/testsuite/libffi.call/struct1_win32.c
diff options
context:
space:
mode:
authorktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4>2012-01-29 13:29:53 +0000
committerktietz <ktietz@138bc75d-0d04-0410-961f-82ee72b054a4>2012-01-29 13:29:53 +0000
commit3e6bf5fe04413ffdcf981bf74684309cb7cf6800 (patch)
tree07d8149ae6b2c61efbc0e6687a4213386743e439 /libffi/testsuite/libffi.call/struct1_win32.c
parente9602c2c334b3dc14c704c09f2c546ac56c6889c (diff)
* src/libffi/src/x86/ffi.c (ffi_call_win32): Add new
argument to prototype for specify calling-convention. (ffi_call): Add support for stdcall/thiscall convention. (ffi_prep_args): Likewise. (ffi_raw_call): Likewise. * src/x86/ffitarget.h (ffi_abi): Add FFI_THISCALL and FFI_FASTCALL. * src/x86/win32.S (_ffi_call_win32): Add support for fastcall/thiscall calling-convention calls. * testsuite/libffi.call/fastthis1_win32.c: New test. * testsuite/libffi.call/fastthis2_win32.c: New test. * testsuite/libffi.call/fastthis3_win32.c: New test. * testsuite/libffi.call/strlen2_win32.c: New test. * testsuite/libffi.call/many2_win32.c: New test. * testsuite/libffi.call/struct1_win32.c: New test. * testsuite/libffi.call/struct2_win32.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@183676 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libffi/testsuite/libffi.call/struct1_win32.c')
-rw-r--r--libffi/testsuite/libffi.call/struct1_win32.c65
1 files changed, 65 insertions, 0 deletions
diff --git a/libffi/testsuite/libffi.call/struct1_win32.c b/libffi/testsuite/libffi.call/struct1_win32.c
new file mode 100644
index 000000000000..4a7eb9444bd4
--- /dev/null
+++ b/libffi/testsuite/libffi.call/struct1_win32.c
@@ -0,0 +1,65 @@
+/* Area: ffi_call
+ Purpose: Check structures with fastcall/thiscall convention.
+ Limitations: none.
+ PR: none.
+ Originator: From the original ffitest.c */
+
+/* { dg-do run { target i?86-*-cygwin* i?86-*-mingw* } } */
+#include "ffitest.h"
+
+typedef struct
+{
+ unsigned char uc;
+ double d;
+ unsigned int ui;
+} test_structure_1;
+
+static __attribute__ ((fastcall)) test_structure_1 struct1(test_structure_1 ts)
+{
+ ts.uc++;
+ ts.d--;
+ ts.ui++;
+
+ return ts;
+}
+
+int main (void)
+{
+ ffi_cif cif;
+ ffi_type *args[MAX_ARGS];
+ void *values[MAX_ARGS];
+ ffi_type ts1_type;
+ ffi_type *ts1_type_elements[4];
+ ts1_type.size = 0;
+ ts1_type.alignment = 0;
+ ts1_type.type = FFI_TYPE_STRUCT;
+ ts1_type.elements = ts1_type_elements;
+ ts1_type_elements[0] = &ffi_type_uchar;
+ ts1_type_elements[1] = &ffi_type_double;
+ ts1_type_elements[2] = &ffi_type_uint;
+ ts1_type_elements[3] = NULL;
+
+ test_structure_1 ts1_arg;
+ /* This is a hack to get a properly aligned result buffer */
+ test_structure_1 *ts1_result =
+ (test_structure_1 *) malloc (sizeof(test_structure_1));
+
+ args[0] = &ts1_type;
+ values[0] = &ts1_arg;
+
+ /* Initialize the cif */
+ CHECK(ffi_prep_cif(&cif, FFI_FASTCALL, 1,
+ &ts1_type, args) == FFI_OK);
+
+ ts1_arg.uc = '\x01';
+ ts1_arg.d = 3.14159;
+ ts1_arg.ui = 555;
+
+ ffi_call(&cif, FFI_FN(struct1), ts1_result, values);
+
+ CHECK(ts1_result->ui == 556);
+ CHECK(ts1_result->d == 3.14159 - 1);
+
+ free (ts1_result);
+ exit(0);
+}