OSDN Git Service

* gcc.c-torture/execute/20000412-1.c: Reduce some more.
[pf3gnuchains/gcc-fork.git] / gcc / testsuite / gcc.c-torture / execute / bcp-1.c
1 int global;
2
3 /* These must fail.  */
4 int bad0(void) { return __builtin_constant_p(global); }
5 int bad1(void) { return __builtin_constant_p(global++); }
6 inline int bad2(int x) { return __builtin_constant_p(x++); }
7 inline int bad3(int x) { return __builtin_constant_p(x); }
8 inline int bad4(const char *x) { return __builtin_constant_p(x); }
9 int bad5(void) { return bad2(1); }
10 inline int bad6(int x) { return __builtin_constant_p(x+1); }
11 int bad7(void) { return __builtin_constant_p(abort()); }
12 int bad8(void) { char buf[10]; return __builtin_constant_p(buf); }
13 int bad9(const char *x) { return __builtin_constant_p(x[123456]); }
14 int bad10(void) { return __builtin_constant_p(&global); }
15
16 /* These must pass, or we've broken gcc2 functionality.  */
17 int good0(void) { return __builtin_constant_p(1); }
18 int good1(void) { return __builtin_constant_p("hi"); }
19 int good2(void) { return __builtin_constant_p((1234 + 45) & ~7); }
20
21 /* These are extensions to gcc2.  Failure indicates an optimization
22    regression.  */
23 int opt0(void) { return bad3(1); }
24 int opt1(void) { return bad6(1); }
25 int opt2(void) { return __builtin_constant_p("hi"[0]); }
26
27 /* 
28  * Opt3 is known to fail.  It is one of the important cases that glibc
29  * was interested in though, so keep this around as a reminder.
30  *
31  * The solution is to add bits to recover bytes from constant pool
32  * elements given nothing but a constant pool label and an offset.
33  * When we can do that, and we can simplify strlen after the fact,
34  * then we can enable recognition of constant pool labels as constants.
35  */
36
37 /* int opt3(void) { return bad4("hi"); } */
38
39
40 /* Call through tables so -finline-functions can't screw with us.  */
41 int (*bad_t0[])(void) = {
42         bad0, bad1, bad5, bad7, bad8, bad10
43 };
44
45 int (*bad_t1[])(int x) = {
46         bad2, bad3, bad6
47 };
48
49 int (*bad_t2[])(const char *x) = {
50         bad4, bad9
51 };
52
53 int (*good_t0[])(void) = {
54         good0, good1, good2
55 };
56
57 int (*opt_t0[])(void) = {
58         opt0, opt1, opt2 /* , opt3 */
59 };
60
61 #define N(arr) (sizeof(arr)/sizeof(*arr))
62
63 int main()
64 {
65   int i;
66
67   for (i = 0; i < N(bad_t0); ++i)
68     if ((*bad_t0[i])())
69       abort();
70
71   for (i = 0; i < N(bad_t1); ++i)
72     if ((*bad_t1[i])(1))
73       abort();
74
75   for (i = 0; i < N(bad_t2); ++i)
76     if ((*bad_t2[i])("hi"))
77       abort();
78
79   for (i = 0; i < N(good_t0); ++i)
80     if (! (*good_t0[i])())
81       abort();
82
83 #ifdef __OPTIMIZE__
84   for (i = 0; i < N(opt_t0); ++i)
85     if (! (*opt_t0[i])())
86       abort();
87 #endif
88
89   exit(0);
90 }