PR fortran/98017 - Suspected regression using PACK
authorHarald Anlauf <anlauf@gmx.de>
Sun, 29 Nov 2020 22:23:16 +0000 (23:23 +0100)
committerHarald Anlauf <anlauf@gmx.de>
Sun, 29 Nov 2020 22:24:45 +0000 (23:24 +0100)
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
gcc/testsuite/gfortran.dg/pr98017.f90 [new file with mode: 0644]

index 32d905a..ae9b0a7 100644 (file)
@@ -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 (file)
index 0000000..ab60407
--- /dev/null
@@ -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