Hello all,

See attached patch.

This was probably a latent bug uncovered by the commit r17-3342.

This is a one-liner fix.

I will commit this soon.

Regression tested on X86_64. Thanks to Harald and Mikael for help isolating 
this.

Best regards,

Jerry

---

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.
---
From 1d178a6cb507923de2e375ab13b6a18ecd954859 Mon Sep 17 00:00:00 2001
From: Jerry DeLisle <[email protected]>
Date: Tue, 17 Nov 2026 13:06:00 -0800
Subject: [PATCH] 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.
---
 gcc/fortran/trans-array.cc             | 2 ++
 gcc/testsuite/gfortran.dg/pr128691.f90 | 8 ++++++++
 2 files changed, 10 insertions(+)
 create mode 100644 gcc/testsuite/gfortran.dg/pr128691.f90

diff --git a/gcc/fortran/trans-array.cc b/gcc/fortran/trans-array.cc
index 61e5611e1a7..aee183a5fef 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 00000000000..8a552925bf8
--- /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
-- 
2.56.0

Reply via email to