#266 closed defect (fixed)

Increment hoisted outside the loop

Reported by: Thierry Delisle Owned by:
Priority: major Component: cfa-cc
Version: 1.0 Keywords:


In the following code:

struct A {
    T * next;

struct B {
    A(B) link;

void baz() {
    for(B ** it;;it = &(*it)->link.next) {}

The for loop is codegened as:

void _X3bazFv___1(){
        struct B **_X2itPPS1B_3;
        struct B **_dtype_static_member_245 = ((struct B **)(&(*(*_X2itPPS1B_3))._X4linkS1A_S1B__1._X4nextPY12__T_generic__1));
        for (;;((void)(_X2itPPS1B_3=_dtype_static_member_245))) {

This moves the loop increment outside the actual loop, which causes infinite loops.

The problem is probably either in Instantiate Generic pass or in the Pass visitor.

Instantiate Generic is the pass creating the variable _dtype_static_member_245, searching from src/GenPoly/InstantiateGenericNew.cpp:384 (as of time of writing) should yield the namer.

It could also be because the pass visitor needs to handle stmts_to_add better in this case.

Change History (1)

comment:1 Changed 19 months ago by ajbeach

Resolution: fixed
Status: newclosed

Fixed in commit: 1dafdfc356ef109039c90bff9ffe0abe74b74097

The solution was to move the initialization to an assignment in a comma expression where the original expression was/is.

Note: See TracTickets for help on using tickets.