* src/SDCCsymt.c (compareType): fixed bugs 1738367 and 1745717 with patch
[fw/sdcc] / support / regression / tests / bitvars.c
index 6bcc10494342c1a855d547d642bb2dec866d4c7f..d1ca006b5bd0a4818dea4201b646d06efe44c514 100644 (file)
@@ -1,24 +1,59 @@
 /** Bit vars test.
 
+    type: bool, char, unsigned char, unsigned short, unsigned long
 */
+
 #include <testfwk.h>
+#include <stdbool.h>
 
-#if defined (SDCC_STACK_AUTO) || defined (SDCC_hc08) || defined (SDCC_z80) || defined (PORT_HOST)
-#define NO_BITS
+#ifndef PORT_HOST
+#pragma disable_warning 180 //no warning about using complement on bit/unsigned char
 #endif
 
-#ifndef NO_BITS
-char foo(bit a, bit b, char c)
+#ifdef __bool_true_false_are_defined
+
+#define TYPE_{type}
+
+char foo(bool a, bool b, char c)
 {
   return a + b + c;
 }
-#endif
+
+char complement(bool a, bool b)
+{
+  return (a == b);
+}
+
+{type} _0 = 0, _1 = 1, _ff = 0xFF, _ffff = -1;
+
+#endif //__bool_true_false_are_defined
 
 void
 testBits(void)
 {
-#ifndef NO_BITS
-  bit x = 2;
+#ifdef __bool_true_false_are_defined
+  bool x = 2;
   ASSERT (foo(x,3,4) == 6);
+
+  ASSERT (complement (~_0, 1));
+  ASSERT (complement (~_1, 1));
+
+#if defined TYPE_char
+  ASSERT (complement (~_ff, 0));
+#else
+  ASSERT (complement (~_ff, 1));
 #endif
+
+#if defined TYPE_bool
+  ASSERT (complement (~_ffff, 1));
+#elif defined TYPE_char
+  ASSERT (complement (~_ffff, 0));
+#else
+  if (sizeof({type}) < sizeof(int))
+    ASSERT (complement (~_ffff, 1));
+  else
+    ASSERT (complement (~_ffff, 0));
+#endif
+
+#endif //__bool_true_false_are_defined
 }