[Issue 14419] [CTFE] Need infinite loop detection?

via Digitalmars-d-bugs digitalmars-d-bugs at puremagic.com
Mon Apr 6 09:48:29 PDT 2015


https://issues.dlang.org/show_bug.cgi?id=14419

Iain Buclaw <ibuclaw at gdcproject.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ibuclaw at gdcproject.org

--- Comment #7 from Iain Buclaw <ibuclaw at gdcproject.org> ---
(In reply to Kenji Hara from comment #2)
> (In reply to Iain Buclaw from comment #0)
> > This was noticed and raised in GDC Bugzilla #178 because of a typo in the
> > code.
> > 
> > http://bugzilla.gdcproject.org/show_bug.cgi?id=178
> > 
> > 
> > What it boils down to is this:
> > ---
> > int foo() { while (true) { } return 1; }
> > enum bar = foo;  // User meant to type '&foo'
> > ---
> > 
> > Perfectly valid code causing an infinite loop in CTFE.  Obviously this is a
> > bug vs. feature argument, but infinite loop detection should really be a
> > feature of CTFE to avoid accidental build bugs from occurring.
> 
> How to do it for a complex code?
> 
> int foo(int n = 0)
> {
>     while (true)
>     {
>         ++n;
>         if (n > 1_000_000)
>             break;
>     }
>     return 1;
> }
> enum bar = foo;  // User meant to type '&foo'
> 
> Using while(true) for the limited loop is usual. And limiting loop
> repetition to arbitrary count is problematic (a million repetition is too
> big?).
> 
> The idea sounds good, but implementing it would be difficult.

Branch exit (BE) prediction might be sufficient (and fast) for this.  I'll have
to double check whether or not we hold enough information though.

--


More information about the Digitalmars-d-bugs mailing list