This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/51971] unclear/unverified restrictions on attribute((const|pure))
- From: "rguenth at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Tue, 24 Jan 2012 13:01:03 +0000
- Subject: [Bug c/51971] unclear/unverified restrictions on attribute((const|pure))
- Auto-submitted: auto-generated
- References: <bug-51971-4@http.gcc.gnu.org/bugzilla/>
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=51971
--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-01-24 13:01:03 UTC ---
GCC explicitely allows you to use const/pure to enable CSE even if it would
not consider the function const/pure itself (thus, if you are happy to
loose a second assert (), or a debug printf).
About returning normally it wants to exclude side-effects that happen
via the return, such as if the function calls longjmp/fork (return twice).
It also wants to exclude functions that do not return because they loop
infinitely. For example
int foo (int b)
{
if (b) while (1);
return b;
}
is not const, as GCC would, if you declare it so, happily remove
foo (1);
as dead code (GCC will do so for all pure/const functions if the result
is not needed).