1 __attribute__ ((externally_visible)) int global;
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
24 int opt0(void) { return bad3(1); }
25 int opt1(void) { return bad6(1); }
26 int opt2(void) { return __builtin_constant_p("hi"[0]); }
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 (* volatile bad_t0[])(void) = {
43 bad0, bad1, bad5, bad7, bad8, bad10
46 int (* volatile bad_t1[])(int x) = {
50 int (* volatile bad_t2[])(const char *x) = {
54 int (* volatile good_t0[])(void) = {
58 int (* volatile opt_t0[])(void) = {
59 opt0, opt1, opt2 /* , opt3 */
62 #define N(arr) (sizeof(arr)/sizeof(*arr))
68 for (i = 0; i < N(bad_t0); ++i)
72 for (i = 0; i < N(bad_t1); ++i)
76 for (i = 0; i < N(bad_t2); ++i)
77 if ((*bad_t2[i])("hi"))
80 for (i = 0; i < N(good_t0); ++i)
81 if (! (*good_t0[i])())
85 for (i = 0; i < N(opt_t0); ++i)