111
|
1 /* { dg-do compile } */
|
|
2 /* { dg-options "-O2 -Wsuggest-attribute=pure" } */
|
|
3 /* { dg-add-options bind_pic_locally } */
|
|
4
|
|
5 extern int extern_const(int a) __attribute__ ((pure));
|
|
6 extern int v;
|
|
7
|
|
8 /* Trivial. */
|
|
9 int
|
|
10 foo1(int a) /* { dg-bogus "normally" "detect pure candidate" } */
|
|
11 { /* { dg-warning "pure" "detect pure candidate" { target *-*-* } "10" } */
|
|
12 return v;
|
|
13 }
|
|
14
|
|
15 /* Loops known to be normally and extern const calls should be safe. */
|
|
16 int __attribute__ ((noinline))
|
|
17 foo2(int n) /* { dg-bogus "normally" "detect pure candidate" } */
|
|
18 { /* { dg-warning "pure" "detect pure candidate" { target *-*-* } "17" } */
|
|
19 int ret = 0;
|
|
20 int i;
|
|
21 for (i=0; i<n; i++)
|
|
22 ret+=extern_const (i);
|
|
23 return ret;
|
|
24 }
|
|
25
|
|
26 /* No warning here; we can work it by ourselves. */
|
|
27 static int __attribute__ ((noinline))
|
|
28 foo2b(int n)
|
|
29 {
|
|
30 int ret = 0;
|
|
31 int i;
|
|
32 for (i=0; i<n; i++)
|
|
33 ret+=extern_const (i);
|
|
34 return ret;
|
|
35 }
|
|
36
|
|
37 /* Unbounded loops are not safe. */
|
|
38 static int __attribute__ ((noinline))
|
|
39 foo3(unsigned int n) /* { dg-warning "pure\[^\n\]* normally" "detect pure candidate" } */
|
|
40 {
|
|
41 int ret = 0;
|
|
42 unsigned int i;
|
|
43 for (i=0; extern_const (i+n); n++)
|
|
44 ret+=extern_const (i);
|
|
45 return ret;
|
|
46 }
|
|
47
|
|
48 int
|
|
49 foo4(int n) /* { dg-warning "pure\[^\n\]* normally" "detect pure candidate" } */
|
|
50 {
|
|
51 return foo3(n) + foo2b(n);
|
|
52 }
|
|
53
|
|
54 int
|
|
55 foo5(int n) /* { dg-bogus "normally" "detect pure candidate" } */
|
|
56 { /* { dg-warning "pure" "detect pure candidate" { target *-*-* } "55" } */
|
|
57 return foo2(n);
|
|
58 }
|