https://gcc.gnu.org/g:54c239848c9afa0291d4aaf6df9de0109ccd68fa

commit r15-10379-g54c239848c9afa0291d4aaf6df9de0109ccd68fa
Author: Harald Anlauf <[email protected]>
Date:   Wed Sep 24 20:57:21 2025 +0200

    Fortran: ICE in character(kind=4) deferred-length array reference [PR121939]
    
            PR fortran/121939
    
    gcc/fortran/ChangeLog:
    
            * trans-types.cc (gfc_init_types): Set string flag for all
            character types.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/deferred_character_39.f90: Disable temporary
            workaround for character(kind=4) deferred-length bug.
    
    (cherry picked from commit 43508d358b9e53abfc3be4e28accbd4a07154dfc)

Diff:
---
 gcc/fortran/trans-types.cc                          |  1 +
 gcc/testsuite/gfortran.dg/deferred_character_39.f90 | 12 +++++++-----
 2 files changed, 8 insertions(+), 5 deletions(-)

diff --git a/gcc/fortran/trans-types.cc b/gcc/fortran/trans-types.cc
index f89807546856..e30b680b0be2 100644
--- a/gcc/fortran/trans-types.cc
+++ b/gcc/fortran/trans-types.cc
@@ -1132,6 +1132,7 @@ gfc_init_types (void)
     {
       type = gfc_build_uint_type (gfc_character_kinds[index].bit_size);
       type = build_qualified_type (type, TYPE_UNQUALIFIED);
+      TYPE_STRING_FLAG (type) = 1;
       snprintf (name_buf, sizeof(name_buf), "character(kind=%d)",
                gfc_character_kinds[index].kind);
       PUSH_TYPE (name_buf, type);
diff --git a/gcc/testsuite/gfortran.dg/deferred_character_39.f90 
b/gcc/testsuite/gfortran.dg/deferred_character_39.f90
index 564f94bb9bde..38ec431fc60f 100644
--- a/gcc/testsuite/gfortran.dg/deferred_character_39.f90
+++ b/gcc/testsuite/gfortran.dg/deferred_character_39.f90
@@ -1,5 +1,6 @@
 ! { dg-do run }
 ! PR fortran/108581 - issues with rank-2 deferred-length character arrays
+! PR fortran/121939 - ICE in gfc_conv_string_parameter
 
 program p
   call pr108581
@@ -79,8 +80,8 @@ subroutine test2
   allocate (a, source = reshape (str1,[1,size(str1)]))
   allocate (b, source = reshape (str1,[1,size(str1)]))
   allocate (c, source = reshape (str4,[1,size(str4)]))
-! allocate (d, source=c)        ! ICE, tracked as pr121939
-  d => c
+  allocate (d, source = c)      ! fixed with pr121939
+! d => c
   ! Positive non-unit stride
   s0 = concat (str1(1::2))
   write(s1,'(4A)') a(1,1::2)
@@ -124,13 +125,14 @@ subroutine test2
   if (s2 /= s0) stop 26
   if (s3 /= s0) stop 27
   if (s4 /= s0) stop 28
-  deallocate (a,b,c)
+  deallocate (a,b,c,d)
 
   ! More complex cases with shape=[2,4]
   allocate (e, source = reshape (str2,[2,size(str2,2)]))
   allocate (f, source = reshape (str2,[2,size(str2,2)]))
   allocate (g, source = reshape (str5,[2,size(str5,2)]))
-  h => g
+  allocate (h, source = reshape (str5,[2,size(str5,2)])) ! fixed with pr121939
+! h => g
   s0 = concat (str2(1,3:1:-2))
   write(s1,'(4A)') e(1,3:1:-2)
   write(s2,'(4A)') f(1,3:1:-2)
@@ -220,7 +222,7 @@ subroutine test2
   if (s2 /= s0) stop 66
   if (s3 /= s0) stop 67
   if (s4 /= s0) stop 68
-  deallocate (e,f,g)
+  deallocate (e,f,g,h)
 
 contains

Reply via email to