Empty loop elimination in 4.0 ?
Michael Veksler
VEKSLER@il.ibm.com
Mon Jan 10 15:14:00 GMT 2005
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.).
More information about the Gcc
mailing list