diff options
Diffstat (limited to 'libgfortran/m4/iforeach.m4')
-rw-r--r-- | libgfortran/m4/iforeach.m4 | 59 |
1 files changed, 46 insertions, 13 deletions
diff --git a/libgfortran/m4/iforeach.m4 b/libgfortran/m4/iforeach.m4 index 105ca97..616caf9 100644 --- a/libgfortran/m4/iforeach.m4 +++ b/libgfortran/m4/iforeach.m4 @@ -20,13 +20,31 @@ name`'rtype_qual`_'atype_code (rtype * retarray, atype *array) index_type n; rank = GFC_DESCRIPTOR_RANK (array); - assert (rank > 0); - assert (GFC_DESCRIPTOR_RANK (retarray) == 1); - assert (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound == rank); + if (rank <= 0) + runtime_error ("Rank of array needs to be > 0"); + + if (retarray->data == NULL) + { + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = rank-1; + retarray->dim[0].stride = 1; + retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1; + retarray->base = 0; + retarray->data = internal_malloc_size (sizeof (rtype_name) * rank); + } + else + { + if (GFC_DESCRIPTOR_RANK (retarray) != 1) + runtime_error ("rank of return array does not equal 1"); + + if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank) + runtime_error ("dimension of return array incorrect"); + + if (retarray->dim[0].stride == 0) + retarray->dim[0].stride = 1; + } if (array->dim[0].stride == 0) array->dim[0].stride = 1; - if (retarray->dim[0].stride == 0) - retarray->dim[0].stride = 1; dstride = retarray->dim[0].stride; dest = retarray->data; @@ -109,17 +127,32 @@ void index_type n; rank = GFC_DESCRIPTOR_RANK (array); - assert (rank > 0); - assert (GFC_DESCRIPTOR_RANK (retarray) == 1); - assert (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound == rank); - assert (GFC_DESCRIPTOR_RANK (mask) == rank); + if (rank <= 0) + runtime_error ("Rank of array needs to be > 0"); + + if (retarray->data == NULL) + { + retarray->dim[0].lbound = 0; + retarray->dim[0].ubound = rank-1; + retarray->dim[0].stride = 1; + retarray->dtype = (retarray->dtype & ~GFC_DTYPE_RANK_MASK) | 1; + retarray->base = 0; + retarray->data = internal_malloc_size (sizeof (rtype_name) * rank); + } + else + { + if (GFC_DESCRIPTOR_RANK (retarray) != 1) + runtime_error ("rank of return array does not equal 1"); + + if (retarray->dim[0].ubound + 1 - retarray->dim[0].lbound != rank) + runtime_error ("dimension of return array incorrect"); + + if (retarray->dim[0].stride == 0) + retarray->dim[0].stride = 1; + } if (array->dim[0].stride == 0) array->dim[0].stride = 1; - if (retarray->dim[0].stride == 0) - retarray->dim[0].stride = 1; - if (retarray->dim[0].stride == 0) - retarray->dim[0].stride = 1; dstride = retarray->dim[0].stride; dest = retarray->data; |