[Bug fortran/123321] Namelist input of variable accessed by use association with renaming fails
kargl at gcc dot gnu.org
gcc-bugzilla@gcc.gnu.org
Sat Dec 27 21:04:40 GMT 2025
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123321
--- Comment #2 from Steve Kargl <kargl at gcc dot gnu.org> ---
Created attachment 63173
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63173&action=edit
dejagnu-ified testcase
Here's a modified version of Van's testcase. I hope that is
equivalent and suitable for the testsuite.
When compiled with -fdump-tree-original, the subroutine 'b'
subroutine b
use m, only: y => tol, z
implicit none
character(len=20) :: str = "&v z=1 y=1/"
real :: tol = 0
namelist /v/ y, z
read(str, nml=v)
if (z /= 1) stop 3
if (y /= 1) stop 4
if (tol /= 0) stop 5
end subroutine b
produces (edited to show only relevant parts)
__attribute__((fn spec (". ")))
void b ()
{
namelist v;
static character(kind=1) str[1:20] = "&v z=1 y=1/ ";
static real(kind=4) tol = 0.0;
{
...
dt_parm.0.internal_unit = (character(kind=1) *) &str;
...
dt_parm.0.namelist_name = &"v"[1]{lb: 1 sz: 1};
...
_gfortran_st_set_nml_var (&dt_parm.0, &tol, &"tol"[1]{lb: 1 sz: 1}, 4, 0,
{.elem_len=4, .version=0, .rank=0, .type=1});
Notice the presences of 'tol' in _gfortran_st_set_nml_var instead of 'y'.
The first &tol is likely correct as gfortran wants to write to that memory
location. The second &"tol"[1] is where gfortran goes wrong. This one
should be 'y' to match the namelist definition.
_gfortran_st_set_nml_var (&dt_parm.0, &z, &"z"[1]{lb: 1 sz: 1}, 4, 0,
{.elem_len=4, .version=0, .rank=0, .type=1});
_gfortran_st_read (&dt_parm.0);
_gfortran_st_read_done (&dt_parm.0);
}
if (z != 1)
{
_gfortran_stop_numeric (3, 0);
}
if (tol != 1)
{
_gfortran_stop_numeric (4, 0);
}
The above is the renamed 'tol' aka 'y'. (Recall -fdump-tree-original
does not show all info about a symbol.)
if (tol != 0.0)
{
_gfortran_stop_numeric (5, 0);
}
The above is the local 'tol'.
}
More information about the Gcc-bugs
mailing list