aboutsummaryrefslogtreecommitdiff
path: root/libffi/src/ffitest.c
diff options
context:
space:
mode:
authorBo Thorsen <bo@suse.de>2002-07-18 23:08:31 +0000
committerBo Thorsen <bo@suse.de>2002-07-18 23:08:31 +0000
commit0bbe55725c2a470ec62c11f7363d60d6bcff8f84 (patch)
tree31860a62cf64b5a75a76259340d1e0a1ac48ef45 /libffi/src/ffitest.c
parent99690cb4fff60370e60d8cdc08aa9009dc7d1dda (diff)
2002-07-16 Bo Thorsen <bo@suse.de>
* src/x86/ffi64.c: New file that adds x86-64 support. * src/x86/unix64.S: New file that handles argument setup for x86-64. * src/x86/sysv.S: Don't use this on x86-64. * src/x86/ffi.c: Don't use this on x86-64. Remove unused vars. * src/prep_cif.c (ffi_prep_cif): Don't do stack size calculation for x86-64. * src/ffitest.c (struct6): New test that tests a special case in the x86-64 ABI. (struct7): Likewise. (struct8): Likewise. (struct9): Likewise. (closure_test_fn): Silence warning about this when it's not used. (main): Add the new tests. (main): Fix a couple of wrong casts and silence some compiler warnings. * include/ffi.h.in: Add x86-64 ABI definition. * fficonfig.h.in: Regenerate. * Makefile.am: Add x86-64 support. * configure.in: Likewise. * Makefile.in: Regenerate. * configure: Likewise. 2002-06-24 Bo Thorsen <bo@suse.de> * src/types.c: Merge settings for similar architectures. Add x86-64 sizes and alignments. 2002-06-23 Bo Thorsen <bo@suse.de> * src/arm/ffi.c (ffi_prep_args): Remove unused vars. * src/sparc/ffi.c (ffi_prep_args_v8): Likewise. * src/mips/ffi.c (ffi_prep_args): Likewise. * src/m68k/ffi.c (ffi_prep_args): Likewise. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@55571 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'libffi/src/ffitest.c')
-rw-r--r--libffi/src/ffitest.c279
1 files changed, 266 insertions, 13 deletions
diff --git a/libffi/src/ffitest.c b/libffi/src/ffitest.c
index ba47ba408d1..8d72df1cc03 100644
--- a/libffi/src/ffitest.c
+++ b/libffi/src/ffitest.c
@@ -153,6 +153,33 @@ typedef struct
char c2;
} test_structure_5;
+typedef struct
+{
+ float f;
+ double d;
+} test_structure_6;
+
+typedef struct
+{
+ float f1;
+ float f2;
+ double d;
+} test_structure_7;
+
+typedef struct
+{
+ float f1;
+ float f2;
+ float f3;
+ float f4;
+} test_structure_8;
+
+typedef struct
+{
+ float f;
+ int i;
+} test_structure_9;
+
static test_structure_1 struct1(test_structure_1 ts)
{
/*@-type@*/
@@ -194,15 +221,52 @@ static test_structure_5 struct5(test_structure_5 ts1, test_structure_5 ts2)
return ts1;
}
+static test_structure_6 struct6 (test_structure_6 ts)
+{
+ ts.f += 1;
+ ts.d += 1;
+
+ return ts;
+}
+
+static test_structure_7 struct7 (test_structure_7 ts)
+{
+ ts.f1 += 1;
+ ts.f2 += 1;
+ ts.d += 1;
+
+ return ts;
+}
+
+static test_structure_8 struct8 (test_structure_8 ts)
+{
+ ts.f1 += 1;
+ ts.f2 += 1;
+ ts.f3 += 1;
+ ts.f4 += 1;
+
+ return ts;
+}
+
+static test_structure_9 struct9 (test_structure_9 ts)
+{
+ ts.f += 1;
+ ts.i += 1;
+
+ return ts;
+}
+
/* Take an int and a float argument, together with int userdata, and */
/* return the sum. */
-static void closure_test_fn(ffi_cif* cif,void* resp,void** args, void* userdata)
+#if FFI_CLOSURES
+static void
+closure_test_fn(ffi_cif* cif,void* resp,void** args, void* userdata)
{
- *(int*)resp =
- *(int *)args[0] + (int)(*(float *)args[1]) + (int)(long)userdata;
+ *(int*)resp = *(int*)args[0] + (int)(*(float*)args[1]) + (int)(long)userdata;
}
typedef int (*closure_test_type)(int, float);
+#endif
int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
{
@@ -230,11 +294,19 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
ffi_type ts3_type;
ffi_type ts4_type;
ffi_type ts5_type;
+ ffi_type ts6_type;
+ ffi_type ts7_type;
+ ffi_type ts8_type;
+ ffi_type ts9_type;
ffi_type *ts1_type_elements[4];
ffi_type *ts2_type_elements[3];
ffi_type *ts3_type_elements[2];
ffi_type *ts4_type_elements[4];
ffi_type *ts5_type_elements[3];
+ ffi_type *ts6_type_elements[3];
+ ffi_type *ts7_type_elements[4];
+ ffi_type *ts8_type_elements[5];
+ ffi_type *ts9_type_elements[3];
ts1_type.size = 0;
ts1_type.alignment = 0;
@@ -256,12 +328,32 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
ts5_type.alignment = 0;
ts5_type.type = FFI_TYPE_STRUCT;
+ ts6_type.size = 0;
+ ts6_type.alignment = 0;
+ ts6_type.type = FFI_TYPE_STRUCT;
+
+ ts7_type.size = 0;
+ ts7_type.alignment = 0;
+ ts7_type.type = FFI_TYPE_STRUCT;
+
+ ts8_type.size = 0;
+ ts8_type.alignment = 0;
+ ts8_type.type = FFI_TYPE_STRUCT;
+
+ ts9_type.size = 0;
+ ts9_type.alignment = 0;
+ ts9_type.type = FFI_TYPE_STRUCT;
+
/*@-immediatetrans@*/
ts1_type.elements = ts1_type_elements;
ts2_type.elements = ts2_type_elements;
ts3_type.elements = ts3_type_elements;
ts4_type.elements = ts4_type_elements;
ts5_type.elements = ts5_type_elements;
+ ts6_type.elements = ts6_type_elements;
+ ts7_type.elements = ts7_type_elements;
+ ts8_type.elements = ts8_type_elements;
+ ts9_type.elements = ts9_type_elements;
/*@=immediatetrans@*/
ts1_type_elements[0] = &ffi_type_uchar;
@@ -285,6 +377,25 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
ts5_type_elements[1] = &ffi_type_schar;
ts5_type_elements[2] = NULL;
+ ts6_type_elements[0] = &ffi_type_float;
+ ts6_type_elements[1] = &ffi_type_double;
+ ts6_type_elements[2] = NULL;
+
+ ts7_type_elements[0] = &ffi_type_float;
+ ts7_type_elements[1] = &ffi_type_float;
+ ts7_type_elements[2] = &ffi_type_double;
+ ts7_type_elements[3] = NULL;
+
+ ts8_type_elements[0] = &ffi_type_float;
+ ts8_type_elements[1] = &ffi_type_float;
+ ts8_type_elements[2] = &ffi_type_float;
+ ts8_type_elements[3] = &ffi_type_float;
+ ts8_type_elements[4] = NULL;
+
+ ts9_type_elements[0] = &ffi_type_float;
+ ts9_type_elements[1] = &ffi_type_sint;
+ ts9_type_elements[2] = NULL;
+
ul = 0;
/* return value tests */
@@ -326,7 +437,7 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
{
ul++;
ffi_call(&cif, FFI_FN(return_sc), &rint, values);
- CHECK(rint == (int) sc);
+ CHECK(rint == (ffi_arg) sc);
}
args[0] = &ffi_type_uchar;
@@ -413,7 +524,7 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
ffi_call(&cif, FFI_FN(floating), &rint, values);
- printf ("%d vs %d\n", rint, floating (si1, f, d, ld, si2));
+ printf ("%d vs %d\n", (int)rint, floating (si1, f, d, ld, si2));
CHECK(rint == floating(si1, f, d, ld, si2));
@@ -483,7 +594,7 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
&ffi_type_float, args) == FFI_OK);
/*@-usedef@*/
- ff = many(fa[0], fa[1],
+ ff = many (fa[0], fa[1],
fa[2], fa[3],
fa[4], fa[5],
fa[6], fa[7],
@@ -532,7 +643,8 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
{
ul++;
ffi_call(&cif, FFI_FN(promotion), &rint, values);
- CHECK(rint == (int) sc + (int) ss + (int) uc + (int) us);
+ CHECK((int)rint == (signed char) sc + (signed short) ss +
+ (unsigned char) uc + (unsigned short) us);
}
printf("%lu promotion tests run\n", ul);
}
@@ -579,8 +691,7 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
values[0] = &ts2_arg;
/* Initialize the cif */
- CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
- &ts2_type, args) == FFI_OK);
+ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts2_type, args) == FFI_OK);
ts2_arg.d1 = 5.55;
ts2_arg.d2 = 6.66;
@@ -647,8 +758,7 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
values[0] = &ts4_arg;
/* Initialize the cif */
- CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1,
- &ts4_type, args) == FFI_OK);
+ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts4_type, args) == FFI_OK);
ts4_arg.ui1 = 2;
ts4_arg.ui2 = 3;
@@ -678,8 +788,7 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
values[1] = &ts5_arg2;
/* Initialize the cif */
- CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2,
- &ts5_type, args) == FFI_OK);
+ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 2, &ts5_type, args) == FFI_OK);
ts5_arg1.c1 = 2;
ts5_arg1.c2 = 6;
@@ -697,6 +806,150 @@ int main(/*@unused@*/ int argc, /*@unused@*/ char *argv[])
free (ts5_result);
}
+ /* struct tests */
+ {
+ test_structure_6 ts6_arg;
+
+ /* This is a hack to get a properly aligned result buffer */
+ test_structure_6 *ts6_result =
+ (test_structure_6 *) malloc (sizeof(test_structure_6));
+
+ args[0] = &ts6_type;
+ values[0] = &ts6_arg;
+
+ /* Initialize the cif */
+ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts6_type, args) == FFI_OK);
+
+ ts6_arg.f = 5.55f;
+ ts6_arg.d = 6.66;
+
+ printf ("%g\n", ts6_arg.f);
+ printf ("%g\n", ts6_arg.d);
+
+ ffi_call(&cif, FFI_FN(struct6), ts6_result, values);
+
+ printf ("%g\n", ts6_result->f);
+ printf ("%g\n", ts6_result->d);
+
+ CHECK(ts6_result->f == 5.55f + 1);
+ CHECK(ts6_result->d == 6.66 + 1);
+
+ printf("structure test 6 ok!\n");
+
+ free (ts6_result);
+ }
+
+ /* struct tests */
+ {
+ test_structure_7 ts7_arg;
+
+ /* This is a hack to get a properly aligned result buffer */
+ test_structure_7 *ts7_result =
+ (test_structure_7 *) malloc (sizeof(test_structure_7));
+
+ args[0] = &ts7_type;
+ values[0] = &ts7_arg;
+
+ /* Initialize the cif */
+ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts7_type, args) == FFI_OK);
+
+ ts7_arg.f1 = 5.55f;
+ ts7_arg.f2 = 55.5f;
+ ts7_arg.d = 6.66;
+
+ printf ("%g\n", ts7_arg.f1);
+ printf ("%g\n", ts7_arg.f2);
+ printf ("%g\n", ts7_arg.d);
+
+ ffi_call(&cif, FFI_FN(struct7), ts7_result, values);
+
+ printf ("%g\n", ts7_result->f1);
+ printf ("%g\n", ts7_result->f2);
+ printf ("%g\n", ts7_result->d);
+
+ CHECK(ts7_result->f1 == 5.55f + 1);
+ CHECK(ts7_result->f2 == 55.5f + 1);
+ CHECK(ts7_result->d == 6.66 + 1);
+
+ printf("structure test 7 ok!\n");
+
+ free (ts7_result);
+ }
+
+ /* struct tests */
+ {
+ test_structure_8 ts8_arg;
+
+ /* This is a hack to get a properly aligned result buffer */
+ test_structure_8 *ts8_result =
+ (test_structure_8 *) malloc (sizeof(test_structure_8));
+
+ args[0] = &ts8_type;
+ values[0] = &ts8_arg;
+
+ /* Initialize the cif */
+ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts8_type, args) == FFI_OK);
+
+ ts8_arg.f1 = 5.55f;
+ ts8_arg.f2 = 55.5f;
+ ts8_arg.f3 = -5.55f;
+ ts8_arg.f4 = -55.5f;
+
+ printf ("%g\n", ts8_arg.f1);
+ printf ("%g\n", ts8_arg.f2);
+ printf ("%g\n", ts8_arg.f3);
+ printf ("%g\n", ts8_arg.f4);
+
+ ffi_call(&cif, FFI_FN(struct8), ts8_result, values);
+
+ printf ("%g\n", ts8_result->f1);
+ printf ("%g\n", ts8_result->f2);
+ printf ("%g\n", ts8_result->f3);
+ printf ("%g\n", ts8_result->f4);
+
+ CHECK(ts8_result->f1 == 5.55f + 1);
+ CHECK(ts8_result->f2 == 55.5f + 1);
+ CHECK(ts8_result->f3 == -5.55f + 1);
+ CHECK(ts8_result->f4 == -55.5f + 1);
+
+ printf("structure test 8 ok!\n");
+
+ free (ts8_result);
+ }
+
+ /* struct tests */
+ {
+ test_structure_9 ts9_arg;
+
+ /* This is a hack to get a properly aligned result buffer */
+ test_structure_9 *ts9_result =
+ (test_structure_9 *) malloc (sizeof(test_structure_9));
+
+ args[0] = &ts9_type;
+ values[0] = &ts9_arg;
+
+ /* Initialize the cif */
+ CHECK(ffi_prep_cif(&cif, FFI_DEFAULT_ABI, 1, &ts9_type, args) == FFI_OK);
+
+ ts9_arg.f = 5.55f;
+ ts9_arg.i = 5;
+
+ printf ("%g\n", ts9_arg.f);
+ printf ("%d\n", ts9_arg.i);
+
+ ffi_call(&cif, FFI_FN(struct9), ts9_result, values);
+
+ printf ("%g\n", ts9_result->f);
+ printf ("%d\n", ts9_result->i);
+
+ CHECK(ts9_result->f == 5.55f + 1);
+ CHECK(ts9_result->i == 5 + 1);
+
+ printf("structure test 9 ok!\n");
+
+ free (ts9_result);
+ }
+
#else
printf("Structure passing doesn't work on Win32.\n");
#endif /* X86_WIN32 */