https://gcc.gnu.org/bugzilla/show_bug.cgi?id=122002

Paul Thomas <pault at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Assignee|unassigned at gcc dot gnu.org      |pault at gcc dot gnu.org

--- Comment #12 from Paul Thomas <pault at gcc dot gnu.org> ---
(In reply to anlauf from comment #8)
> (In reply to anlauf from comment #6)
> > 'name' is never initialized:
> > 
> >   /* Used to build up the name of the PDT instance. The prefix uses 4
> >      characters and each KIND parameter 2 more.  Allow 8 of the latter. */
> >   char name[GFC_MAX_SYMBOL_LEN + 21];
> > 
> > Can one try setting
> > 
> >   name[0] = ’\0’;
> > 
> > or similar?
> 
> This was just fishing in the dark.
> 
> The following fixes the uninitialized reads here for pdt_13.f03:
> 
> diff --git a/gcc/fortran/decl.cc b/gcc/fortran/decl.cc
> index 99644939056..a10cc754b36 100644
> --- a/gcc/fortran/decl.cc
> +++ b/gcc/fortran/decl.cc
> @@ -3857,7 +3881,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 +4061,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 638018bcce3..68413ec55da 100644
> --- a/gcc/fortran/primary.cc
> +++ b/gcc/fortran/primary.cc
> @@ -4067,7 +4068,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.  */

This does indeed fix the immediate problem. However, inserting a warning at
decl.cc:4042 gives as the first message:
/home/pault/gitsources/gcc/gcc/testsuite/gfortran.dg/pdt_13.f03:20:26:

   20 |     type (link(real_kind)), pointer :: next => NULL()
      |                          1
Warning: At (1) kind_value = 0

The following messages are OK.

That said, the valgrind output on f951 still shows memory loss from allocations
in the offending areas in decl.cc and primary.cc.

Since it's my doing and this afternoon is forecast to be rainy, I'll take the
bug.

Thanks for all your input Harald and Jerry. Please do not feel that you should
not continue, just because I have taken the PR.

Paul

Reply via email to