1/* Copyright (C) 2002  Free Software Foundation.
2
3   Test that optimizing ((c>=1) && (c<=127)) into (signed char)c < 0
4   doesn't cause any problems for the compiler and behaves correctly.
5
6   Written by Roger Sayle, 8th May 2002.  */
7
8#include <limits.h>
9
10extern void abort (void);
11
12void
13testc (unsigned char c, int ok)
14{
15  if ((c>=1) && (c<=SCHAR_MAX))
16    {
17      if (!ok) abort ();
18    }
19  else
20    if (ok) abort ();
21}
22
23void
24tests (unsigned short s, int ok)
25{
26  if ((s>=1) && (s<=SHRT_MAX))
27    {
28      if (!ok) abort ();
29    }
30  else
31    if (ok) abort ();
32}
33
34void
35testi (unsigned int i, int ok)
36{
37  if ((i>=1) && (i<=INT_MAX))
38    {
39      if (!ok) abort ();
40    }
41  else
42    if (ok) abort ();
43}
44
45void
46testl (unsigned long l, int ok)
47{
48  if ((l>=1) && (l<=LONG_MAX))
49    {
50      if (!ok) abort ();
51    }
52  else
53    if (ok) abort ();
54}
55
56int
57main ()
58{
59  testc (0, 0);
60  testc (1, 1);
61  testc (SCHAR_MAX, 1);
62  testc (SCHAR_MAX+1, 0);
63  testc (UCHAR_MAX, 0);
64
65  tests (0, 0);
66  tests (1, 1);
67  tests (SHRT_MAX, 1);
68  tests (SHRT_MAX+1, 0);
69  tests (USHRT_MAX, 0);
70
71  testi (0, 0);
72  testi (1, 1);
73  testi (INT_MAX, 1);
74  testi (INT_MAX+1U, 0);
75  testi (UINT_MAX, 0);
76
77  testl (0, 0);
78  testl (1, 1);
79  testl (LONG_MAX, 1);
80  testl (LONG_MAX+1UL, 0);
81  testl (ULONG_MAX, 0);
82
83  return 0;
84}
85
86