Thanks for the patch. If you have not already opened a new PR for the other issue with C8107, I'll open one later today. It's likely that we need to check the namelist-group-name for USE association in match.cc:gfc_match_namelist.
Hmmm, it seems we already catch the error, but accept it as an extension. % gfcx -o z -std=f2023 a.f90 && ./z a.f90:11:23: 11 | namelist /nam_nml1/j | 1 Error: GNU Extension: Namelist group name 'nam_nml1' at (1) already is USE associated and cannot be respecified. In hindsight, I wish GNU extensions had warnings associated with them. -- steve On Thu, Aug 29, 2024 at 09:31:37PM +0200, Harald Anlauf wrote: > Dear all, > > the attached simple & obvious patch fixes a NULL pointer dereference > when USEing with rename a namelist member and reading/writing the > namelist. > > Patch was OK'ed in the PR by Steve and is pushed to mainline as: > > r15-3308-g6bfeba12c86b4d0dae27d99b484f64774dd49398 > > As this is a 14/15 regression, I plan to backport when it has > successfully passed the testers. > > Thanks, > Harald > > From 6bfeba12c86b4d0dae27d99b484f64774dd49398 Mon Sep 17 00:00:00 2001 > From: Harald Anlauf <anl...@gmx.de> > Date: Thu, 29 Aug 2024 21:21:39 +0200 > Subject: [PATCH] Fortran: fix ICE with use with rename of namelist member > [PR116530] > > gcc/fortran/ChangeLog: > > PR fortran/116530 > * trans-io.cc (transfer_namelist_element): Prevent NULL pointer > dereference. > > gcc/testsuite/ChangeLog: > > PR fortran/116530 > * gfortran.dg/use_rename_12.f90: New test. > --- > gcc/fortran/trans-io.cc | 3 ++- > gcc/testsuite/gfortran.dg/use_rename_12.f90 | 27 +++++++++++++++++++++ > 2 files changed, 29 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/gfortran.dg/use_rename_12.f90 > > diff --git a/gcc/fortran/trans-io.cc b/gcc/fortran/trans-io.cc > index 7ab82fa2f5b..c0baa718ef6 100644 > --- a/gcc/fortran/trans-io.cc > +++ b/gcc/fortran/trans-io.cc > @@ -1692,7 +1692,8 @@ transfer_namelist_element (stmtblock_t * block, const > char * var_name, > gcc_assert (sym || c); > > /* Build the namelist object name. */ > - if (sym && !sym->attr.use_only && sym->attr.use_rename) > + if (sym && !sym->attr.use_only && sym->attr.use_rename > + && sym->ns->use_stmts->rename) > string = gfc_build_cstring_const > (sym->ns->use_stmts->rename->local_name); > else > string = gfc_build_cstring_const (var_name); > diff --git a/gcc/testsuite/gfortran.dg/use_rename_12.f90 > b/gcc/testsuite/gfortran.dg/use_rename_12.f90 > new file mode 100644 > index 00000000000..0447d5fe150 > --- /dev/null > +++ b/gcc/testsuite/gfortran.dg/use_rename_12.f90 > @@ -0,0 +1,27 @@ > +! { dg-do compile } > +! PR fortran/116530 - ICE with member of namelist renamed by use module > +! > +! Reported by philippe.wautelet at cnrs.fr > + > +module mod_nml1 > + implicit none > + logical :: ldiag > + namelist /nam_nml1/ldiag > +end module mod_nml1 > + > +module mod_interm > + use mod_nml1 > +end module mod_interm > + > +program ice_nml > + use mod_nml1, ldiag_nml1 => ldiag > + use mod_nml1, only : ldiag_only => ldiag > + use mod_interm > + implicit none > + integer :: ilu = 10 > + read(unit=ilu,nml=nam_nml1) > + write(unit=*,nml=nam_nml1) > + print *, ldiag > + print *, ldiag_nml1 > + print *, ldiag_only > +end program ice_nml > -- > 2.35.3 > -- Steve