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
));
10 foo1(int a
) /* { dg-bogus "normally" "detect pure candidate" } */
11 { /* { dg-warning "pure" "detect pure candidate" { target *-*-* } "10" } */
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" } */
22 ret
+=extern_const (i
);
26 /* No warning here; we can work it by ourselves. */
27 static int __attribute__ ((noinline
))
33 ret
+=extern_const (i
);
37 /* Unbounded loops are not safe. */
38 static int __attribute__ ((noinline
))
39 foo3(unsigned int n
) /* { dg-warning "pure\[^\n\]* normally" "detect pure candidate" } */
43 for (i
=0; extern_const (i
+n
); n
++)
44 ret
+=extern_const (i
);
49 foo4(int n
) /* { dg-warning "pure\[^\n\]* normally" "detect pure candidate" } */
51 return foo3(n
) + foo2b(n
);
55 foo5(int n
) /* { dg-bogus "normally" "detect pure candidate" } */
56 { /* { dg-warning "pure" "detect pure candidate" { target *-*-* } "55" } */