From bb67ad5cff58a707aaae645d4f45a913d8511c86 Mon Sep 17 00:00:00 2001 From: Harald Anlauf Date: Sun, 29 Nov 2020 23:23:16 +0100 Subject: [PATCH] PR fortran/98017 - Suspected regression using PACK When substituting a parameter variable of type character, the character length was reset to 1. Fix this by copying the length. gcc/fortran/ChangeLog: * expr.c (simplify_parameter_variable): Fix up character length after copying an array-valued expression. gcc/testsuite/ChangeLog: * gfortran.dg/pr98017.f90: New test. --- gcc/fortran/expr.c | 3 +++ gcc/testsuite/gfortran.dg/pr98017.f90 | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 gcc/testsuite/gfortran.dg/pr98017.f90 diff --git a/gcc/fortran/expr.c b/gcc/fortran/expr.c index 32d905ad179..ae9b0a79474 100644 --- a/gcc/fortran/expr.c +++ b/gcc/fortran/expr.c @@ -2096,6 +2096,9 @@ simplify_parameter_variable (gfc_expr *p, int type) return false; e->rank = p->rank; + + if (e->ts.type == BT_CHARACTER && p->ts.u.cl) + e->ts = p->ts; } if (e->ts.type == BT_CHARACTER && e->ts.u.cl == NULL) diff --git a/gcc/testsuite/gfortran.dg/pr98017.f90 b/gcc/testsuite/gfortran.dg/pr98017.f90 new file mode 100644 index 00000000000..ab60407bf1d --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr98017.f90 @@ -0,0 +1,14 @@ +! { dg-do run } +! PR98017 - [8/9/10/11 Regression] Suspected regression using PACK + +program p + implicit none + character(*), parameter :: s(1) = ['abc()'] + character(*), parameter :: t(*) = s(:)(:1) + if (len (pack (s, s(:)(:1) == 'a')) /= len (s)) stop 1 + if (any (pack (s, s(:)(:1) == 'a') /= s)) stop 2 + if (len (pack (s, t == 'a')) /= len (s)) stop 3 + if (any (pack (s, t == 'a') /= s)) stop 4 + if (len (pack (s(:)(1:5), t == 'a')) /= len (s)) stop 5 + if (any (pack (s(:)(1:5), t == 'a') /= s)) stop 6 +end -- 2.30.2