https://gcc.gnu.org/g:947b22d9d0622f4a1bf7476f76f17b0d48201c4e

commit r16-4098-g947b22d9d0622f4a1bf7476f76f17b0d48201c4e
Author: Paul Thomas <[email protected]>
Date:   Fri Sep 26 07:30:07 2025 +0100

    Fortran: Fix uninitialized reads for pdt_13.f03 etc. [PR122002]
    
    2025-09-26  Harald Anlauf  <[email protected]>
    
    gcc/fortran
            PR fortran/122002
            * decl.cc (gfc_get_pdt_instance): Initialize 'instance' to NULL
            and set 'kind_value' to zero before calling gfc_extract_int.
            * primary.cc (gfc_match_rvalue): Intitialize 'ctr_arglist' to
            NULL and test for default values if gfc_get_pdt_instance
            returns NULL.

Diff:
---
 gcc/fortran/decl.cc    | 3 ++-
 gcc/fortran/primary.cc | 4 ++--
 2 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
index 102c6a8e8df8..a891dc86eae9 100644
--- a/gcc/fortran/decl.cc
+++ b/gcc/fortran/decl.cc
@@ -3857,7 +3857,7 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, 
gfc_symbol **sym,
   /* The symbol for the parameter in the template f2k_namespace.  */
   gfc_symbol *param;
   /* The hoped for instance of the PDT.  */
-  gfc_symbol *instance;
+  gfc_symbol *instance = NULL;
   /* The list of parameters appearing in the PDT declaration.  */
   gfc_formal_arglist *type_param_name_list;
   /* Used to store the parameter specification list during recursive calls.  */
@@ -4037,6 +4037,7 @@ gfc_get_pdt_instance (gfc_actual_arglist *param_list, 
gfc_symbol **sym,
          goto error_return;
        }
 
+      kind_value = 0;
       gfc_extract_int (kind_expr, &kind_value);
       sprintf (name + strlen (name), "_%d", kind_value);
 
diff --git a/gcc/fortran/primary.cc b/gcc/fortran/primary.cc
index 638018bcce37..fd03ceace51f 100644
--- a/gcc/fortran/primary.cc
+++ b/gcc/fortran/primary.cc
@@ -4067,7 +4067,7 @@ gfc_match_rvalue (gfc_expr **result)
        {
          gfc_symtree *pdt_st;
          gfc_symbol *pdt_sym;
-         gfc_actual_arglist *ctr_arglist, *tmp;
+         gfc_actual_arglist *ctr_arglist = NULL, *tmp;
          gfc_component *c;
 
          /* Obtain the template.  */
@@ -4088,7 +4088,7 @@ gfc_match_rvalue (gfc_expr **result)
                 first argument list and return the parameter list in
                 ctr_arglist.  */
              m = gfc_get_pdt_instance (actual_arglist, &pdt_sym, &ctr_arglist);
-             if (m != MATCH_YES)
+             if (m != MATCH_YES || !ctr_arglist)
                {
                  if (ctr_arglist)
                    gfc_free_actual_arglist (ctr_arglist);

Reply via email to