From da9e9f17a450c8e36a7adc88cb55237bcf5baa63 Mon Sep 17 00:00:00 2001 From: michaelh Date: Wed, 1 Aug 2001 03:32:51 +0000 Subject: [PATCH] Added test cases from the bug list git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@1116 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- support/regression/tests/bug-221100.c | 35 ++++++++++++++++++++++ support/regression/tests/bug-221168.c | 19 ++++++++++++ support/regression/tests/bug-221220.c | 42 +++++++++++++++++++++++++++ support/regression/tests/bug-223113.c | 40 ++++++++++--------------- support/regression/tests/bug-227710.c | 30 +++++++++++++++++++ support/regression/tests/bug-408972.c | 5 +--- support/regression/tests/bug-426632.c | 12 ++++---- support/regression/tests/bug-435068.c | 17 +++++++++++ support/regression/tests/bug-441448.c | 26 +++++++++++++++++ 9 files changed, 192 insertions(+), 34 deletions(-) create mode 100644 support/regression/tests/bug-221100.c create mode 100644 support/regression/tests/bug-221168.c create mode 100644 support/regression/tests/bug-221220.c create mode 100644 support/regression/tests/bug-227710.c create mode 100644 support/regression/tests/bug-435068.c create mode 100644 support/regression/tests/bug-441448.c diff --git a/support/regression/tests/bug-221100.c b/support/regression/tests/bug-221100.c new file mode 100644 index 00000000..052b8aa2 --- /dev/null +++ b/support/regression/tests/bug-221100.c @@ -0,0 +1,35 @@ +/* bug-221100.c + + If test_index is char, loses high bit when indexes table + workaround is to use [(unsigned int) test_index] + */ +#include + +static unsigned int +testArray[130]; + +static unsigned int test_int ; +static unsigned char test_index ; + +static void +fetch(void) +{ + test_int = testArray [test_index] ; +} + +static void +testUnsignedCharIndex(void) +{ + int i; + for (i = 0; i < 130; i++) { + testArray[i] = i; + } + + test_index = 5; + fetch(); + ASSERT(test_int == 5); + + test_index = 129; + fetch(); + ASSERT(test_int == 129); +} diff --git a/support/regression/tests/bug-221168.c b/support/regression/tests/bug-221168.c new file mode 100644 index 00000000..623f06b4 --- /dev/null +++ b/support/regression/tests/bug-221168.c @@ -0,0 +1,19 @@ +/* bug-221168.c + */ +#include + +#define XDATA + +XDATA static char x[10][20]; + +XDATA char * +getAddrOfCell(unsigned char y, unsigned char z) +{ + return &x[y][z]; +} + +static void +testMultiDimensionalAddress(void) +{ + ASSERT(getAddrOfCell(5, 6) == (char *)x + 106); +} diff --git a/support/regression/tests/bug-221220.c b/support/regression/tests/bug-221220.c new file mode 100644 index 00000000..91472e12 --- /dev/null +++ b/support/regression/tests/bug-221220.c @@ -0,0 +1,42 @@ +/* bug-221220.c + Or an approximation there of. +*/ +#include + +typedef struct { + int filler; + int value; +} TESTSTRUCT; + +static void +incrementValue(TESTSTRUCT *ps) +{ + ps->value++; +} + +static void +subTestStructVolatile(TESTSTRUCT *ps) +{ + int a, b; + + /* sdcc used to cache the value of ps->value into registers, such + that as a = ps->value and b = ps->value, then a = b. However + if an intervening function uses the structure then ps->value + could change. + */ + a = ps->value; + incrementValue(ps); + b = ps->value; + + ASSERT(a == 7); + ASSERT(b == 8); +} + +static void +testStructVolatile(void) +{ + TESTSTRUCT s; + + s.value = 7; + subTestStructVolatile(&s); +} diff --git a/support/regression/tests/bug-223113.c b/support/regression/tests/bug-223113.c index 82a338c6..aacf1387 100644 --- a/support/regression/tests/bug-223113.c +++ b/support/regression/tests/bug-223113.c @@ -1,33 +1,25 @@ +/* bug-223113.c + PENDING + */ #include -/* - *------------------------------------------------- - */ - int putch( int Ch ) +int putch( int Ch ) { - return( Ch ); + return( Ch ); } - /* - * *------------------------------------------------- - * */ - int puts( char *Str ) + +int puts( char *Str ) { - char *Ptr; + char *Ptr; - for( Ptr = Str; *Ptr != '\0'; Ptr++ ) - { - putch( *Ptr ); - } + for( Ptr = Str; *Ptr != '\0'; Ptr++ ) { + putch( *Ptr ); + } - return( (Ptr - Str) ); + return( (Ptr - Str) ); } - /* - * *-------------------------------------------------- - * */ - void __main( void ) + +void __main( void ) { - puts( "hello world\n" ); -} - /* - * *---------------------------------------------------- - * */ + puts( "hello world\n" ); +} diff --git a/support/regression/tests/bug-227710.c b/support/regression/tests/bug-227710.c new file mode 100644 index 00000000..ccf98a5b --- /dev/null +++ b/support/regression/tests/bug-227710.c @@ -0,0 +1,30 @@ +/* bug-227710.c + */ +#include + +static unsigned char _data[] = { + 1, 2, 3, 4 +}; + +unsigned char *p; + +struct { + unsigned char index; +} s; + +static unsigned char +foo(void) +{ + // BUG, there will be a PRE-increment + return p[s.index++]; +} + +static void +testPostIncrement(void) +{ + p = _data; + ASSERT(foo() == 1); + ASSERT(foo() == 2); + ASSERT(foo() == 3); + ASSERT(foo() == 4); +} diff --git a/support/regression/tests/bug-408972.c b/support/regression/tests/bug-408972.c index ab8ded70..23988240 100644 --- a/support/regression/tests/bug-408972.c +++ b/support/regression/tests/bug-408972.c @@ -11,10 +11,7 @@ long leftShiftLong (long l) { int leftShiftIntMasked (int v) { - /* PENDING: Disabled. - return ((v & 0xff00U) << 3); - */ - return v; + return ((v & 0xff00U) << 3); } int leftShiftIntMasked2 (int v) { diff --git a/support/regression/tests/bug-426632.c b/support/regression/tests/bug-426632.c index 8d29050f..ff9db32b 100644 --- a/support/regression/tests/bug-426632.c +++ b/support/regression/tests/bug-426632.c @@ -1,12 +1,12 @@ +/* bug-436632.c + PENDING +*/ #include typedef struct { - unsigned char year; /* Current - * year (with offset 1900) */ - unsigned char month; /* Month (1 = - * Jan., ..., 12 = Dec.) */ - unsigned char day; /* Day of - * month (1 to 31) */ + unsigned char year; /* Current year (with offset 1900) */ + unsigned char month; /* Month (1 = Jan., ..., 12 = Dec.) */ + unsigned char day; /* Day of month (1 to 31) */ } DATE_STRUCT; unsigned char year; diff --git a/support/regression/tests/bug-435068.c b/support/regression/tests/bug-435068.c new file mode 100644 index 00000000..f6789a4d --- /dev/null +++ b/support/regression/tests/bug-435068.c @@ -0,0 +1,17 @@ +/* bug-435068.c + */ +#include + +char c, d; + +static void +testQuestion(void) +{ + volatile char c, d; + + c = (0x100 & 0x100) ? 4 : 8; // ok + d = ((0x100 & 0x100) ? 4 : 8) + 1; + + ASSERT(c == 4); + ASSERT(d == 5); +} diff --git a/support/regression/tests/bug-441448.c b/support/regression/tests/bug-441448.c new file mode 100644 index 00000000..5ab0ac23 --- /dev/null +++ b/support/regression/tests/bug-441448.c @@ -0,0 +1,26 @@ +/* bug-441448.c + PENDING + */ +#include + +#define DATA + +typedef struct +{ + unsigned char buffer[0x20]; + unsigned char OutPtr, InPtr; + unsigned char Count; +} Fifo; + +DATA Fifo TxFifo={"ABCD", 0, 0, 0}, RxFifo={"FGHI", 0, 0, 0}; +DATA unsigned char dummy1, dummy2; + +void +testPrePostIncrement(void) +{ + dummy2 = TxFifo.buffer[++TxFifo.OutPtr]; + dummy1 = RxFifo.buffer[RxFifo.OutPtr++]; + + ASSERT(dummy2 == 'B'); + ASSERT(dummy1 == 'F'); +} -- 2.30.2