https://gcc.gnu.org/g:8ed729d68d2b8f2207054915ae3dca15a5ff75c0

commit r17-6426-g8ed729d68d2b8f2207054915ae3dca15a5ff75c0
Author: Jerry DeLisle <[email protected]>
Date:   Tue Nov 17 13:06:00 2026 -0800

    fortran: [PR128691] ICE for vector subscript on CHARACTER TARGET dummy
    
    gfc_conv_expr_descriptor describes a CHARACTER subreference array by a
    new descriptor instead of copying it to a temporary, but that code cannot
    describe a vector subscript and asserts.  Since r17-3342 every
    assumed-shape CHARACTER TARGET dummy counts as a subreference array, so a
    vector-subscripted section of one of rank two or more reached it; a
    CHARACTER pointer to an array of components already could.  Make a
    temporary for any expression with a vector subscript.
    
    Assisted-by: Claude Opus 5.5
    
            PR fortran/128691
    
    gcc/fortran/ChangeLog:
    
            * trans-array.cc (gfc_conv_expr_descriptor): Do not treat an
            expression with a vector subscript as a subreference array target.
    
    gcc/testsuite/ChangeLog:
    
            * gfortran.dg/pr128691.f90: New test.

Diff:
---
 gcc/fortran/trans-array.cc             | 2 ++
 gcc/testsuite/gfortran.dg/pr128691.f90 | 8 ++++++++
 2 files changed, 10 insertions(+)

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 61e5611e1a71..aee183a5fefe 100644
--- a/gcc/fortran/trans-array.cc
+++ b/gcc/fortran/trans-array.cc
@@ -8251,7 +8251,9 @@ gfc_conv_expr_descriptor (gfc_se *se, gfc_expr *expr)
       substr = info->ref && info->ref->next
               && info->ref->next->type == REF_SUBSTRING;
 
+      /* A vector subscript always needs a temporary.  */
       subref_array_target = (is_subref_array (expr)
+                            && !gfc_has_vector_subscript (expr)
                             && (se->direct_byref
                                 || se->force_no_tmp
                                 || expr->ts.type == BT_CHARACTER));
diff --git a/gcc/testsuite/gfortran.dg/pr128691.f90 
b/gcc/testsuite/gfortran.dg/pr128691.f90
new file mode 100644
index 000000000000..8a552925bf81
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pr128691.f90
@@ -0,0 +1,8 @@
+! { dg-do compile }
+!
+! PR 128691
+
+subroutine sub2(dd)
+  character(len=4), target :: dd(:,:,:,:)
+  if (size (dd(:,[1],:,:)) > 0) stop 1
+end subroutine

Reply via email to