@@ -751,19 +751,6 @@ add_p_dealloc_item(int sptr)
751751 sem .p_dealloc = itemp ;
752752}
753753
754- /** \brief Given an allocatable array and an explicit shape list which has been
755- deposited in the semant 'bounds' structure, generate assignments to
756- the arrays bounds temporaries, and allocate the array. Save the id
757- ast
758- of the array for an ensuing deallocate of the array.
759- */
760- void
761- gen_allocate_array (int arr )
762- {
763- int alloc_obj = gen_defer_shape (arr , 0 , arr );
764- (void )gen_alloc_dealloc (TK_ALLOCATE , alloc_obj , 0 );
765- add_p_dealloc_item (arr );
766- }
767754
768755/** \brief Generate deallocates for the temporary arrays in the sem.p_delloc
769756 * list.
@@ -1011,7 +998,6 @@ typedef struct {
1011998} _ACS ;
1012999
10131000static _ACS acs ;
1014-
10151001static LOGICAL _can_fold (int );
10161002static void constructf90 (int , ACL * );
10171003static void _dinit_acl (ACL * , LOGICAL );
@@ -1033,6 +1019,24 @@ iexpr_op(int op)
10331019 return "?N?" ;
10341020}
10351021
1022+ /** \brief Given an allocatable array and an explicit shape list which has been
1023+ deposited in the semant 'bounds' structure, generate assignments to
1024+ the arrays bounds temporaries, and allocate the array. Save the id
1025+ ast
1026+ of the array for an ensuing deallocate of the array.
1027+ */
1028+ void
1029+ gen_allocate_array (int arr )
1030+ {
1031+ int alloc_obj = gen_defer_shape (arr , 0 , arr );
1032+ if (is_deferlenchar_dtype (acs .arrtype )) {
1033+ get_static_descriptor (arr );
1034+ get_all_descriptors (arr );
1035+ }
1036+ gen_alloc_dealloc (TK_ALLOCATE , alloc_obj , 0 );
1037+ add_p_dealloc_item (arr );
1038+ }
1039+
10361040#if DEBUG
10371041static void
10381042_printacl (int in_array , ACL * aclp , FILE * f )
@@ -1491,6 +1495,9 @@ chk_constructor(ACL *aclp, DTYPE dtype)
14911495 sem .arrdim .ndefer = 1 ;
14921496 acs .is_const = FALSE;
14931497 }
1498+ if (sem .gcvlen && is_deferlenchar_dtype (acs .eltype )) {
1499+ sem .arrdim .ndefer = 1 ;
1500+ }
14941501 aclp -> size = sem .bounds [0 ].upast ;
14951502
14961503 acs .arrtype = mk_arrdsc ();
@@ -1669,6 +1676,7 @@ init_sptr_w_acl(int in_sptr, ACL *aclp)
16691676 if (sem .arrdim .ndefer ) {
16701677 ALLOCATE_ARRAYS = 0 ; /* allocate for these array temps is done here */
16711678 }
1679+
16721680 sptr = acs .tmp = get_arr_temp (acs .arrtype , FALSE, FALSE, FALSE);
16731681 ALLOCATE_ARRAYS = 1 ;
16741682 if (sem .arrdim .ndefer ) {
@@ -1767,13 +1775,17 @@ compute_size_ast(bool add_flag, ACL *aclp, DTYPE dtype)
17671775static DTYPE
17681776compute_size_expr (bool add_flag , ACL * aclp , DTYPE dtype )
17691777{
1778+ DTYPE dt2 , dtype2 ;
17701779 SST * stkp = aclp -> u1 .stkp ;
17711780 LOGICAL specified_dtype = dtype != 0 ;
1772- DTYPE dt = dtype ;
1781+ DTYPE dt = DDTG (dtype );
1782+ dtype2 = SST_DTYPEG (stkp );
1783+ dt2 = DDTG (SST_DTYPEG (stkp ));
17731784 if (!specified_dtype ) {
1774- dtype = SST_DTYPEG ( stkp ) ;
1775- dt = DDTG ( dtype ) ;
1785+ dtype = dtype2 ;
1786+ dt = dt2 ;
17761787 }
1788+
17771789 if (acs .eltype == 0 || acs .zln ) {
17781790 int id = SST_IDG (stkp );
17791791 if (acs .eltype != 0 ) {
@@ -1786,15 +1798,21 @@ compute_size_expr(bool add_flag, ACL *aclp, DTYPE dtype)
17861798 || dtype == DT_ASSNCHAR || dtype == DT_DEFERNCHAR
17871799 ) {
17881800 dt = adjust_ch_length (dt , SST_ASTG (stkp ));
1801+ } else if (dt == DT_ASSCHAR || dt == DT_DEFERCHAR
1802+ || dt == DT_ASSNCHAR || dt == DT_DEFERNCHAR
1803+ ) {
1804+ dt = fix_dtype (SST_SYMG (stkp ), dt );
17891805 }
17901806 }
17911807 /* need to change the type for the first element too */
17921808 if (specified_dtype && acs .eltype == 0 &&
17931809 add_flag ) { /* if we're in a struct, don't do */
17941810 if (DTY (dt ) == TY_CHAR && DTY (dtype ) == TY_CHAR )
1795- ;
1811+ if (dtype2 != DT_DEFERCHAR && dtype2 != DT_DEFERNCHAR )
1812+ dtype = SST_DTYPEG (stkp );
17961813 else if (DTY (dt ) == TY_NCHAR && DTY (dtype ) == TY_NCHAR )
1797- ;
1814+ if (dtype2 != DT_DEFERCHAR && dtype2 != DT_DEFERNCHAR )
1815+ dtype = SST_DTYPEG (stkp );
17981816 else if (DTY (dtype ) == TY_ARRAY ) {
17991817 if (DDTG (dtype ) != dt ) {
18001818 errsev (95 );
@@ -1818,10 +1836,12 @@ compute_size_expr(bool add_flag, ACL *aclp, DTYPE dtype)
18181836 * causes S_CONST to become S_EXPR.
18191837 */
18201838 if (add_flag ) { /* if we're in a struct, don't do */
1821- if (DTY (acs .eltype ) == TY_CHAR && DTY (dtype ) == TY_CHAR )
1822- ;
1823- else if (DTY (acs .eltype ) == TY_NCHAR && DTY (dtype ) == TY_NCHAR )
1824- ;
1839+ if (DTY (dt ) == TY_CHAR && DTY (dtype ) == TY_CHAR )
1840+ if (dtype2 != DT_DEFERCHAR && dtype2 != DT_DEFERNCHAR )
1841+ dtype = SST_DTYPEG (stkp );
1842+ else if (DTY (dt ) == TY_NCHAR && DTY (dtype ) == TY_NCHAR )
1843+ if (dtype2 != DT_DEFERCHAR && dtype2 != DT_DEFERNCHAR )
1844+ dtype = SST_DTYPEG (stkp );
18251845 else if (DTY (dtype ) == TY_ARRAY ) {
18261846 if (!eq_dtype (DDTG (dtype ), acs .eltype )) {
18271847 errsev (95 );
@@ -2328,6 +2348,9 @@ get_shape_arraydtype(int shape, int eltype)
23282348 }
23292349 }
23302350
2351+ if (is_deferlenchar_dtype (acs .arrtype ))
2352+ sem .arrdim .ndefer = 1 ;
2353+
23312354 arrtype = mk_arrdsc ();
23322355 DTY (arrtype + 1 ) = eltype ;
23332356 return arrtype ;
@@ -2364,7 +2387,11 @@ mkexpr_assign_temp(SST *stkptr)
23642387 /* if we have an array expression, we need to assign it to
23652388 a temporary so that we can subscript it. */
23662389 if (DTY (dtype = SST_DTYPEG (stkptr )) == TY_ARRAY && !simple ) {
2367- dtype = get_shape_arraydtype (A_SHAPEG (ast ), DTY (dtype + 1 ));
2390+ if (is_deferlenchar_ast (ast )) {
2391+ dtype = get_shape_arraydtype (A_SHAPEG (ast ), DTY (acs .arrtype + 1 ));
2392+ } else {
2393+ dtype = get_shape_arraydtype (A_SHAPEG (ast ), DTY (dtype + 1 ));
2394+ }
23682395 id = get_arr_temp (dtype , FALSE, FALSE, FALSE);
23692396 if (sem .arrdim .ndefer )
23702397 gen_allocate_array (id );
@@ -7605,13 +7632,15 @@ get_ch_temp(DTYPE dtype)
76057632 } while (dt != dtype );
76067633
76077634 if (needalloc ) {
7635+ int clen ;
76087636 ALLOCP (sptr , 1 );
76097637 /* if the length is not a constant, make it 'adjustable' */
7610- if (A_ALIASG (len ) == 0 ) {
7638+ if (sem .gcvlen && is_deferlenchar_dtype (dtype )) {
7639+ clen = ast_intr (I_LEN , astb .bnd .dtype , 1 , mk_id (sptr ));
7640+ } else if (A_ALIASG (len ) == 0 ) {
76117641 /* fill in CVLEN field */
76127642 ADJLENP (sptr , 1 );
76137643 if (CVLENG (sptr ) == 0 ) {
7614- int clen ;
76157644 clen = sym_get_scalar (SYMNAME (sptr ), "len" , astb .bnd .dtype );
76167645 CVLENP (sptr , clen );
76177646 }
@@ -7626,7 +7655,8 @@ get_ch_temp(DTYPE dtype)
76267655 if (ADD_LWBD (dtype , d ) == 0 )
76277656 ADD_LWBD (dtype , d ) = astb .bnd .one ;
76287657 }
7629- allocate_temp (sptr );
7658+ if (!ADD_DEFER (DTYPEG (sptr )) || ADJLENG (sptr ))
7659+ allocate_temp (sptr );
76307660 }
76317661 } else {
76327662 allocate_temp (sptr );
@@ -11408,8 +11438,7 @@ gen_alloc_dealloc(int stmtyp, int object, ITEM *spec)
1140811438 /* This is for allocate statement, must set length before allocate
1140911439 * sem.gcvlen supposedly gets set only when it is character
1141011440 */
11411- if ((DDTG (A_DTYPEG (object )) == DT_DEFERCHAR ||
11412- DDTG (A_DTYPEG (object )) == DT_DEFERCHAR ) &&
11441+ if (is_deferlenchar_ast (object ) &&
1141311442 stmtyp == TK_ALLOCATE ) {
1141411443 if (sem .gcvlen ) {
1141511444 len_stmt =
0 commit comments