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