https://gcc.gnu.org/g:55cd182560b57ac9ed6394fad7390668c7e8e0b3

commit r17-5405-g55cd182560b57ac9ed6394fad7390668c7e8e0b3
Author: Paul Thomas <[email protected]>
Date:   Tue Oct 20 11:59:34 2026 +0100

    Fortran: [meta-bug] [PDT] Parameterized derived type errors [PR82173]
    
    2026-10-20  Paul Thomas  <[email protected]>
    
    gcc/fortran
            PR fortran/82173
            * decl.cc (gfc_get_pdt_instance): Eliminate double !.
            * expr.cc (gfc_check_pointer_assign): If rvalue is expr_NULL,
            return true.
    
    gcc/testsuite/
            PR fortran/82173
            * gfortran.dg/pdt_bug13.f90: New test.

Diff:
---
 gcc/fortran/decl.cc                     |  2 +-
 gcc/fortran/expr.cc                     |  2 ++
 gcc/testsuite/gfortran.dg/pdt_bug13.f90 | 30 ++++++++++++++++++++++++++++++
 3 files changed, 33 insertions(+), 1 deletion(-)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 46a1dece8919..63d4973c018b 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -4677,7 +4677,7 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, 
gfc_symbol **sym,
          if (gfc_derived_parameter_expr (c2->initializer))
            gfc_insert_parameter_exprs (c2->initializer, type_param_spec_list);
          c2->initializer->ts = c2->ts;
-         if (!!gfc_is_constant_expr (c2->initializer))
+         if (!gfc_is_constant_expr (c2->initializer))
            gfc_simplify_expr (c2->initializer, 1);
        }
     }
diff --git a/gcc/fortran/expr.cc b/gcc/fortran/expr.cc
index 48711f7fe7ab..fe006eb8dc43 100644
--- a/gcc/fortran/expr.cc
+++ b/gcc/fortran/expr.cc
@@ -4551,6 +4551,8 @@ gfc_check_pointer_assign (gfc_expr *lvalue, gfc_expr 
*rvalue,
 
          name = s2->name;
        }
+      else if (rvalue->expr_type == EXPR_NULL)
+       return true;
       else
        {
          s2 = rvalue->symtree->n.sym;
diff --git a/gcc/testsuite/gfortran.dg/pdt_bug13.f90 
b/gcc/testsuite/gfortran.dg/pdt_bug13.f90
new file mode 100644
index 000000000000..be27159dfe78
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/pdt_bug13.f90
@@ -0,0 +1,30 @@
+! { dg-do run }
+! See attachment to PR82173 comment 10 - bug13-proc-ptr-comp-init-ice.f90
+module ml
+  type :: t(n)
+    integer, len :: n = 1
+    real :: v(n)
+    procedure(reducer), pointer, nopass :: op => null () ! ICE
+  end type
+  abstract interface
+    real function reducer (x)
+      real, intent(in) :: x(:)
+    end function
+  end interface
+end module
+program l1
+  use ml
+  type(t(3)) :: a
+  a%v = 1.0
+  if (associated (a%op)) stop 1
+  a%op => tgt
+  if (.not.associated (a%op)) stop 2 ! Check normal functioning not affected
+  if (a%op ([1.,2.,3.,4.]) /= 10) stop 3
+  a%op => NULL ()
+  if (associated (a%op)) stop 4
+contains
+    real function tgt (x)
+      real, intent(in) :: x(:)
+      tgt = sum (x)
+    end function
+end program

Reply via email to