OSDN Git Service

PR middle-end/20256
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.dg / builtin-choose-expr.c
1 /* { dg-do run } */
2 /* { dg-options "-O1 -Wall" } */
3
4 #define choose __builtin_choose_expr
5
6 /* Check the type of __builtin_choose_expr between E1 and E2, both
7    ways round and with both 0 and 1 as the condition.  */
8 #define ASSERT_COND_TYPE(E1, E2)                                \
9         do {                                                    \
10           typedef __typeof(E1) T1;                              \
11           typedef __typeof(E2) T2;                              \
12           typedef T1 **T1pp;                                    \
13           typedef T2 **T2pp;                                    \
14           typedef __typeof(choose (1, (E1), (E2))) T1a;         \
15           typedef __typeof(choose (0, (E2), (E1))) T1b;         \
16           typedef __typeof(choose (1, (E2), (E1))) T2a;         \
17           typedef __typeof(choose (0, (E1), (E2))) T2b;         \
18           typedef T1a **T1app;                                  \
19           typedef T1b **T1bpp;                                  \
20           typedef T2a **T2app;                                  \
21           typedef T2b **T2bpp;                                  \
22           T1pp t1 = 0;                                          \
23           T2pp t2 = 0;                                          \
24           T1app t1a = 0;                                        \
25           T1bpp t1b = 0;                                        \
26           T2app t2a = 0;                                        \
27           T2bpp t2b = 0;                                        \
28           t1 = t1a;                                             \
29           t1 = t1b;                                             \
30           t2 = t2a;                                             \
31           t2 = t2b;                                             \
32         } while (0)
33
34
35 extern void abort ();
36 extern void exit ();
37
38 void bad ()
39 {
40   abort ();
41 }
42
43 void good ()
44 {
45   exit (0);
46 }
47
48 int main (void)
49 {
50   signed char sc1, sc2;
51   void *v1;
52   int i, j;
53   double dd;
54   float f;
55   typedef void (*fpt)(void);
56   fpt triple;
57   struct S { int x, y; } pour, some, sugar;
58   union u { int p; } united, nations;
59
60   if (__builtin_choose_expr (0, 12, 0)
61       || !__builtin_choose_expr (45, 5, 0)
62       || !__builtin_choose_expr (45, 3, 0))
63     abort ();
64
65   ASSERT_COND_TYPE (sc1, sc2);
66   ASSERT_COND_TYPE (v1, sc1);
67   ASSERT_COND_TYPE (i, j);
68   ASSERT_COND_TYPE (dd, main);
69   ASSERT_COND_TYPE ((float)dd, i);
70   ASSERT_COND_TYPE (4, f);
71   ASSERT_COND_TYPE (triple, some);
72   ASSERT_COND_TYPE (united, nations);
73   ASSERT_COND_TYPE (nations, main);
74
75   pour.y = 69;
76   __builtin_choose_expr (0, bad (), sugar) = pour;
77   if (sugar.y != 69)
78     abort ();
79
80   __builtin_choose_expr (sizeof (int), f, bad ()) = 3.5F;
81
82   if (f != 3.5F)
83     abort ();
84
85   __builtin_choose_expr (1, good, bad)();
86
87   exit (0);
88 }