OSDN Git Service

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