public inbox for gcc-cvs@sourceware.org help / color / mirror / Atom feed
From: Jerry DeLisle <jvdelisle@gcc.gnu.org> To: gcc-cvs@gcc.gnu.org Subject: [gcc r14-8992] Fortran: namelist-object-name renaming. Date: Wed, 14 Feb 2024 22:43:51 +0000 (GMT) [thread overview] Message-ID: <20240214224351.DF64C3861038@sourceware.org> (raw) https://gcc.gnu.org/g:8221201cc59870579b9dc451b173f94b8d8b0993 commit r14-8992-g8221201cc59870579b9dc451b173f94b8d8b0993 Author: Steve Kargl <kargl@gcc.gnu.org> Date: Wed Feb 14 14:40:16 2024 -0800 Fortran: namelist-object-name renaming. PR fortran/105847 gcc/fortran/ChangeLog: * trans-io.cc (transfer_namelist_element): When building the namelist object name, if the use rename attribute is set, use the local name specified in the use statement. gcc/testsuite/ChangeLog: * gfortran.dg/pr105847.f90: New test. Diff: --- gcc/fortran/trans-io.cc | 6 ++++-- gcc/testsuite/gfortran.dg/pr105847.f90 | 39 ++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/gcc/fortran/trans-io.cc b/gcc/fortran/trans-io.cc index 3cde1dabd60c..ee2cc560cdfa 100644 --- a/gcc/fortran/trans-io.cc +++ b/gcc/fortran/trans-io.cc @@ -1692,8 +1692,10 @@ transfer_namelist_element (stmtblock_t * block, const char * var_name, gcc_assert (sym || c); /* Build the namelist object name. */ - - string = gfc_build_cstring_const (var_name); + if (sym && !sym->attr.use_only && sym->attr.use_rename) + string = gfc_build_cstring_const (sym->ns->use_stmts->rename->local_name); + else + string = gfc_build_cstring_const (var_name); string = gfc_build_addr_expr (pchar_type_node, string); /* Build ts, as and data address using symbol or component. */ diff --git a/gcc/testsuite/gfortran.dg/pr105847.f90 b/gcc/testsuite/gfortran.dg/pr105847.f90 new file mode 100644 index 000000000000..9a89d3971c58 --- /dev/null +++ b/gcc/testsuite/gfortran.dg/pr105847.f90 @@ -0,0 +1,39 @@ +! { dg-do run } +module m + integer :: name_in_module = 123 +end module + +program foo + + use m, name_in_program => name_in_module + namelist /nl/ name_in_program + + if (name_in_program /= 123) stop 1 + + open(unit=10, file='fort.10', status='replace') + write(10,nl) + close(10) + + name_in_program = 42 + if (name_in_program /= 42) stop 2 + + open(unit=10, file='fort.10', status='old') + read(10,nl) + if (name_in_program /= 123) stop 3 + close(10) + + call bar + + contains + + subroutine bar + integer name_in_program + namelist /nl/ name_in_program + name_in_program = 0 + open(unit=10, file='fort.10', status='old') + read(10,nl) + if (name_in_program /= 123) stop 4 + close(10,status='delete') + end subroutine bar + +end
reply other threads:[~2024-02-14 22:43 UTC|newest] Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20240214224351.DF64C3861038@sourceware.org \ --to=jvdelisle@gcc.gnu.org \ --cc=gcc-cvs@gcc.gnu.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).