Merged r158704 through r158906 into branch.
[official-gcc.git] / gcc / testsuite / gcc.dg / pure-2.c
blob97ba31f0261f1552c412238f30b208cb9cef582a
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -Wsuggest-attribute=pure" } */
4 extern int extern_const(int a) __attribute__ ((pure));
5 extern int v;
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;
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;
25 /* No warning here; we can work it by ourselves. */
26 static int __attribute__ ((noinline))
27 foo2b(int n)
29 int ret = 0;
30 int i;
31 for (i=0; i<n; i++)
32 ret+=extern_const (i);
33 return ret;
36 /* Unbounded loops are not safe. */
37 static int __attribute__ ((noinline))
38 foo3(int n) /* { dg-warning "pure\[^\n\]* normally" "detect pure candidate" } */
40 int ret = 0;
41 int i;
42 for (i=0; extern_const (i+n); n++)
43 ret+=extern_const (i);
44 return ret;
47 int
48 foo4(int n) /* { dg-warning "pure\[^\n\]* normally" "detect pure candidate" } */
50 return foo3(n) + foo2b(n);
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);