https://gcc.gnu.org/g:565d9a3617fcc167f190e04445a1d7952b4d9bba

commit r16-3648-g565d9a3617fcc167f190e04445a1d7952b4d9bba
Author: Paul Thomas <pa...@gcc.gnu.org>
Date:   Mon Sep 8 08:13:07 2025 +0100

    Fortran: Correct variable typespec in PDT specification exprs [PR84008]
    
    2025-09-08  Paul Thomas  <pa...@gcc.gnu.org>
    
    gcc/fortran
            PR fortran/84008
            * decl.cc (insert_parameter_exprs): Correct the typespec of new
            variable declarations, where the type is set to BT_PROCEDURE as
            a precaution for resolution of the whole program unit.
    
    gcc/testsuite/
            PR fortran/84008
            * gfortran.dg/pdt_45.f03: New test.

Diff:
---
 gcc/fortran/decl.cc                  |  3 +++
 gcc/testsuite/gfortran.dg/pdt_45.f03 | 29 +++++++++++++++++++++++++++++
 2 files changed, 32 insertions(+)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 8b0d959dea62..9fe697cd5498 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -3817,6 +3817,9 @@ insert_parameter_exprs (gfc_expr* e, gfc_symbol* sym 
ATTRIBUTE_UNUSED,
          copy = gfc_copy_expr (param->expr);
          *e = *copy;
          free (copy);
+         /* Catch variables declared without a value expression.  */
+         if (e->expr_type == EXPR_VARIABLE && e->ts.type == BT_PROCEDURE)
+           e->ts = e->symtree->n.sym->ts;
        }
     }
 
diff --git a/gcc/testsuite/gfortran.dg/pdt_45.f03 
b/gcc/testsuite/gfortran.dg/pdt_45.f03
new file mode 100644
index 000000000000..ceba1ad993e3
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_45.f03
@@ -0,0 +1,29 @@
+! { dg-do compile }
+!
+! Contributed by Steve Kargl  <ka...@gcc.gnu.org>
+!
+module mod
+
+   type :: objects(k1,l1)
+      integer, kind :: k1 = selected_int_kind(4)
+      integer, len :: l1
+      integer(k1) :: p(l1+1)
+   end type
+
+   contains
+      subroutine foo(n)
+         integer n
+         type(objects(l1=n)) :: x
+         ! Any of these lines caused an ICE in compilation.
+         if (x%k1 /= selected_int_kind(4)) stop 1
+         if (x%l1 /= n) stop 2
+         if (size(x%p) /= x%l1+1) stop 3
+      end subroutine
+
+end module
+
+program p
+   use mod
+   type(objects(1,30)) :: x
+   call foo(3)
+end program p

Reply via email to