Make ICC more happy by spelling -f combo as -fcombo, so it can properly ignore "combo...
[libfirm] / ir / be / test / if.c
1 #include <stdio.h>
2 #include <assert.h>
3
4 int test1(int a)
5 {
6         return a == 0;
7 }
8
9 int test2(int a, int b)
10 {
11         return a == b;
12 }
13
14 int test2a(int a, int b)
15 {
16         return a != b;
17 }
18
19 int test3(int a, int b)
20 {
21         return a == 0 && b + 1 < 10;
22 }
23
24 int test4(int a, int b)
25 {
26         return a == 0 || b + 1 < 10;
27 }
28
29 int test5(int a, int b)
30 {
31         return a > b ? a : b - 1;
32 }
33
34 int test6(int a, int b)
35 {
36         return a < 0 ? -1 : (a > 0 ? 1 : 0);
37 }
38
39 int test6a(int a, int b)
40 {
41         if(a < b)
42                 ;
43         else
44                 ;
45
46         return 0;
47 }
48
49 int test7(int a, int b)
50 {
51         int i, res = 0;
52
53         for(i = 0; i < a; ++i)
54                 res += i * b;
55
56         return res;
57 }
58
59 int test8(int a, int b, int c)
60 {
61         return a < b ? (a < c ? a : c) : (b < c ? b : c);
62 }
63
64 int test9(int a, int b)
65 {
66         return a ? b : b;
67 }
68
69 int testam(int a, int b, int c)
70 {
71         if(a < 42)
72                 return b;
73         else
74                 return c;
75 }
76
77 int main()
78 {
79 #define TU(t,a,s)       printf("%s(%d) = %d (should be %d)\n", \
80                            #t, a, t(a), s); \
81                     assert(t(a) == s);
82
83 #define TB(t,a,b,s)     printf("%s(%d,%d) = %d (should be %d)\n", \
84                             #t, a, b, t(a,b), s); \
85                     assert(t(a,b) == s);
86
87 #define TT(t,a,b,c,s)   printf("%s(%d,%d,%d) = %d (should be %d)\n", \
88                             #t, a, b, c, t(a,b,c), s); \
89                     assert(t(a,b,c) == s);
90
91
92         TU(test1, 0, 1);
93         TU(test1, 42, 0);
94
95         TB(test2, 0, 0, 1);
96         TB(test2, -23, -23, 1);
97         TB(test2, 0, 42, 0);
98         TB(test2, -1, 0, 0);
99
100         TB(test2a, 0, 0, 0);
101         TB(test2a, -23, -23, 0);
102         TB(test2a, 0, 42, 1);
103         TB(test2a, -1, 0, 1);
104
105         TB(test3, 0, 8, 1);
106         TB(test3, 0, -200, 1);
107         TB(test3, 0, 10, 0);
108         TB(test3, 42, 8, 0);
109         TB(test3, -1, -200, 0);
110         TB(test3, -1, 10, 0);
111
112         TB(test4, 0, 8, 1);
113         TB(test4, 0, -200, 1);
114         TB(test4, 0, 10, 1);
115         TB(test4, 42, 8, 1);
116         TB(test4, -1, -200, 1);
117         TB(test4, -1, 10, 0);
118
119         TB(test5, 42, -1, 42);
120         TB(test5, 1, 0, 1);
121         TB(test5, 0, 1, 0);
122         TB(test5, -1, 42, 41);
123
124         TB(test6, -5, 42, -1);
125         TB(test6, -20, -1, -1);
126         TB(test6, 20, -1, 1);
127         TB(test6a, 42, -1, 0);
128
129         TB(test7, 3, 2, 6);
130
131         TT(test8, 0, 2, 3, 0);
132         TT(test8, 0, 2, 1, 0);
133         TT(test8, -1, 42, 5, -1);
134         TT(test8, -7, 4, -42, -42);
135         TT(test8, 0, 2, -1, -1);
136         TT(test8, 24, 123, 7, 7);
137
138         TT(testam, -24, 13, 7, 13);
139         TT(testam, 102, 13, 7, 7);
140
141         TB(test9, 3, 2, 2);
142         TB(test9, -42, -42, -42);
143
144         return 0;
145 }