diff --git a/trans-array.c b/trans-array.c index d386a22..abff8b5 100644 --- a/trans-array.c +++ b/trans-array.c @@ -3193,7 +3193,8 @@ gfc_trans_scalarizing_loops (gfc_loopinfo * loop, stmtblock_t * body) /* Clear all the used flags. */ for (ss = loop->ss; ss != gfc_ss_terminator; ss = ss->loop_chain) - ss->info->useflags = 0; + if (ss->parent == NULL) + ss->info->useflags = 0; } diff --git a/trans-expr.c b/trans-expr.c index e091c89..72d35f8 100644 --- a/trans-expr.c +++ b/trans-expr.c @@ -83,6 +83,7 @@ void gfc_advance_se_ss_chain (gfc_se * se) { gfc_se *p; + gfc_ss *ss; gcc_assert (se != NULL && se->ss != NULL && se->ss != gfc_ss_terminator); @@ -93,7 +94,15 @@ gfc_advance_se_ss_chain (gfc_se * se) /* Simple consistency check. */ gcc_assert (p->parent == NULL || p->parent->ss == p->ss); - p->ss = p->ss->next; + /* If we were in a nested loop, the next scalarized expression can be + on the parent ss' next pointer. Thus we should not take the next + pointer blindly, but rather go up one nest level as long as next + is the end of chain. */ + ss = p->ss; + while (ss->next == gfc_ss_terminator && ss->parent != NULL) + ss = ss->parent; + + p->ss = ss->next; p = p->parent; } diff --git a/trans.h b/trans.h index 62bcc64..53c5ce2 100644 --- a/trans.h +++ b/trans.h @@ -246,6 +246,9 @@ typedef struct gfc_ss struct gfc_ss *loop_chain; struct gfc_ss *next; + /* Non-null if the ss is part of a nested loop. */ + struct gfc_ss *parent; + /* The loop this gfc_ss is in. */ struct gfc_loopinfo *loop;