@@ -220,6 +220,14 @@ I8(local_copy)(char *db, F90_Desc *dd, __INT_T doffset, char *ab,
220220 }
221221}
222222
223+ /** \brief check if a descriptor is associated with a non-contiguous
224+ * section.
225+ *
226+ * \param a is the descriptor we are checking.
227+ * \param dim is the rank of the array we are checking.
228+ *
229+ * \returns 0 if contiguous, else the dimension that is non-contiguous.
230+ */
223231__INT_T
224232I8 (is_nonsequential_section )(F90_Desc * a , __INT_T dim )
225233{
@@ -233,7 +241,7 @@ I8(is_nonsequential_section)(F90_Desc *a, __INT_T dim)
233241 for (i = 0 ; i < dim ; i ++ ) {
234242 SET_DIM_PTRS (ad , a , i );
235243 if (F90_DPTR_LSTRIDE_G (ad ) != tmp_lstride || F90_DPTR_SSTRIDE_G (ad ) != 1 ) {
236- is_nonseq_section = 1 ;
244+ is_nonseq_section = i + 1 ;
237245 break ;
238246 }
239247 tmp_lstride *= F90_DPTR_EXTENT_G (ad );
@@ -2744,3 +2752,60 @@ ENTF90(IS_CONTIGUOUS, is_contiguous)(char *ab, F90_Desc *ad)
27442752 return GET_DIST_TRUE_LOG ;
27452753}
27462754
2755+ /** \brief Print a contiguous error message and abort.
2756+ *
2757+ * This function will also call is_nonsequential_section() to get the
2758+ * first dimension of the array that is non-contiguous and include it in the
2759+ * error message.
2760+ *
2761+ * \param ptr is the pointer we are checking.
2762+ * \param pd is the descriptor we are checking.
2763+ * \param lineno is the source line number we are checking.
2764+ * \param ptrnam is the name of pointer, null-terminated string.
2765+ * \param srcfil is the name of source file, null-terminated string.
2766+ * \param flags is currently 1 when ptr is an optional argument, else 0.
2767+ */
2768+ void
2769+ ENTF90 (CONTIGERROR , contigerror )(void * ptr , F90_Desc * pd , __INT_T lineno ,
2770+ char * ptrnam , char * srcfil , __INT_T flags )
2771+ {
2772+ char str [200 ];
2773+ int dim ;
2774+
2775+ if (flags == 1 && ptr == NULL ) {
2776+ /* ignore non-present optional argument */
2777+ return ;
2778+ }
2779+ dim = I8 (is_nonsequential_section )(pd , F90_RANK_G (pd ));
2780+ sprintf (str , "Runtime Error at %s, line %d: Pointer assignment of "
2781+ "noncontiguous target (dimension %d) to CONTIGUOUS pointer "
2782+ "%s\n" , srcfil , lineno , dim , ptrnam );
2783+ __fort_abort (str );
2784+ }
2785+
2786+ /** \brief Check whether a pointer is associated with a contiguous array object.
2787+ *
2788+ * If the pointer is not associated with a contiguous array object, then a
2789+ * message is printed to stderr and the user program aborts.
2790+ *
2791+ * \param ptr is the pointer we are checking.
2792+ * \param pd is the descriptor we are checking.
2793+ * \param lineno is the source line number we are checking.
2794+ * \param ptrnam is the name of pointer, null-terminated string.
2795+ * \param srcfil is the name of source file, null-terminated string.
2796+ * \param flags is currently 1 when ptr is an optional argument, else 0.
2797+ */
2798+ void
2799+ ENTF90 (CONTIGCHK , contigchk )(void * ptr , F90_Desc * pd , __INT_T lineno ,
2800+ char * ptrnam , char * srcfil , __INT_T flags )
2801+ {
2802+ if (flags == 1 && ptr == NULL ) {
2803+ /* ignore non-present optional argument */
2804+ return ;
2805+ }
2806+
2807+ if (!(ENTF90 (IS_CONTIGUOUS , is_contiguous )(ptr , pd ))) {
2808+ ENTF90 (CONTIGERROR , contigerror )(ptr , pd , lineno , ptrnam , srcfil , flags );
2809+ }
2810+ }
2811+
0 commit comments