diff --git a/trans-array.c b/trans-array.c index d918fa820093edb19f100364faafd4f4839083e8..1a86ae66c59e2814d7735d66c6418b46fa59585b 100644 *** a/trans-array.c --- b/trans-array.c *************** gfc_trans_create_temp_array (stmtblock_t *** 943,948 **** --- 943,949 ---- bool dealloc, bool callee_alloc, locus * where) { gfc_loopinfo *loop; + gfc_ss *s; gfc_array_info *info; tree from[GFC_MAX_DIMENSIONS], to[GFC_MAX_DIMENSIONS]; tree type; *************** gfc_trans_create_temp_array (stmtblock_t *** 966,977 **** if (gfc_option.warn_array_temp && where) gfc_warning ("Creating array temporary at %L", where); - loop = ss->loop; - total_dim = loop->dimen; /* Set the lower bound to zero. */ for (n = 0; n < loop->dimen; n++) { ! dim = ss->dim[n]; /* Callee allocated arrays may not have a known bound yet. */ if (loop->to[n]) --- 967,981 ---- if (gfc_option.warn_array_temp && where) gfc_warning ("Creating array temporary at %L", where); /* Set the lower bound to zero. */ + for (s = ss; s; s = s->parent) + { + loop = s->loop; + + total_dim += loop->dimen; for (n = 0; n < loop->dimen; n++) { ! dim = s->dim[n]; /* Callee allocated arrays may not have a known bound yet. */ if (loop->to[n]) *************** gfc_trans_create_temp_array (stmtblock_t *** 990,997 **** /* We are constructing the temporary's descriptor based on the loop dimensions. As the dimensions may be accessed in arbitrary order (think of transpose) the size taken from the n'th loop may not map ! to the n'th dimension of the array. We need to reconstruct loop infos ! in the right order before using it to set the descriptor bounds. */ tmp_dim = get_scalarizer_dim_for_array_dim (ss, dim); from[tmp_dim] = loop->from[n]; --- 994,1001 ---- /* We are constructing the temporary's descriptor based on the loop dimensions. As the dimensions may be accessed in arbitrary order (think of transpose) the size taken from the n'th loop may not map ! to the n'th dimension of the array. We need to reconstruct loop ! infos in the right order before using it to set the descriptor bounds. */ tmp_dim = get_scalarizer_dim_for_array_dim (ss, dim); from[tmp_dim] = loop->from[n]; *************** gfc_trans_create_temp_array (stmtblock_t *** 1002,1007 **** --- 1006,1012 ---- info->end[dim] = gfc_index_zero_node; info->stride[dim] = gfc_index_one_node; } + } /* Initialize the descriptor. */ type = *************** gfc_trans_create_temp_array (stmtblock_t *** 1042,1049 **** } if (size == NULL_TREE) ! { ! for (n = 0; n < loop->dimen; n++) { dim = get_scalarizer_dim_for_array_dim (ss, ss->dim[n]); --- 1047,1054 ---- } if (size == NULL_TREE) ! for (s = ss; s; s = s->parent) ! for (n = 0; n < s->loop->dimen; n++) { dim = get_scalarizer_dim_for_array_dim (ss, ss->dim[n]); *************** gfc_trans_create_temp_array (stmtblock_t *** 1053,1060 **** MINUS_EXPR, gfc_array_index_type, gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[dim]), gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[dim])); ! loop->to[n] = tmp; ! } } else { --- 1058,1064 ---- MINUS_EXPR, gfc_array_index_type, gfc_conv_descriptor_ubound_get (desc, gfc_rank_cst[dim]), gfc_conv_descriptor_lbound_get (desc, gfc_rank_cst[dim])); ! s->loop->to[n] = tmp; } else { *************** gfc_trans_create_temp_array (stmtblock_t *** 1112,1117 **** --- 1116,1124 ---- gfc_trans_allocate_array_storage (pre, post, info, size, nelem, initial, dynamic, dealloc); + while (ss->parent) + ss = ss->parent; + if (ss->dimen > ss->loop->temp_dim) ss->loop->temp_dim = ss->dimen;