OSDN Git Service

testsuite/
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.c-torture / execute / 20040311-1.c
1 /* Copyright (C) 2004 Free Software Foundation.
2
3    Check that constant folding and RTL simplification of -(x >> y) doesn't
4    break anything and produces the expected results.
5
6    Written by Roger Sayle, 11th March 2004.  */
7
8 extern void abort (void);
9
10 #define INT_BITS  (sizeof(int)*8)
11
12 int test1(int x)
13 {
14   return -(x >> (INT_BITS-1));
15 }
16
17 int test2(unsigned int x)
18 {
19   return -((int)(x >> (INT_BITS-1)));
20 }
21
22 int test3(int x)
23 {
24   int y;
25   y = INT_BITS-1;
26   return -(x >> y);
27 }
28
29 int test4(unsigned int x)
30 {
31   int y;
32   y = INT_BITS-1;
33   return -((int)(x >> y));
34 }
35
36 int main()
37 {
38   if (test1(0) != 0)
39     abort ();
40   if (test1(1) != 0)
41     abort ();
42   if (test1(-1) != 1)
43     abort ();
44
45   if (test2(0) != 0)
46     abort ();
47   if (test2(1) != 0)
48     abort ();
49   if (test2((unsigned int)-1) != -1)
50     abort ();
51
52   if (test3(0) != 0)
53     abort ();
54   if (test3(1) != 0)
55     abort ();
56   if (test3(-1) != 1)
57     abort ();
58
59   if (test4(0) != 0)
60     abort ();
61   if (test4(1) != 0)
62     abort ();
63   if (test4((unsigned int)-1) != -1)
64     abort ();
65
66   return 0;
67 }
68