New const function detection code and infinite loops.

Jan Hubicka jhub6202@ss1000.ms.mff.cuni.cz
Tue Aug 31 23:20:00 GMT 1999


On Mon, 23 Aug 1999, John Wehle wrote:

> > int funct(int b)
> > {
> >   while(b&1) b+=2;
> >   return b;
> > }
> > main()
> > { 
> >   funct(1);
> > }
> > despite the fact, that function is complette nonsence, it still contains
> > infinite loop (for certain input values), but will be marked as const by
> > the detection code. So this program will terminate. Maybe this is ANSI-C
> > conforming, but I don't believe so.
> 
> I'm not following you. Are you saying that the program may be ANSI-C
> conforming, or the new behavior of the compiler?  I believe that marking
> the function as const allows CSE to remove * redundant * calls which
This is nor true. CSE hapilly removes call as long as return value is
dead.
If we modify CSE in way you suggest, we might get around the problem.
But I don't think it is trivial task. At least following function:
main()
{
funct(1);
funct(1);
}
can be optimized to one call, but function:
main()
{
funct(2);
funct(1);
}
can not.
This also contradict way CSE works. So I think better way to get around
is to keep current behaviour on const functions and add the separate
structure as I suggest.
> means that the infinite loop will still occur for certain inputs, just
> not as many infinite loops as would otherwise happen.  I'm not sure in
> what situation having fewer infinite loops for a given input creates a
> problem unless you are thinking of situations where an external event
> is causing control to leave the loop in which cause the loop may be
> quite deliberate and perhaps should be marked volatile.
I am not ANSI-C expert. If ANSI-C requires infinite loops to be volatile,
we've won. But as pure programmer I would never come with idea to mark
such loop as volatile and would be surprised to have my program finite.

Honza
> 
> -- John
> -------------------------------------------------------------------------
> |   Feith Systems  |   Voice: 1-215-646-8000  |  Email: john@feith.com  |
> |    John Wehle    |     Fax: 1-215-540-5495  |                         |
> -------------------------------------------------------------------------
> 



More information about the Gcc mailing list