Skip to content

Commit

Permalink
test for incomplete ccall method declaration behavior for 8-bit integ…
Browse files Browse the repository at this point in the history
…er parameters in clang-compiled code
  • Loading branch information
vtjnash authored and JeffBezanson committed Jan 6, 2013
1 parent 52f3db5 commit 8cfb66f
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
*.dll
*.do
*.o
*.dylib
*.dSYM

*.out

Expand Down
1 change: 1 addition & 0 deletions test/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
/ccall
9 changes: 8 additions & 1 deletion test/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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)

24 changes: 24 additions & 0 deletions test/ccall.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include <stdio.h>

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));
}

3 changes: 3 additions & 0 deletions test/ccall.jl
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions test/extra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ runtests("image")
runtests("gzip")

runtests("perf")
runtests("ccall")

0 comments on commit 8cfb66f

Please sign in to comment.