OSDN Git Service

31426a3279a0070d4313214ffb0869e727ae3139
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.c-torture / execute / 20111208-1.c
1 /* PR tree-optimization/51315 */
2 /* Reported by Jurij Smakov <jurij@wooyd.org> */
3
4 typedef unsigned int size_t;
5
6 extern void *memcpy (void *__restrict __dest,
7        __const void *__restrict __src, size_t __n)
8      __attribute__ ((__nothrow__)) __attribute__ ((__nonnull__ (1, 2)));
9
10 extern size_t strlen (__const char *__s)
11      __attribute__ ((__nothrow__)) __attribute__ ((__pure__)) __attribute__ ((__nonnull__ (1)));
12
13 #if __SIZEOF_SHORT__ == 2
14 typedef short int int16_t;
15 #elif __SIZEOF_INT__ == 2
16 typedef int int16_t;
17 #elif __SIZEOF_LONG__ == 2
18 typedef long int16_t;
19 #else
20 #error Fix this
21 #endif
22
23
24 #if __SIZEOF_INT__ == 4
25 typedef int int32_t;
26 #elif __SIZEOF_LONG__ == 4
27 typedef long int32_t;
28 #elif __SIZEOF_SHORT__ == 4
29 typedef short int32_t;
30 #else
31 #error Fix this
32 #endif
33
34 extern void abort (void);
35
36 int a;
37
38 static void __attribute__ ((noinline,noclone))
39 do_something (int item)
40 {
41   a = item;
42 }
43
44 int
45 pack_unpack (char *s, char *p)
46 {
47   char *send, *pend;
48   char type;
49   int integer_size;
50
51   send = s + strlen (s);
52   pend = p + strlen (p);
53
54   while (p < pend)
55     {
56       type = *p++;
57
58       switch (type)
59  {
60  case 's':
61    integer_size = 2;
62    goto unpack_integer;
63
64  case 'l':
65    integer_size = 4;
66    goto unpack_integer;
67
68  unpack_integer:
69    switch (integer_size)
70      {
71      case 2:
72        {
73   union
74   {
75     int16_t i;
76     char a[sizeof (int16_t)];
77   }
78   v;
79   memcpy (v.a, s, sizeof (int16_t));
80   s += sizeof (int16_t);
81   do_something (v.i);
82        }
83        break;
84
85      case 4:
86        {
87   union
88   {
89     int32_t i;
90     char a[sizeof (int32_t)];
91   }
92   v;
93   memcpy (v.a, s, sizeof (int32_t));
94   s += sizeof (int32_t);
95   do_something (v.i);
96        }
97        break;
98      }
99    break;
100  }
101     }
102   return (int) *s;
103 }
104
105 int
106 main (void)
107 {
108   int n = pack_unpack ("\200\001\377\376\035\300", "sl");
109   if (n != 0)
110     abort ();
111   return 0;
112 }