1 /* { dg-do compile } */
2 /* { dg-options "-O2 -Wsuggest-attribute=pure" } */
4 extern int extern_const(int a
) __attribute__ ((pure
));
9 foo1(int a
) /* { dg-bogus "normally" "detect pure candidate" } */
10 { /* { dg-warning "pure" "detect pure candidate" { target *-*-* } "9" } */
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" } */
21 ret
+=extern_const (i
);
25 /* No warning here; we can work it by ourselves. */
26 static int __attribute__ ((noinline
))
32 ret
+=extern_const (i
);
36 /* Unbounded loops are not safe. */
37 static int __attribute__ ((noinline
))
38 foo3(unsigned int n
) /* { dg-warning "pure\[^\n\]* normally" "detect pure candidate" } */
42 for (i
=0; extern_const (i
+n
); n
++)
43 ret
+=extern_const (i
);
48 foo4(int n
) /* { dg-warning "pure\[^\n\]* normally" "detect pure candidate" } */
50 return foo3(n
) + foo2b(n
);
54 foo5(int n
) /* { dg-bogus "normally" "detect pure candidate" } */
55 { /* { dg-warning "pure" "detect pure candidate" { target *-*-* } "54" } */