PR tree-optimization/83369 - Missing diagnostics during inlining
[official-gcc.git] / gcc / testsuite / gcc.dg / pure-2.c
blobfe6e2bce6954900a78774567af79c39c59f9289a
1 /* { dg-do compile } */
2 /* { dg-options "-O2 -Wsuggest-attribute=pure" } */
3 /* { dg-add-options bind_pic_locally } */
5 extern int extern_const(int a) __attribute__ ((pure));
6 extern int v;
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;
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;
26 /* No warning here; we can work it by ourselves. */
27 static int __attribute__ ((noinline))
28 foo2b(int n)
30 int ret = 0;
31 int i;
32 for (i=0; i<n; i++)
33 ret+=extern_const (i);
34 return ret;
37 /* Unbounded loops are not safe. */
38 static int __attribute__ ((noinline))
39 foo3(unsigned int n) /* { dg-warning "pure\[^\n\]* normally" "detect pure candidate" } */
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;
48 int
49 foo4(int n) /* { dg-warning "pure\[^\n\]* normally" "detect pure candidate" } */
51 return foo3(n) + foo2b(n);
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);