PR middle-end/77357 - strlen of constant strings not folded
[official-gcc.git] / gcc / testsuite / gcc.dg / ipa / pure-const-1.c
blob06b415e0c3cda1b1fde5c621f00eedce5eb934fc
1 /* { dg-do compile { target nonpic } } */
2 /* { dg-options "-O3 -fdump-tree-local-pure-const1 -fdump-ipa-pure-const -fdump-tree-optimized -fno-early-inlining -fgnu89-inline" } */
3 void abort (void);
4 int error_code;
5 static int val;
6 __attribute__ ((noinline, noclone))
7 static int
8 i_am_pure1 (int a)
10 if (a > 50)
11 abort ();
12 return a;
15 __attribute__ ((noinline, noclone))
16 static int
17 i_am_const2 (int a)
19 return a+val;
22 __attribute__ ((noinline, noclone))
23 int
24 call_me(int a)
26 return a;
29 inline int
30 call_callback(int (*fn)(int), int a)
32 return fn(a);
35 __attribute__ ((noinline, noclone)) int
36 i_am_const3(int a)
38 return call_callback (call_me, a);
41 __attribute__ ((noinline)) int
42 explode_badly()
44 error_code = 0xbad;
45 abort ();
48 __attribute__ ((noinline, noclone)) int
49 i_am_pure4(int a)
51 if (a > 50)
52 explode_badly ();
53 return a;
56 int
57 test()
59 int s;
60 s = i_am_pure1(5);
61 s += i_am_pure1(5);
62 s += i_am_const2(5);
63 s += i_am_const2(5);
64 s += i_am_const3(5);
65 s += i_am_const3(5);
66 s += i_am_pure4(5);
67 s += i_am_pure4(5);
68 return s;
70 /* { dg-final { scan-tree-dump-times "i_am_pure1 .5" 1 "optimized"} } */
71 /* { dg-final { scan-tree-dump-times "i_am_const2 .5" 1 "optimized"} } */
72 /* { dg-final { scan-tree-dump-times "i_am_const3 .5" 1 "optimized"} } */
73 /* { dg-final { scan-tree-dump-times "i_am_pure4 .5" 1 "optimized"} } */
74 /* { dg-final { scan-tree-dump "found to be looping pure: i_am_pure1" "local-pure-const1"} } */
75 /* { dg-final { scan-tree-dump "found to be looping pure: i_am_pure4" "local-pure-const1"} } */
76 /* { dg-final { scan-ipa-dump "found to be const: i_am_const2" "pure-const"} } */
77 /* { dg-final { scan-ipa-dump "found to be const: i_am_const3" "pure-const"} } */