aboutsummaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/Makefile14
-rw-r--r--tests/abitest.c63
2 files changed, 60 insertions, 17 deletions
diff --git a/tests/Makefile b/tests/Makefile
index f47ede4..ae5d47d 100644
--- a/tests/Makefile
+++ b/tests/Makefile
@@ -13,7 +13,7 @@ TESTS = \
hello-run \
libtest \
test3 \
- abitest-exe \
+ abitest \
moretests
# test4 -- problem with -static
@@ -180,12 +180,16 @@ asmtest: asmtest.ref
# Check that code generated by libtcc is binary compatible with
# that generated by CC
-abitest$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
- $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir) -g -O0
+abitest-cc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
+ $(CC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
+
+abitest-tcc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
+ $(TCC) -o $@ $^ $(CPPFLAGS) $(CFLAGS) $(NATIVE_DEFINES) $(LIBS) $(LINK_LIBTCC) $(LDFLAGS) -I$(top_srcdir)
-abitest-exe: abitest$(EXESUF)
+abitest: abitest-cc$(EXESUF) abitest-tcc$(EXESUF)
@echo ------------ $@ ------------
- abitest$(EXESUF) lib_path=..
+ abitest-cc$(EXESUF) lib_path=..
+ abitest-tcc$(EXESUF) lib_path=..
# targets for development
%.bin: %.c tcc
diff --git a/tests/abitest.c b/tests/abitest.c
index 51a30ba..90f4cb8 100644
--- a/tests/abitest.c
+++ b/tests/abitest.c
@@ -37,24 +37,62 @@ static int run_callback(const char *src, callback_type callback) {
return result;
}
-typedef struct test1_type_s {int x, y;} test1_type;
-typedef test1_type (*test1_function_type) ();
+/*
+ * reg_pack_test: return a small struct which should be packed into
+ * registers (Win32) during return.
+ */
+typedef struct reg_pack_test_type_s {int x, y;} reg_pack_test_type;
+typedef reg_pack_test_type (*reg_pack_test_function_type) (reg_pack_test_type);
+
+static int reg_pack_test_callback(void *ptr) {
+ reg_pack_test_function_type f = (reg_pack_test_function_type)ptr;
+ reg_pack_test_type a = {10, 35};
+ reg_pack_test_type r;
+ r = f(a);
+ return ((r.x == a.x*5) && (r.y == a.y*3)) ? 0 : -1;
+}
+
+static int reg_pack_test(void) {
+ const char *src =
+ "typedef struct reg_pack_test_type_s {int x, y;} reg_pack_test_type;"
+ "reg_pack_test_type f(reg_pack_test_type a) {\n"
+ " reg_pack_test_type r = {a.x*5, a.y*3};\n"
+ " return r;\n"
+ "}\n";
+
+ return run_callback(src, reg_pack_test_callback);
+}
+
+/*
+ * sret_test: Create a struct large enough to be returned via sret
+ * (hidden pointer as first function argument)
+ */
+typedef struct sret_test_type_s {
+ long long a;
+ long long b;
+} sret_test_type;
+
+typedef sret_test_type (*sret_test_function_type) (sret_test_type);
-static int test1_callback(void *ptr) {
- test1_type r;
- r = ((test1_function_type)ptr)();
- return ((r.x == 10) && (r.y == 35)) ? 0 : -1;
+static int sret_test_callback(void *ptr) {
+ sret_test_function_type f = (sret_test_function_type)(ptr);
+ sret_test_type x = {5436LL, 658277698LL};
+ sret_test_type r = f(x);
+ return ((r.a==x.a*35)&&(r.b==x.b*19)) ? 0 : -1;
}
-static int test1() {
+static int sret_test(void) {
const char *src =
- "typedef struct test1_type_s {int x, y;} test1_type;"
- "test1_type f() {\n"
- " test1_type r = {10, 35};\n"
+ "typedef struct sret_test_type_s {\n"
+ " long long a;\n"
+ " long long b;\n"
+ "} sret_test_type;\n"
+ "sret_test_type f(sret_test_type x) {\n"
+ " sret_test_type r = {x.a*35, x.b*19};\n"
" return r;\n"
"}\n";
- return run_callback(src, test1_callback);
+ return run_callback(src, sret_test_callback);
}
#define RUN_TEST(t) \
@@ -75,6 +113,7 @@ int main(int argc, char **argv) {
if (argc == 2 && !memcmp(argv[1], "lib_path=",9))
tccdir = argv[1] + 9;
- RUN_TEST(test1);
+ RUN_TEST(reg_pack_test);
+ RUN_TEST(sret_test);
return retval;
}