Workaround for MinGWs use of 80-bit long double on Win32.

This is incompatible with MSVC and TCC on Win32.

Bounds checking appears to be broken (test4).
master
James Lyon 2013-04-19 23:21:33 +01:00
parent 23f73e92f3
commit 05fa2e754b
2 changed files with 27 additions and 8 deletions

View File

@ -108,20 +108,20 @@ test3: test.ref
test4: test.ref
@echo ------------ $@ ------------
# object + link output
$(TCC) -c -o tcctest3.o tcctest.c
$(TCC) -c -o tcctest3.o $(SRCDIR)/tcctest.c
$(TCC) -o tcctest3 tcctest3.o
./tcctest3 > test3.out
@if diff -u test.ref test3.out ; then echo "Object Auto Test OK"; fi
# dynamic output
$(TCC) -o tcctest1 tcctest.c
$(TCC) -o tcctest1 $(SRCDIR)/tcctest.c
./tcctest1 > test1.out
@if diff -u test.ref test1.out ; then echo "Dynamic Auto Test OK"; fi
# dynamic output + bound check
$(TCC) -b -o tcctest4 tcctest.c
$(TCC) -b -o tcctest4 $(SRCDIR)/tcctest.c
./tcctest4 > test4.out
@if diff -u test.ref test4.out ; then echo "BCheck Auto Test OK"; fi
# static output
$(TCC) -static -o tcctest2 tcctest.c
$(TCC) -static -o tcctest2 $(SRCDIR)/tcctest.c
./tcctest2 > test2.out
@if diff -u test.ref test2.out ; then echo "Static Auto Test OK"; fi
@ -188,8 +188,8 @@ abitest-tcc$(EXESUF): abitest.c $(top_builddir)/$(LIBTCC)
abitest: abitest-cc$(EXESUF) abitest-tcc$(EXESUF)
@echo ------------ $@ ------------
./abitest-cc$(EXESUF) lib_path=..
./abitest-tcc$(EXESUF) lib_path=..
./abitest-cc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
./abitest-tcc$(EXESUF) lib_path=.. include="$(top_srcdir)/include"
# targets for development
%.bin: %.c tcc

View File

@ -4,7 +4,17 @@
#include <string.h>
#include <stdarg.h>
// MinGW has 80-bit rather than 64-bit long double which isn't compatible with TCC or MSVC
#if defined(_WIN32) && defined(__GNUC__)
#define LONG_DOUBLE double
#define LONG_DOUBLE_LITERAL(x) x
#else
#define LONG_DOUBLE long double
#define LONG_DOUBLE_LITERAL(x) x ## L
#endif
static const char *tccdir = NULL;
static const char *include_dir = NULL;
typedef int (*callback_type) (void*);
@ -21,6 +31,10 @@ static int run_callback(const char *src, callback_type callback) {
return -1;
if (tccdir)
tcc_set_lib_path(s, tccdir);
if (include_dir) {
if (tcc_add_include_path(s, include_dir) == -1)
return -1;
}
if (tcc_set_output_type(s, TCC_OUTPUT_MEMORY) == -1)
return -1;
if (tcc_compile_string(s, src) == -1)
@ -38,6 +52,9 @@ static int run_callback(const char *src, callback_type callback) {
return result;
}
#define STR2(x) #x
#define STR(x) STR2(x)
#define RET_PRIMITIVE_TEST(name, type, val) \
static int ret_ ## name ## _test_callback(void *ptr) { \
type (*callback) (type) = (type(*)(type))ptr; \
@ -47,7 +64,7 @@ static int run_callback(const char *src, callback_type callback) {
} \
\
static int ret_ ## name ## _test(void) { \
const char *src = #type " f(" #type " x) {return x+x;}"; \
const char *src = STR(type) " f(" STR(type) " x) {return x+x;}"; \
return run_callback(src, ret_ ## name ## _test_callback); \
}
@ -55,7 +72,7 @@ RET_PRIMITIVE_TEST(int, int, 70000)
RET_PRIMITIVE_TEST(longlong, long long, 4333369356528LL)
RET_PRIMITIVE_TEST(float, float, 63.0)
RET_PRIMITIVE_TEST(double, double, 14789798.0)
RET_PRIMITIVE_TEST(longdouble, long double, 378943892.0)
RET_PRIMITIVE_TEST(longdouble, LONG_DOUBLE, LONG_DOUBLE_LITERAL(378943892.0))
/*
* ret_2float_test:
@ -303,6 +320,8 @@ int main(int argc, char **argv) {
tccdir = argv[i] + 9;
else if (!memcmp(argv[i], "run_test=", 9))
testname = argv[i] + 9;
else if (!memcmp(argv[i], "include=", 8))
include_dir = argv[i] + 8;
}
RUN_TEST(ret_int_test);