from Robert Larice, thanks
* support/regression/tests/bitopcse.c,
* support/regression/tests/bitvars.c,
* support/regression/tests/bug-908454.c: use <stdbool.h> 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
+2007-07-11 Maarten Brock <sourceforge.brock AT dse.nl>
+
+ * 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 <stdbool.h> 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 <sourceforge.brock AT dse.nl>
* device/include/stdbool.h: do not define __bool_true_false_are_defined
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;
/* Test CSE with |&^
- type: bit, char, short, long
+ type: bool, char, short, long
*/
#include <testfwk.h>
+#include <stdbool.h>
/* 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
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)
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 == );
#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}
{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);
ASSERT (complement (~_ffff, 0));
#endif
-#endif
+#endif //__bool_true_false_are_defined
}
/* promoting bit to char */
#include <testfwk.h>
+#include <stdbool.h>
-#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
void
testAddFunc(void)
{
-#ifndef SDCC_z80
char buf[5];
unsigned char count = 0;
ASSERT(count == 1 &&
buf[0] == '5' &&
buf[1] == '\0');
-#else
- ASSERT(1);
-#endif
}
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
#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
}
--- /dev/null
+/*\r
+ bug1745717.c\r
+*/\r
+\r
+#include <testfwk.h>\r
+#include <stdbool.h>\r
+\r
+#ifdef __bool_true_false_are_defined\r
+\r
+bool and1(char arg)\r
+{\r
+ return arg & 1;\r
+}\r
+\r
+bool and2(char arg)\r
+{\r
+ return 1 & arg;\r
+}\r
+\r
+#endif //__bool_true_false_are_defined\r
+\r
+\r
+void\r
+testBug(void)\r
+{\r
+#ifdef __bool_true_false_are_defined\r
+ ASSERT(!and1(0x00));\r
+ ASSERT( and1(0x01));\r
+ ASSERT(!and2(0x00));\r
+ ASSERT( and2(0x01));\r
+#endif //__bool_true_false_are_defined\r
+}\r
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;
*/
#include <testfwk.h>
-#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";
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