[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2024-02-15 Thread jvdelisle at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

--- Comment #11 from Jerry DeLisle  ---
Having done all this, I found:

C8102 (R868) The namelist-group-name shall not be a name accessed by use
association.

What does this mean in the context of renamed?

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2024-02-14 Thread cvs-commit at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

--- Comment #10 from GCC Commits  ---
The master branch has been updated by Jerry DeLisle :

https://gcc.gnu.org/g:8221201cc59870579b9dc451b173f94b8d8b0993

commit r14-8992-g8221201cc59870579b9dc451b173f94b8d8b0993
Author: Steve Kargl 
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.

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2024-02-14 Thread jvdelisle at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

--- Comment #9 from Jerry DeLisle  ---
This seems to work:

   /* 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);

Evidently the processing of the 'only' takes care of the renaming before we get
here. Without the attr.use_only part namelist_use_only.f90 fails.

With these tweaks there are no regressions and the test case here passes.

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2024-02-14 Thread jvdelisle at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

--- Comment #8 from Jerry DeLisle  ---
There is an assert just above the patch that implies that sym can be NULL if c
is not. With gdb I checked, and sure enough thats the failure point.  I am
testing with  sym included in the condition.

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2024-02-14 Thread jvdelisle at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

--- Comment #7 from Jerry DeLisle  ---
Steve, I am getting a boatload of regressions on this.  I wonder if something
in the sym structure needs to be guarded here. They appear to be segfaults. Can
you take a look?

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2024-02-14 Thread jvdelisle at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

--- Comment #6 from Jerry DeLisle  ---
I obviously did not get to this last May. Will try now.

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2023-05-30 Thread jvdelisle at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

--- Comment #5 from Jerry DeLisle  ---
Hi Steve,I will see if I can get all this tested and committed this coming
weekend.

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2023-05-29 Thread kargl at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

--- Comment #4 from kargl at gcc dot gnu.org ---
Created attachment 55196
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55196=edit
patch that fixes the bug

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2023-05-29 Thread kargl at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

--- Comment #3 from kargl at gcc dot gnu.org ---
Created attachment 55195
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=55195=edit
dejagnu-ified testcase

Testcase showing the wrong namelist object name ends up in the file.

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2022-06-04 Thread jvdelisle at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

Jerry DeLisle  changed:

   What|Removed |Added

   Assignee|unassigned at gcc dot gnu.org  |jvdelisle at gcc dot 
gnu.org
 CC||jvdelisle at gcc dot gnu.org

--- Comment #2 from Jerry DeLisle  ---
I will see if I can commit this one.

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2022-06-04 Thread kargl at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105847

kargl at gcc dot gnu.org changed:

   What|Removed |Added

   Priority|P3  |P4

[Bug fortran/105847] namelist-object-name can be a renamed host associated entity

2022-06-04 Thread kargl at gcc dot gnu.org via Gcc-bugs
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.  */