This is the mail archive of the gcc-help@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: Code optimization: warning for code that hangs


On Sat, Jun 23, 2012 at 5:30 PM, Ian Lance Taylor <iant@google.com> wrote:
> "Peter A. Felvegi" <petschy@praire-chicken.com> writes:
>
>> My question is: wouldn't it be possible to print a warning when a jmp
>> to itself or trivial infinite recursion is generated? The code
>> compiled fine w/ -Wall -Wextra -Werror w/ 4.6 and 4.7.
>
> This question is not appropriate for the mailing list gcc@gcc.gnu.org,
> which is for discussions about the development of GCC. ?It would be
> appropriate for gcc-help@gcc.gnu.org. ?Please take any followups to
> gcc-help. ?Thanks.
>
> I'm not yet convinced that a -Wall warning would be worth the effort in
> this case. ?You have basically come up with a complicated way to write
>
> void f() { f(); }
>
> I suppose I think it would be reasonable to issue a -Wall warning for
> code like that. ?The trick is detecting it. ?Obviously there is nothing
> wrong with a recursive call. ?What is different here is that the
> recursive call is unconditional. ?I don't see a way to detect that
> without writing a specific warning pass to look for that case. ?And I
> think this case is rare enough, and easy enough to discover in other
> ways, that I don't think a warning would be worth the cost in
> compilation time and compiler maintenance.
>
> If the problem can be detected cheaply in the course of an existing
> pass, I would support a warning.

I suppose you could rely on detecting the CFG form of an uncontional
goto to an empty block from that block - the above recursion should
have been eliminated by the tail-recursion pass.

The issue with this kind of warnings is always that they are issued
even when the endless loop might not be reached at runtime.

Richard.

> Ian


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