# HG changeset patch # User Maxim Dounin # Date 1313518197 -14400 # Node ID e0a26cc60a2058b02f4e77e7d1d9d14abf83867a Test for solaris cc bug with bit-fields. With "cc -fast" (or, rather, "cc -xalias_level=basic -xO3", implied by "cc -fast") solaris cc compiles incorrect code for bit-field accesses, notably not rechecking data after functions calls in some situations. Using "-xalias_level=any" resolves the problem (as well as using any non-bit-field type). Tested cc version is "Sun C 5.9 SunOS_i386 2007/05/03" (Sun Studio 12). diff --git a/Makefile b/Makefile new file mode 100644 --- /dev/null +++ b/Makefile @@ -0,0 +1,21 @@ + +FAST= -fast +#FAST= -xalias_level=basic -xO3 + +# no bug seen with: +#FAST= -fast -xalias_level=any + +test: t + ./t + +clean: + rm t *.o + +t: t.o t2.o + cc -o t t.o t2.o ${FAST} + +t.o: t.c t.h + cc -c t.c ${FAST} + +t2.o: t2.c t.h + cc -c t2.c ${FAST} diff --git a/t.c b/t.c new file mode 100644 --- /dev/null +++ b/t.c @@ -0,0 +1,19 @@ + +#include +#include "t.h" + +int +main(void) +{ + test t; + + doinstall(); + + if (dotest(&t) == 0) { + printf("ok\n"); + return 0; + } + + printf("not ok\n"); + return 1; +} diff --git a/t.h b/t.h new file mode 100644 --- /dev/null +++ b/t.h @@ -0,0 +1,7 @@ + +typedef struct { + unsigned bit:1; +} test; + +void doinstall(); +int dotest(test *t); diff --git a/t2.c b/t2.c new file mode 100644 --- /dev/null +++ b/t2.c @@ -0,0 +1,32 @@ + +#include "t.h" + + +void (*x)(test *t); + + +void +dosomething(test *t) +{ + t->bit = 1; +} + +void +doinstall() +{ + x = dosomething; +} + +int +dotest(test *t) +{ + t->bit = 0; + + x(t); + + if (t->bit) { + return 0; + } + + return 1; +}