From 8cfb66fd9a96f31d9dcad56ffaeac455ffb68b1e Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Tue, 26 Jun 2012 21:27:41 -0400 Subject: [PATCH] test for incomplete ccall method declaration behavior for 8-bit integer parameters in clang-compiled code --- .gitignore | 2 ++ test/.gitignore | 1 + test/Makefile | 9 ++++++++- test/ccall.c | 24 ++++++++++++++++++++++++ test/ccall.jl | 3 +++ test/extra.jl | 1 + 6 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 test/.gitignore create mode 100644 test/ccall.c create mode 100644 test/ccall.jl diff --git a/.gitignore b/.gitignore index 187cd88651a76..afa5e9c4cee96 100644 --- a/.gitignore +++ b/.gitignore @@ -13,6 +13,8 @@ *.dll *.do *.o +*.dylib +*.dSYM *.out diff --git a/test/.gitignore b/test/.gitignore new file mode 100644 index 0000000000000..00e869a2da043 --- /dev/null +++ b/test/.gitignore @@ -0,0 +1 @@ +/ccall diff --git a/test/Makefile b/test/Makefile index 5376c2a1f9d79..048038a7437cf 100644 --- a/test/Makefile +++ b/test/Makefile @@ -10,7 +10,7 @@ random math functional bigint bigfloat combinatorics \ statistics glpk linprog poly file Rmath remote zlib image \ iostring gzip -$(TESTS) :: +$(TESTS) :: libccall.$(SHLIB_EXT) ccall $(QUIET_JULIA) $(JULIA_EXECUTABLE) ./runtests.jl $@ perf: @@ -25,6 +25,13 @@ benchmark: clean: @$(MAKE) -C perf $@ + -rm -f libccall.${SHLIB_EXT} ccall .PHONY: $(TESTS) perf benchmark clean +libccall.$(SHLIB_EXT): ccall.c + $(CC) $(CFLAGS) $(DEBUGFLAGS) -O3 $< -shared -o $@ $(LDFLAGS) -DCC=$(CC) + +ccall: ccall.c + $(CC) $(CFLAGS) $(DEBUGFLAGS) -O3 $< -o $@ $(LDFLAGS) -DCC=$(CC) + diff --git a/test/ccall.c b/test/ccall.c new file mode 100644 index 0000000000000..dedd7b4827c64 --- /dev/null +++ b/test/ccall.c @@ -0,0 +1,24 @@ +#include + +int xs[300] = {0,0,0,1,0}; + +int __attribute((noinline)) testUcharX(unsigned char x) { + return xs[x]; +} + +#define xstr(s) str(s) +#define str(s) #s +volatile int (*fptr)(unsigned char x); +volatile int a; +volatile int b; + +int main() { + printf("all of the following should be 1 except xs[259] = 0"); + a = 3; + b = 259; + fptr = (volatile int (*)(unsigned char x))&testUcharX; + if ((((long)fptr)&((long)1)<<32) == 1) fptr = NULL; + printf("compiled with: '%s'\nxs[3] = %d\nxs[259] = %d\ntestUcharX(3) = %d\ntestUcharX(%d) = %d\nfptr(3) = %d\nfptr(259) = %d\n", + xstr(CC), xs[a], xs[b], testUcharX(a), b, testUcharX(b), fptr(a), fptr(b)); +} + diff --git a/test/ccall.jl b/test/ccall.jl new file mode 100644 index 0000000000000..7b8b556d3bef5 --- /dev/null +++ b/test/ccall.jl @@ -0,0 +1,3 @@ +ccall_test_func(x) = ccall((:testUcharX, :libccall), Int32, (Int8,), x) +@assert ccall_test_func(3) == 1 +@assert ccall_test_func(259) == 1 diff --git a/test/extra.jl b/test/extra.jl index bd074d31f1925..09a96b015c676 100644 --- a/test/extra.jl +++ b/test/extra.jl @@ -13,3 +13,4 @@ runtests("image") runtests("gzip") runtests("perf") +runtests("ccall")