]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fortran: Correct variable typespec in PDT specification exprs [PR84008]
authorPaul Thomas <pault@gcc.gnu.org>
Mon, 8 Sep 2025 07:13:07 +0000 (08:13 +0100)
committerPaul Thomas <pault@gcc.gnu.org>
Mon, 8 Sep 2025 07:13:07 +0000 (08:13 +0100)
2025-09-08  Paul Thomas  <pault@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.

gcc/fortran/decl.cc
gcc/testsuite/gfortran.dg/pdt_45.f03 [new file with mode: 0644]

index 8b0d959dea62b9e8d0a3105c10f4e47a231d6dd1..9fe697cd5498467df2600fe878956e8050a28adb 100644 (file)
@@ -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 (file)
index 0000000..ceba1ad
--- /dev/null
@@ -0,0 +1,29 @@
+! { dg-do compile }
+!
+! Contributed by Steve Kargl  <kargl@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