Hi Thomas,
> I don't think that this is a feature of gfc_copy_expr, I think it is a
> bug which probably also bites us in other circumstances which we may
> work around in other places and/or which causes other instances of
> wrong code.
>
> So, I'd very much prefer that the character length is set correctly
> in gfc_copy_expr. If that works, we should definitely backport
> to all open branches.
I spent some time on understanding what happens. But after receiving
Tobias' mail, I sort of lost motivation to pursue this further.
I've committed a slightly adjusted fix with a slightly enhanced testcase
that better exhibits that there were actually two regressions: one with
gcc-8, and another one with gcc-9. Just look at the tree-dumps for the
attached version.
Unless somebody stops me in a constructive way, I'll backport very slowly
- and hopefully carefully - but not waste any time on this.
Thanks,
Harald
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