From ab0bc49797431b2747b7e5e37cfb89f8c0dad332 Mon Sep 17 00:00:00 2001 From: MaartenBrock Date: Wed, 11 Jul 2007 14:42:00 +0000 Subject: [PATCH] * src/SDCCsymt.c (compareType): fixed bugs 1738367 and 1745717 with patch from Robert Larice, thanks * support/regression/tests/bitopcse.c, * support/regression/tests/bitvars.c, * support/regression/tests/bug-908454.c: use for the bit types * support/regression/tests/bug-927659.c: enabled test for z80 * support/regression/tests/bug1738367.c: added extra tests by Frieder * support/regression/tests/bug1745717.c: new, added * support/regression/tests/literalop.c, * support/regression/tests/nullstring.c: removed storage definitions that are now in testfwk.h git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@4879 4a8a32a2-be11-0410-ad9d-d568d2c75423 --- ChangeLog | 14 ++++++++ src/SDCCsymt.c | 2 +- support/regression/tests/bitopcse.c | 50 ++++++++++++--------------- support/regression/tests/bitvars.c | 18 +++------- support/regression/tests/bug-908454.c | 9 ++--- support/regression/tests/bug-927659.c | 4 --- support/regression/tests/bug1738367.c | 43 +++++++++++++++++++++++ support/regression/tests/bug1745717.c | 32 +++++++++++++++++ support/regression/tests/literalop.c | 5 --- support/regression/tests/nullstring.c | 12 ++----- 10 files changed, 123 insertions(+), 66 deletions(-) create mode 100644 support/regression/tests/bug1745717.c diff --git a/ChangeLog b/ChangeLog index 34dd3781..53f7e6cf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,17 @@ +2007-07-11 Maarten Brock + + * src/SDCCsymt.c (compareType): fixed bugs 1738367 and 1745717 with patch + from Robert Larice, thanks + * support/regression/tests/bitopcse.c, + * support/regression/tests/bitvars.c, + * support/regression/tests/bug-908454.c: use for the bit types + * support/regression/tests/bug-927659.c: enabled test for z80 + * support/regression/tests/bug1738367.c: added extra tests by Frieder + * support/regression/tests/bug1745717.c: new, added + * support/regression/tests/literalop.c, + * support/regression/tests/nullstring.c: removed storage definitions that + are now in testfwk.h + 2007-07-10 Maarten Brock * device/include/stdbool.h: do not define __bool_true_false_are_defined diff --git a/src/SDCCsymt.c b/src/SDCCsymt.c index 8e0f402f..e686c296 100644 --- a/src/SDCCsymt.c +++ b/src/SDCCsymt.c @@ -2136,7 +2136,7 @@ compareType (sym_link * dest, sym_link * src) instead of the next two lines, but the regression tests fail with them; I guess it's a problem with replaceCheaperOp */ getSize (dest) == getSize (src) && - !(!IS_BIT (dest) && IS_BIT (src))) + (IS_BIT (dest) == IS_BIT (src))) return 1; else if (IS_ARITHMETIC (dest) && IS_ARITHMETIC (src)) return -1; diff --git a/support/regression/tests/bitopcse.c b/support/regression/tests/bitopcse.c index 552eadcd..c99fa022 100644 --- a/support/regression/tests/bitopcse.c +++ b/support/regression/tests/bitopcse.c @@ -1,39 +1,41 @@ /* Test CSE with |&^ - type: bit, char, short, long + type: bool, char, short, long */ #include +#include /* This is not only a regression test, the focus of this test is more on the generated code (volatile!). */ -#define _{type} +#define TYPE_{type} +#if defined(TYPE_bool) && !defined(SDCC) +# define UNSIGNED +#else +# define UNSIGNED unsigned +#endif -#if defined(_bit) || defined(SDCC_hc08) +#if defined(TYPE_bool) || defined(SDCC_hc08) # define _data #else # define _data idata #endif -#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) || defined(SDCC_hc08) || defined(SDCC_pic16) -# define NO_BIT_TYPE -#endif - -#if defined(_bit) && !defined(NO_BIT_TYPE) +#if defined(TYPE_bool) && defined(__bool_true_false_are_defined) # define MASK 1 -#elif defined(_bit) && defined(NO_BIT_TYPE) +#elif defined(TYPE_bool) && !defined(__bool_true_false_are_defined) # if defined(PORT_HOST) # define MASK 0xffffffff # else # define MASK 0xffff # endif -# define bit int -#elif defined(_char) +# define bool int +#elif defined(TYPE_char) # define MASK 0xff -#elif defined(_short) +#elif defined(TYPE_short) # define MASK 0xffff -#elif defined(_long) +#elif defined(TYPE_long) # define MASK 0xffffffff #else # warning Unknown type @@ -43,14 +45,14 @@ const unsigned long mask = MASK; volatile {type} v; - volatile unsigned {type} uv; + volatile UNSIGNED {type} uv; /* an array would be nicer, but an array of bits isn't possible */ _data {type} a0 , a1 , a2 , a3 , a4 , a5 , a6 , a7 , a8 , a9 , a10, a11, a12, a13, a14, a15, a16, a17, a18, a19, a20; -_data unsigned {type} ua0, ua1, ua2, ua3, ua4, ua5, ua6; +_data UNSIGNED {type} ua0, ua1, ua2, ua3, ua4, ua5, ua6; _data {type} b; -_data volatile unsigned {type} ub = 0xbe; +_data volatile UNSIGNED {type} ub = 0xbe; void testcse(void) @@ -110,23 +112,17 @@ testcse(void) ASSERT( a0 == 0); ASSERT( a1 == 0); ASSERT( a2 == b); -#if defined(_bit) && !defined(NO_BIT_TYPE) +#if defined(TYPE_bool) && defined(__bool_true_false_are_defined) ASSERT( a3 == 1); -#else - ASSERT( a3 == ({type}) 0x33); -#endif - ASSERT(ua0 == ub); -#if defined(_bit) && !defined(NO_BIT_TYPE) ASSERT(ua1 == 1); -#else - ASSERT(ua1 == ({type}) 0x7b); -#endif - ASSERT( a4 == b); -#if defined(_bit) && !defined(NO_BIT_TYPE) ASSERT( a5 == 1); #else + ASSERT( a3 == ({type}) 0x33); + ASSERT(ua1 == ({type}) 0x7b); ASSERT( a5 == ({type}) 0x33); #endif + ASSERT(ua0 == ub); + ASSERT( a4 == b); ASSERT( a6 == 0); // ASSERT( a7 == ); // ASSERT(ua2 == ); diff --git a/support/regression/tests/bitvars.c b/support/regression/tests/bitvars.c index c40e43eb..d1ca006b 100644 --- a/support/regression/tests/bitvars.c +++ b/support/regression/tests/bitvars.c @@ -10,17 +10,7 @@ #pragma disable_warning 180 //no warning about using complement on bit/unsigned char #endif -#if defined (SDCC_hc08) || defined (SDCC_z80) || defined (SDCC_gbz80) || defined (SDCC_pic14) || defined (SDCC_pic16) -/* sdcc tagrets not supporting bit type */ -#define NO_BITS -#endif - -#if defined (__GNUC__) && defined (__alpha__) && (__GNUC__ < 3) -/* since this fails on GCC 2.95.4 on alpha... */ -#define NO_BITS -#endif - -#ifndef NO_BITS +#ifdef __bool_true_false_are_defined #define TYPE_{type} @@ -36,12 +26,12 @@ char complement(bool a, bool b) {type} _0 = 0, _1 = 1, _ff = 0xFF, _ffff = -1; -#endif +#endif //__bool_true_false_are_defined void testBits(void) { -#ifndef NO_BITS +#ifdef __bool_true_false_are_defined bool x = 2; ASSERT (foo(x,3,4) == 6); @@ -65,5 +55,5 @@ testBits(void) ASSERT (complement (~_ffff, 0)); #endif -#endif +#endif //__bool_true_false_are_defined } diff --git a/support/regression/tests/bug-908454.c b/support/regression/tests/bug-908454.c index fa766aed..009ad534 100644 --- a/support/regression/tests/bug-908454.c +++ b/support/regression/tests/bug-908454.c @@ -1,15 +1,12 @@ /* promoting bit to char */ #include +#include -#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) || defined(SDCC_hc08) || defined(SDCC_pic16) -# define NO_BIT_TYPE -#endif - -#if defined(NO_BIT_TYPE) +#if !defined(__bool_true_false_are_defined) volatile int a = 1, b = 1; #else -volatile bit a = 1, b = 1; +volatile bool a = 1, b = 1; #endif char diff --git a/support/regression/tests/bug-927659.c b/support/regression/tests/bug-927659.c index 5e809a0c..96fc3eb5 100644 --- a/support/regression/tests/bug-927659.c +++ b/support/regression/tests/bug-927659.c @@ -37,7 +37,6 @@ testReverse(void) void testAddFunc(void) { -#ifndef SDCC_z80 char buf[5]; unsigned char count = 0; @@ -45,7 +44,4 @@ testAddFunc(void) ASSERT(count == 1 && buf[0] == '5' && buf[1] == '\0'); -#else - ASSERT(1); -#endif } diff --git a/support/regression/tests/bug1738367.c b/support/regression/tests/bug1738367.c index f9da20e0..c0653575 100644 --- a/support/regression/tests/bug1738367.c +++ b/support/regression/tests/bug1738367.c @@ -12,6 +12,33 @@ bool ternary(unsigned char status) return (status == 0) ? 0 : 1; } +bool ternary_inv(unsigned char status) +{ + return (status == 0) ? 1 : 0; +} + + +bool ternary1(unsigned char status) +{ + return status ? 1 : 0; +} + +bool ternary1_inv(unsigned char status) +{ + return status ? 0 : 1; +} + + +bool ternary2(unsigned char status) +{ + return !status ? 0 : 1; +} + +bool ternary2_inv(unsigned char status) +{ + return !status ? 1 : 0; +} + #endif //__bool_true_false_are_defined @@ -21,5 +48,21 @@ testBug(void) #ifdef __bool_true_false_are_defined ASSERT(!ternary(0x00)); ASSERT( ternary(0x10)); + + ASSERT( ternary_inv(0x00)); + ASSERT(!ternary_inv(0x10)); + + ASSERT(!ternary1(0x00)); + ASSERT( ternary1(0x10)); + + ASSERT( ternary1_inv(0x00)); + ASSERT(!ternary1_inv(0x10)); + + ASSERT(!ternary2(0x00)); + ASSERT( ternary2(0x10)); + + ASSERT( ternary2_inv(0x00)); + ASSERT(!ternary2_inv(0x10)); + ASSERT(!ternary2_inv(1==1)); #endif //__bool_true_false_are_defined } diff --git a/support/regression/tests/bug1745717.c b/support/regression/tests/bug1745717.c new file mode 100644 index 00000000..fef18086 --- /dev/null +++ b/support/regression/tests/bug1745717.c @@ -0,0 +1,32 @@ +/* + bug1745717.c +*/ + +#include +#include + +#ifdef __bool_true_false_are_defined + +bool and1(char arg) +{ + return arg & 1; +} + +bool and2(char arg) +{ + return 1 & arg; +} + +#endif //__bool_true_false_are_defined + + +void +testBug(void) +{ +#ifdef __bool_true_false_are_defined + ASSERT(!and1(0x00)); + ASSERT( and1(0x01)); + ASSERT(!and2(0x00)); + ASSERT( and2(0x01)); +#endif //__bool_true_false_are_defined +} diff --git a/support/regression/tests/literalop.c b/support/regression/tests/literalop.c index ea7bcf86..43262561 100644 --- a/support/regression/tests/literalop.c +++ b/support/regression/tests/literalop.c @@ -14,11 +14,6 @@ typedef signed {type} stype; typedef unsigned {type} utype; -#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) -# define idata -# define code -#endif - volatile char is8 = 8; signed char sc; diff --git a/support/regression/tests/nullstring.c b/support/regression/tests/nullstring.c index 51313c88..0060b8b0 100644 --- a/support/regression/tests/nullstring.c +++ b/support/regression/tests/nullstring.c @@ -4,12 +4,6 @@ */ #include -#if defined(PORT_HOST) || defined(SDCC_z80) || defined(SDCC_gbz80) -# define data -# define xdata -# define code -#endif - {storage} char string1[] = ""; {storage} char string2[] = "a\0b\0c"; {storage} char string3[5] = "a\0b\0c"; @@ -24,11 +18,11 @@ testStringArray(void) ASSERT(sizeof(string3)==5); ASSERT(string1[0]==0); ASSERT(string2[5]==0); - + ASSERT(string2[0]=='a'); ASSERT(string2[2]=='b'); - ASSERT(string2[4]=='c'); - + ASSERT(string2[4]=='c'); + } void -- 2.30.2