summaryrefslogtreecommitdiff
path: root/support/regression/tests/funsigned-char.c
blob: 70223f3a404f2f1719d2e932782c13d4486a3b4e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
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
}