This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/51971] unclear/unverified restrictions on attribute((const|pure))


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).


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]