This is the mail archive of the
mailing list for the GCC project.
Re: Empty loop elimination in 4.0 ?
- From: Michael Veksler <VEKSLER at il dot ibm dot com>
- To: Robert Dewar <dewar at adacore dot com>
- Cc: gcc at gcc dot gnu dot org, Zdenek Dvorak <rakdver at atrey dot karlin dot mff dot cuni dot cz>
- Date: Mon, 10 Jan 2005 16:34:40 +0200
- Subject: Re: Empty loop elimination in 4.0 ?
Robert Dewar <firstname.lastname@example.org> 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
of callbacks. These callbacks are inline functions, some of them are empty.
template <class V>
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.).