summaryrefslogtreecommitdiff
path: root/support/regression/tests/funsigned-char.c
diff options
context:
space:
mode:
authorXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
committerXavier ASUS <xavi92psx@gmail.com>2019-10-18 00:31:54 +0200
commit268a53de823a6750d6256ee1fb1e7707b4b45740 (patch)
tree42c1799a9a82b2f7d9790ee9fe181d72a7274751 /support/regression/tests/funsigned-char.c
downloadsdcc-gas-268a53de823a6750d6256ee1fb1e7707b4b45740.tar.gz
sdcc-3.9.0 fork implementing GNU assembler syntax
This fork aims to provide better support for stm8-binutils
Diffstat (limited to 'support/regression/tests/funsigned-char.c')
-rw-r--r--support/regression/tests/funsigned-char.c51
1 files changed, 51 insertions, 0 deletions
diff --git a/support/regression/tests/funsigned-char.c b/support/regression/tests/funsigned-char.c
new file mode 100644
index 0000000..70223f3
--- /dev/null
+++ b/support/regression/tests/funsigned-char.c
@@ -0,0 +1,51 @@
+/*
+ * check for the correct signness of a char constant
+ * (signed versus unsigned)
+ * (indirect via integer promotion)
+ *
+ * Note, the check for the --funsigned-char must be invoked by hand
+ * see the following emacs sexp
+ * (compile "SDCCFLAGS=--funsigned-char make -C .. ALL_TESTS='./tests/funsigned-char.c'")
+ * (compile "make -C .. ALL_TESTS='./tests/funsigned-char.c'")
+ *
+ */
+
+#include <testfwk.h>
+#include <stdint.h>
+#include <limits.h>
+
+int glb_schar_to_int = ~ (signed char) '\200';
+int glb_uchar_to_int = ~ (unsigned char) '\200';
+int glb_char_to_int = ~ '\200';
+
+int tst_schar_to_int() { return ~ (signed char) '\200'; }
+int tst_uchar_to_int() { return ~ (unsigned char) '\200'; }
+int tst_char_to_int() { return ~ '\200'; }
+
+
+void
+testBug(void)
+{
+#if CHAR_MIN >= 0
+ ASSERT(CHAR_MAX == 255);
+ ASSERT(CHAR_MIN == 0);
+#else
+ ASSERT(CHAR_MAX == 127);
+ ASSERT(CHAR_MIN == -128);
+#endif
+
+ ASSERT(tst_uchar_to_int() == -129);
+ ASSERT(glb_uchar_to_int == -129);
+
+ ASSERT(tst_schar_to_int() == 127);
+ ASSERT(glb_schar_to_int == 127);
+
+#if CHAR_MIN >= 0
+ ASSERT(tst_char_to_int() == -129);
+ ASSERT(glb_char_to_int == -129);
+#else
+ ASSERT(tst_char_to_int() == 127);
+ ASSERT(glb_char_to_int == 127);
+#endif
+}
+