This is the mail archive of the gcc@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]

Re: Empty loop elimination in 4.0 ?







Robert Dewar <dewar@adacore.com> wrote on 10/01/2005 15:49:00:
> I think it is always a good idea to generate a warning
> when an empty loop is detected (whether or not it is
> eliminated), since this is either a timing loop, or it
> is likely a bug.

Maybe in C, but not in C++ when you may have generic code
that is translated to empty loops.

When you pass a generic visitor (visitor in the old GTL sense), it has a
set
of callbacks. These callbacks are inline functions, some of them are empty.
  template <class V>
  f(V v)
  {
     for(....)  v.Do1();
     for(....)  v.Do2();
  }

Whoever defines 'f' does not care if V::Do1() is empty. Morever,
nobody wants to write special code for the case when V::Do1() is
empty. It is assumed that the compiler is smart enough to get
rid of the loop.

Another example, with C macros. I assume that with -DNDEBUG
assert(x) is empty:

for (p: iterates over elements)
  assert(p->value != NULL);  /* Will warn with -DNDEBUG */

/* Should I add "#ifndef NDEBUG" to protect the loop? */

------------

Conclusion: I think that the warning will give too many false warnings.
Unlike -Wsign-compare (which also generates lots of false positive),
bugs will be so minor they will not pay for the false positives.

---------

Of course, missing loop elimination is not a regerssion because no
gcc did it before. Also, I have no evidence that this situation is common
enough (with C macros or with C++ generic programmic.).



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