-/* This file is linked into the runtime for the sole purpose
- * of testing FFI code. */
#include "ffi_test.h"
#include <assert.h>
+#include <stdarg.h>
#include <string.h>
void ffi_test_0(void) {}
}
void ffi_test_20(double x1, double x2, double x3, double y1, double y2,
- double y3, double z1, double z2, double z3) {}
+ double y3, double z1, double z2, double z3) {
+ (void) x1, (void) x2, (void) x3, (void) y1, (void) y2,
+ (void) y3, (void) z1, (void) z2, (void) z3;
+}
long long ffi_test_21(long x, long y) { return (long long) x * (long long) y; }
return x;
}
-struct bool_and_ptr ffi_test_61() {
+/* C99 features */
+#ifndef _MSC_VER
+
+struct bool_and_ptr ffi_test_61(void) {
struct bool_and_ptr bap;
bap.b = true;
bap.ptr = NULL;
return bap;
}
-struct uint_pair ffi_test_62() {
+#endif
+
+struct uint_pair ffi_test_62(void) {
struct uint_pair uip;
uip.a = 0xabcdefab;
uip.b = 0x12345678;
return uip;
}
-struct ulonglong_pair ffi_test_63() {
+struct ulonglong_pair ffi_test_63(void) {
struct ulonglong_pair ullp;
ullp.a = 0xabcdefabcdefabcd;
ullp.b = 0x1234567891234567;
return ullp;
}
+
+int ffi_test_64(int n, ...) {
+ va_list ap;
+ va_start(ap, n);
+ int sum = 0;
+ for (int i = 0; i < n; i++) {
+ sum += va_arg(ap, int);
+ }
+ va_end(ap);
+ return sum;
+}
+
+double ffi_test_65(int n, ...) {
+ va_list ap;
+ va_start(ap, n);
+ double sum = 0.0;
+ for (int i = 0; i < n; i++) {
+ sum += va_arg(ap, double);
+ }
+ va_end(ap);
+ return sum;
+}
+
+unsigned long ffi_test_66(unsigned long a, unsigned long b, unsigned long c,
+ struct test_struct_66 d, struct test_struct_66 e) {
+ unsigned long x;
+ x = a + b + c + d.mem1 + d.mem2 + e.mem1 + e.mem2;
+ return x;
+}
+
+unsigned long ffi_test_67(unsigned long a, unsigned long b, unsigned long c,
+ struct test_struct_66 d, struct test_struct_66 e,
+ unsigned long f) {
+ unsigned long x;
+ x = a + b + c + d.mem1 + d.mem2 + e.mem1 + e.mem2 + f*2;
+ return x;
+}
+
+unsigned long ffi_test_68(unsigned long a, unsigned long b, unsigned long c,
+ struct test_struct_66 d, struct test_struct_68 e, struct test_struct_66 f) {
+ unsigned long x;
+ x = a + b + c + d.mem1 + d.mem2 + e.mem1 + e.mem2 + e.mem3 + f.mem1 + f.mem2;
+ return x;
+}
+
+unsigned long ffi_test_69(unsigned long a, unsigned long b, unsigned long c,
+ struct test_struct_66 d, struct test_struct_69 e, struct test_struct_66 f) {
+ unsigned long x;
+ x = a + b + c + d.mem1 + d.mem2 + (long)e.mem1 + e.mem2 + e.mem3 + f.mem1 + f.mem2;
+ return x;
+}
+
+unsigned long ffi_test_70(struct test_struct_68 a, struct test_struct_68 b, struct test_struct_66 c) {
+ unsigned long x;
+ x = a.mem1 + a.mem2 + a.mem3 + b.mem1 + b.mem2 + b.mem3 + c.mem1 + c.mem2;
+ return x;
+}
+
+
+void* bug1021_test_1(void* x, int y) {
+ return (void*)(y * y + (size_t)x);
+}
+
+int bug1021_test_2(int x, char *y, void *z) {
+ (void) x;
+ (void) z;
+ return y[0];
+}
+
+void* bug1021_test_3(int x) {
+ return (void*)(size_t)((long)x);
+}