Thread overview
[Issue 14214] Internal error: backend/go.c 242
Feb 22, 2015
Ketmar Dark
Jun 22, 2015
Kenji Hara
Jan 03, 2017
Timothee Cour
Jan 03, 2017
Ketmar Dark
Jan 03, 2017
Ketmar Dark
Jan 03, 2017
Timothee Cour
Mar 02, 2019
Basile-z
Mar 21, 2020
Basile-z
February 22, 2015
https://issues.dlang.org/show_bug.cgi?id=14214

Ketmar Dark <ketmar@ketmar.no-ip.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |ketmar@ketmar.no-ip.org
           Hardware|x86_64                      |All
                 OS|Linux                       |All

--- Comment #1 from Ketmar Dark <ketmar@ketmar.no-ip.org> ---
this is general arch-independent optimiser bug, so i changed hardware section.

--
June 22, 2015
https://issues.dlang.org/show_bug.cgi?id=14214

Kenji Hara <k.hara.pg@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice
           Severity|normal                      |major

--- Comment #2 from Kenji Hara <k.hara.pg@gmail.com> ---
Further reduced test case:

alias TypeTuple(T...) = T;
alias members = TypeTuple!(
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,0,
    0,0,0,0,0,0,0,0,0,
    0,  // error will disappear by removing one element
);

void main()
{
    int row = 0;
    foreach (_unused; members)  // copy the loop body 100 times
    {
        ++row;
        if (row)
            row = 0; // error triggered by this line.
    }
}

----------------------

The ICE seems happened by the assertion with incorrect assumption for "infinite loop check". But I'm not sure the correct iteration limit...

backend/go.c =======

    // Each pass through the loop can reduce only one level of comma
expression.
    // The infinite loop check needs to take this into account.
    // Add 100 just to give optimizer more rope to try to converge.
    int iterationLimit = 0;
    for (b = startblock; b; b = b->Bnext)
    {
        if (!b->Belem)
            continue;
        int d = el_countCommas(b->Belem) + 100;
        if (d > iterationLimit)
            iterationLimit = d;
    }

    // Some functions can take enormous amounts of time to optimize.
    // We try to put a lid on it.
    starttime = clock();
    do
    {
        //printf("iter = %d\n", iter);
        if (++iter > 200)
        {   assert(iter < iterationLimit);      // infinite loop check
<-- the assert is on line 242
            break;
        }

--
January 03, 2017
https://issues.dlang.org/show_bug.cgi?id=14214

Timothee Cour <timothee.cour2@gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |timothee.cour2@gmail.com

--- Comment #3 from Timothee Cour <timothee.cour2@gmail.com> ---
ping: hit this bug: https://github.com/gtkd-developers/GtkD/issues/176#issuecomment-270096196

--
January 03, 2017
https://issues.dlang.org/show_bug.cgi?id=14214

--- Comment #4 from Ketmar Dark <ketmar@ketmar.no-ip.org> ---
Created attachment 1630
  --> https://issues.dlang.org/attachment.cgi?id=1630&action=edit
hackfix

--
January 03, 2017
https://issues.dlang.org/show_bug.cgi?id=14214

--- Comment #5 from Ketmar Dark <ketmar@ketmar.no-ip.org> ---
the core issue is that optimizer is failed to distinguish comma expressions from enumerations, so it sees huge enumeration as alot of comma-expressions, tries to optimize that and fails. in my hackfix i just made optimizer to give up if it sees "alot of commas".

--
January 03, 2017
https://issues.dlang.org/show_bug.cgi?id=14214

--- Comment #6 from Timothee Cour <timothee.cour2@gmail.com> ---
NOTE: ldc doesn't have this issue and is faster;
for this particular bug, a workaround as to use
```
s/foreach(_a; members)/foreach(_a; [members])/
```
but it won't work if types are distinct

--
March 02, 2019
https://issues.dlang.org/show_bug.cgi?id=14214

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
                 CC|                            |b2.temp@gmx.com
         Resolution|---                         |WORKSFORME

--
March 21, 2020
https://issues.dlang.org/show_bug.cgi?id=14214

Basile-z <b2.temp@gmx.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|b2.temp@gmx.com             |

--