public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "kargl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug fortran/105847] namelist-object-name can be a renamed host associated entity
Date: Sat, 04 Jun 2022 18:08:22 +0000	[thread overview]
Message-ID: <bug-105847-4-7bonKEBHJP@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-105847-4@http.gcc.gnu.org/bugzilla/>

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

kargl at gcc dot gnu.org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2022-06-04
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1

--- Comment #1 from kargl at gcc dot gnu.org ---
Found via https://groups.google.com/g/comp.lang.fortran/c/CfODg8wnF8M

The following code should compile and execute to completion.

! { 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)
   close(10, status='delete')
   if (name_in_program /= 123) stop 3

end 


The following patch fixes the problem.

diff --git a/gcc/fortran/trans-io.cc b/gcc/fortran/trans-io.cc
index 732221f848b..4621ff1c5b7 100644
--- a/gcc/fortran/trans-io.cc
+++ b/gcc/fortran/trans-io.cc
@@ -1666,8 +1666,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->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.  */

  reply	other threads:[~2022-06-04 18:08 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-04 18:05 [Bug fortran/105847] New: " kargl at gcc dot gnu.org
2022-06-04 18:08 ` kargl at gcc dot gnu.org [this message]
2022-06-04 18:12 ` [Bug fortran/105847] " kargl at gcc dot gnu.org
2022-06-05  2:27 ` jvdelisle at gcc dot gnu.org
2023-05-30  1:52 ` kargl at gcc dot gnu.org
2023-05-30  1:53 ` kargl at gcc dot gnu.org
2023-05-31  2:30 ` jvdelisle at gcc dot gnu.org
2024-02-14 20:02 ` jvdelisle at gcc dot gnu.org
2024-02-14 21:31 ` jvdelisle at gcc dot gnu.org
2024-02-14 21:57 ` jvdelisle at gcc dot gnu.org
2024-02-14 22:38 ` jvdelisle at gcc dot gnu.org
2024-02-14 22:43 ` cvs-commit at gcc dot gnu.org
2024-02-15 17:50 ` jvdelisle at gcc dot gnu.org

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=bug-105847-4-7bonKEBHJP@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@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: link
Be 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).