From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id 1ED78384144B; Sat, 4 Jun 2022 18:08:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 1ED78384144B From: "kargl at gcc dot 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 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: fortran X-Bugzilla-Version: 13.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: kargl at gcc dot gnu.org X-Bugzilla-Status: NEW X-Bugzilla-Resolution: X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: cf_reconfirmed_on bug_status everconfirmed Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-BeenThere: gcc-bugs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-bugs mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 04 Jun 2022 18:08:22 -0000 https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D105847 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 =3D 123 end module program foo use m, name_in_program =3D> name_in_module namelist /nl/ name_in_program if (name_in_program /=3D 123) stop 1 open(unit=3D10, file=3D'fort.10', status=3D'replace') write(10,nl) close(10) name_in_program =3D 42 if (name_in_program /=3D 42) stop 2 open(unit=3D10, file=3D'fort.10', status=3D'old') read(10,nl) close(10, status=3D'delete') if (name_in_program /=3D 123) stop 3 end=20 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 =3D gfc_build_cstring_const (var_name); + if (sym->attr.use_rename) + string =3D gfc_build_cstring_const (sym->ns->use_stmts->rename->local_= name); + else + string =3D gfc_build_cstring_const (var_name); string =3D gfc_build_addr_expr (pchar_type_node, string); /* Build ts, as and data address using symbol or component. */=